Search code examples
linuxsystemdstartupscript

How stop systemd service


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


Solution

  • 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.