[lang]

Present Perfect

Personal
Projects
Packages
Patches
Presents
Linux

Picture Gallery
Present Perfect

.pid files after reboot

Filed under: sysadmin — Thomas @ 4:30 pm

2009-5-4
4:30 pm

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!

11 Comments »

  1. I prefer /var/run to be mounted as a tmpfs

    Comment by Robert — 2009-5-4 @ 4:59 pm

  2. .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-5-4 @ 5:14 pm

  3. 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-5-4 @ 5:50 pm

  4. 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-5-4 @ 5:59 pm

  5. On Gentoo, bootmisc init script takes care of it during /var/run cleanup on boot.

    Comment by plaes — 2009-5-4 @ 6:22 pm

  6. 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-5-4 @ 6:26 pm

  7. 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-5-4 @ 6:38 pm

  8. 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-5-4 @ 6:43 pm

  9. 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-5-4 @ 7:30 pm

  10. Put the directory holding the pid-files on a ram-disk and they will go away automatically

    Comment by Kristian — 2009-5-4 @ 8:58 pm

  11. 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-5-4 @ 10:07 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

picture