CentOS 7 systemd Requires and After values for Kafka to depend on local Zookeeper?

Viewed 925

I have 5 VMs with CentOS 7, each with both kafka and its embedded zookeeper running.

In my systemd unit files, I tried using zookeeper.service as a Requires dependency of kafka.service but it doesn't appear to work, and the docs don't explicitly clarify whether only .target files are valid values for Requires (and I presume After/Before as well), or .service files themselves are also allowed.

Do I have to use a zookeeper.target for Requires?

Also, should I use Wants instead of Requires, in case Kafka can start fine but the local Zookeeper can't? That way, I assume Kafka would connect to one of the other zookeepers since it knows all 5 of them, while the local zookeeper could be repaired and started to rejoin the ensemble later. But zookeeper would at least attempt to start anytime kafka does.

Here are my .service files:

kafka.service

# Kafka server (broker) management

[Unit]
Description=Apache Kafka server (broker)
Documentation=http://kafka.apache.org/documentation.html
Requires=network.target remote-fs.target zookeeper.service
After=network.target remote-fs.target zookeeper.service

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

zookeeper.service

# Zookeeper server management (Kafka-embedded)

[Unit]
Description=Apache Zookeeper server (Kafka-embedded)
Documentation=http://zookeeper.apache.org
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

edit: I expected to see a dependency hierarchy showing zookeeper indented below kafka, but they just show up as siblings:

# systemctl --all list-dependencies | egrep '(kafka|zookeeper)'
● ├─kafka.service
● ├─zookeeper.service
1 Answers
Related