On a Debian 8 I have deployed an application of mine that consists of several smaller apps and one of those smaller ones uses a HDF5 file. The problem with HDF5
files is that you have to close them. If for example you program chrases or your program get killed, the HDF5
files get corrupted. Depending on the size of the HDF5
file, closing it can take several seconds.
I have a tool mondas_ctrl
which is a manager of my applications, their structure is not important here. When logged in (over ssh) I can execute mondas_ctrl start
or mondas_ctrl stop
without a problem, specially the stop command knows how to deal with the HDF5
files (by adding delays inbetween).
With the old SysV I was able to delay the halt process by changing the runlevel 6 on /etc/inittab
wth a self written script that took care of the HDF5 files before doing init 0
. Now systemd
is default and I had to change the way I think of init.d
files and services. So I wrote an user service that uses my manager to start and stop my apps:
File: ~/.config/systemd/user/mondas.service
[Unit]
Description=Mondas
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/mondas/anaconda/default/bin/mondas_ctrl start
ExecRestart=/home/mondas/anaconda/default/bin/mondas_ctrl restart
ExecStop=/home/mondas/anaconda/default/bin/mondas_ctrl stop
KillMode=none
[Install]
WantedBy=default.target
At first I had a little bit of trouble with the stop command. After reading this thread I added the Type
, RemainAfterExit
and KillMode
options. These helped a lot and now I can do this:
$ systemctl --user start mondas
$ systemctl --user stop mondas
$ systemctl --user start mondas
as many times as I want, the stop command doesn't kill anything, my mondas_ctrl
manager stops the HDF5
app, the file is closed and doesn't get corrupted.
But when I do a system wide reboot (either by executing reboot
or shutdown -r now
), the KillMode
flag seems to be ignored or the whole service seems to be skipped, the logs on screen pass by so quick, I cannot tell if my service is executed at all.
So the question is, do "stop" services behave differently when you execute systemctl stop
and when you execute reboot/shutdown -r now
? If so, what do I have to do during reboot so that my app has enough time to close the HDF5
file?
Thanks