Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

systemd: How to use ExecStopPre in service files

Tags:

systemd

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?

like image 488
arved Avatar asked Nov 21 '15 17:11

arved


People also ask

How do I edit a systemd service file?

Systemd services can be modified using the systemctl edit command. This creates an override file /etc/systemd/system/httpd. service.

What is a .service file?

The database server requires a Services file, which contains information about the known services on your network. The Services file is typically located in %windir%\System32\drivers\etc\services.

What is ExecStop systemd?

The ExecStop setting is optional and is used to communicate with the service for a clean termination. The process specified by ExecStop will run in case the service crashes.


1 Answers

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
like image 66
vortarian Avatar answered Sep 19 '22 21:09

vortarian