.pid files after reboot |
2009-05-04
|
Hey all you Unix heads and sysadminny/developer types,
should .pid files be cleaned up on a reboot, because the processes definately went away ? If so, which part of the system should take care of this ? Each and every service script on its own somehow ? If not, why ?
Answers on a postcard or in the comments!
I prefer /var/run to be mounted as a tmpfs
Comment by Robert — 2009-05-04 @ 16:59
.pid files go into /var/run, and that gets cleaned up by the system. Each service does not need to clean things up itself.
For example, on Ubuntu 9.04, see /etc/rcS.d/S46mountall-bootclean.sh.
Comment by Lars Wirzenius — 2009-05-04 @ 17:14
Clearly defined by the lsb:
/var/run has to be cleaned up by the system, typically done by a sysv init script (/etc/rcS.d/S36mountall-bootclean.sh on Debian/Ubuntu fwiw).
Nonetheless, it’s a good practice if the daemon itself cleans up the pid file on stop.
Comment by Michael — 2009-05-04 @ 17:50
On debian systems you have /lib/init/bootclean.sh (called from /etc/init.d/mount*) cleaning up /var/run on every startup. On others, like ubuntu, a tmpfs is mounted over /var/run to make sure everything vanishes on reboot without having to clean it up explicitly.
OTOH, a well-behaved service probably takes care of removing stale pid files on startup anyway, since last run might have crashed leaving the pidfile around…..
Comment by fatal — 2009-05-04 @ 17:59
On Gentoo, bootmisc init script takes care of it during /var/run cleanup on boot.
Comment by plaes — 2009-05-04 @ 18:22
Shouldn’t use .pid files at all, the init system should just track the child processes itself. This is how upstart and SMF work at least.
Comment by Colin Walters — 2009-05-04 @ 18:26
If .pid files for some reason have to be used possibly cleaning them on startup is the best. However – as it was pointed out – better solution is to query the processes.
Comment by Uzytkownik — 2009-05-04 @ 18:38
The ‘correct’ way is to write the process id into the pid file, then when the application is started it should open the file, read the pid, look up if a process with that pid exists and whether it is the same command. If the process does not exist or it is the wrong command, then complain about a stale pid file to log, delete it and start as normally.
Comment by Aigars Mahinovs — 2009-05-04 @ 18:43
At my place of work, we write our pid files to a ramdisk (via tmpfs) so that the system automatically clears them up for us.
Comment by andrewd18 — 2009-05-04 @ 19:30
Put the directory holding the pid-files on a ram-disk and they will go away automatically
Comment by Kristian — 2009-05-04 @ 20:58
Hopefully all your .pid files are in one location and if that is the case, just make it (/var/run) a tmpfs. It’ll clear itself on reboot :)
Comment by ryanc — 2009-05-04 @ 22:07