10

Before my daemon is stopped I need to do call another program.

My first try was to use ExecStopPre similar to ExecStartPre but according to https://bugs.freedesktop.org/show_bug.cgi?id=73177 this is not supported and I should use "multiple ExecStop".

Anyone got an example for this? How should i kill the daemon from ExecStop?

arved
  • 4,401
  • 4
  • 30
  • 53

1 Answers1

14

You put multiple lines with ExecStop (from a node.js service): e.g.

[Service]
ExecStartPre=/usr/local/bin/npm run build
ExecStartPre=-/bin/rm local.sock
ExecStart=/usr/local/bin/npm --parseable start 
ExecStop=/usr/local/bin/npm --parseable stop
ExecStop=-/bin/rm local.sock
RestartSec=300
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs
User=nobody
Group=nobody
Environment=NODE_ENV=dev
Environment=PORT=3000
WorkingDirectory=/var/www/nodejs/quaff
UMask=007
vortarian
  • 156
  • 2
  • 3
  • 2
    Is the execution order always top to bottom? – arved Feb 02 '16 at 09:13
  • 3
    The [documentation on `ExecStart=`](https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=) says: "If more than one command is specified, the commands are invoked sequentially in the order they appear in the unit file. If one of the commands fails (and is not prefixed with '-'), other lines are not executed, and the unit is considered failed." I guess the same holds for `ExecStop=`. – jotrocken Oct 17 '18 at 16:44