I would not put pidfile in the application installation directory, for example /opt/my_app/whatever . This directory can be mounted read-only, shared between machines, a daemon can be observed that treats any changes there as a possible hacking attempt ...
The usual place for pidfiles is /var/run . Most devices will clear this directory on boot; on Ubuntu, this is achieved using the /var/run in-memory file system (tmpfs).
If you run your daemon from a script that runs as root, create a subdirectory /var/run/gmooredaemon and transfer it to the user working with the daemon, before su ing for the user and start the daemon. Otherwise, select a location under /tmp or /var/tmp , but this will add extra complexity because the pidfile name cannot be uniquely determined if it is in a directory writable in the world.
In any case, simplify (a command line option, and also possibly a compile time option) for the distributor or administrator to change the location of the pidfile.
Gilles Mar 02 2018-11-22T00: 00Z
source share