Can someone let me know how can I make a systemd service to be stopped first before the unmounting of the file system starts during the shutdown of a host?
Unit File looks like below
[Unit]
Description=FDB Service
After=network-online.target
Wants=network-online.target
[Service]
Environment=FDB_PID_DIR=/var/run/fdb/
Environment=LOCKFILE=/var/run/fdb/fdbmonitor.pid
Type=simple
User=ubuntu
Group=ubuntu
IgnoreSIGPIPE=false
ExecStart=/bin/bash /home/ubuntu/build-target/fdb/fdb-sysd-start.sh
ExecStopPost=-/home/ubuntu/build-target/fdb/fdb-sysd-poststop.sh
RestartSec=2s
Restart=always
[Install]
WantedBy=multi-user.target
- OS –
Ubuntu 16.04.6
Best Answer
It is almost certainly a problem with your service (fdb). systemd will first try to stop all services and then do the unmount. Make sure your service stops in a reasonable time - if it needs more time to stop gracefully, you may set
TimeoutStopSec=
to a higher value. Also, make sureType=simple
is appropriate, from what it looksType=forking
might be better. When switching toType=forking
make use of PID file by addingPIDFile=/var/run/fdb/fdbmonitor.pid
- if it actually contains the main process PID.If you are using network-mounted shares, systemd should detect them and unmount before shutting down the network. If that does not happen, add
_netdev
mount option to tell systemd this is actually a network share.