Storing pid file for a daemon run as user

后端 未结 3 1806
执念已碎
执念已碎 2021-01-11 11:09

Is there a preferred place to store a pid file for a daemon that\'s run as a user? /var/run is the standard place, but this is for a user daemon so it doesn\'t have write pr

相关标签:
3条回答
  • 2021-01-11 11:34

    I suggest you go for a subdirectory within the user's home directory.

    ~/.programname/.pid
    

    If there is any other user configuration data, you can store that in here too, in order to avoid cluttering up the home directory.

    0 讨论(0)
  • 2021-01-11 11:36

    The XDG Basedir specification defines where you should store these.
    The variable $XDG_RUNTIME_DIR defines it's location, although it has no default.
    The most common fallback (if the variable is unset) is /tmp/service-$USER.id.

    This helps keep uncluttered homedirs, while keeping all runtime data in

    0 讨论(0)
  • 2021-01-11 11:56

    If it's being run for a user, let's see, what sort of storage exists that is user-specific.

    Hmmm.

    That's it! The home directory. I knew it would come to me eventually :-)


    Sorry for the light jab. Seriously, I would just stash the PID into $HOME/.daemon.pid or ~/.daemon.pid (how you name the file is up to you of course).

    This is, of course, assuming you will only have one daemon running for a user. If not, you'll need to be a bit trickier.


    And hopefully allaying your fears that a user will inadvertently delete unknown files in their home directory, that's why you make it "hidden" by starting it with a . character.

    Most non-experienced users should never even see these and experienced users should know better than to muck about with them.

    0 讨论(0)
提交回复
热议问题