0

I tried the fix here: systemd not restarting my process and that didn't work for me.

I have a Kafka exporter for Prometheus. I have Kafka running on the same computer. When I stop Kafka, the Kakfa exporter dies (it depends on being able to communicate with the Kafka processes). I would like the exporter to automatically restart after Kafka is started again, but this isn't working.

Here's my systemd file, below. I've tried various things here. What can I do to ensure the Kafka exporter starts after Kafka is finally restarted / brought back up?

[Unit]
Requires=kafka.service
After=kafka.service

[Service]
Type=simple
User=kafka
# give kafka time to start up first
ExecStartPre=/bin/sleep 15
ExecStart=/opt/kafka_exporter/kafka_exporter --kafka.server=localhost:9092
Restart=always
RestartSec=30
StartLimitInterval=0s

[Install]
WantedBy=multi-user.target
HorseHair
  • 317
  • 4
  • 11

1 Answers1

0

Can you try PartOf? From manual:

PartOf= Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.

In that case unit should be like below.

[Unit]
After=kafka.service
Requires=kafka.service
PartOf=kafka.service
asktyagi
  • 2,401
  • 1
  • 5
  • 19