Should my pidfile be in / var / run?

I ask in both contexts: technically and stylistically.

Can my application / daemon save pidfile to /opt/my_app/run/ ?

Is it really bad?

My need is this: my daemon runs under a specific user, and the developer must mkdir create a new directory in /var/run , chown and chgrp to start my daemon. It seems easier to just save the pidfile locally (for the daemon).

+62
linux unix ubuntu pid
Mar 02 2018-11-21T00:
source share
4 answers

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.

+83
Mar 02 2018-11-22T00:
source share

/ opt is used to install "stand-alone" applications, so there is nothing wrong with that. Using /opt/my_app/etc/ for configuration files, /opt/my_app/log/ for logs, etc. - A common practice for this type of application.

In this case, you can distribute your applications as a TGZ file, and not support the package for each package manager (at least DEB since you noted ubuntu ). I would recommend this for internal applications or situations where you have a lot of control over the environment. The reason is that it makes no sense if the safe costs more than what you put inside (the work required to package the application should not overshadow the effort required to write the application).

+9
Mar 02 '11 at 21:30
source share

The location of the pid file must be customizable. / var / run is standard for pid files, just as / var / log is standard for log files. But your daemon should allow you to overwrite this parameter in some kind of configuration file.

+6
Mar 02 2018-11-21T00:
source share

Another convention, if you are not using the script as root, is to put the pidfile in ~/.my_app/my_app.pid . This is simpler, although safe, since the home directory cannot be written to the world.

+6
May 8 '13 at 16:25
source share



All Articles