20

I am trying to create systemd service file for Flume, have created /etc/systemd/system/flume-ng.service with following contents

[Unit]
Description=Apache Flume

[Service]
Environment=FLUME_CLASSPATH=/opt/flume/current/lib/
ExecStart=/usr/bin/nohup /usr/bin/flume-ng agent -c /etc/flume-ng/conf -f /etc/flume-ng/conf/flume.conf --name a1 &

[Install]
WantedBy=multi-user.target

which start the Flume service but how do I stop it as a service ?

In this case I had to kill with PID.

thanks

smonff
  • 3,399
  • 3
  • 36
  • 46
roy
  • 6,344
  • 24
  • 92
  • 174

3 Answers3

30

You can just execute systemctl stop flume-ng.service. When executed, the default action is sending SIGTERM to the main process and wait until a configurable time to see if the processes has been terminated. If the process doesn't terminate, then systemd sends SIGKILL signal which does the job. If the main process has forked off other processes, systemd will take them down too since they all live in the same cgroup.

You do not need to have ExecStop= directive unless you have a different way of shutting down your service.

Umut
  • 2,317
  • 1
  • 17
  • 19
17

You need to put in a ExecStop option in the [Service] section with the command you want to use to stop the service.

Something like:

[Service]
Environment=FLUME_CLASSPATH=/opt/flume/current/lib/
ExecStart=/usr/bin/nohup /usr/bin/flume-ng agent -c /etc/flume-ng/conf -f /etc/flume-ng/conf/flume.conf --name a1 &
ExecStop=/usr/bin/flume-ng agent stop

or whatever the command is to stop the flume-ng

Then you can stop the service with systemctl stop flume-ng.

Read the manual at https://www.freedesktop.org/software/systemd/man/systemd.service.html for the full set of options available to control the service.

Munir
  • 3,442
  • 3
  • 19
  • 29
0

ExecStop is not sufficient in my opinion. Also important is KillSignal=. The signal that you use here should be the one that you would like to handle internally and safely exit the application. Systemd would use the same to kill your application. In case ExecStop= fails to exit the process, it will be killed by KillSignal. Last resort with systemd is to use SIGKILL and kill your process anyway to proceed with system shutdown.

Bhush
  • 58
  • 10