tags:

views:

28

answers:

2

Is there a preffered 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 doesnt have write privelages there. Presumably my daemon will be started from .profile or .bashrc or something. Is just saving it to /tmp a bad idea?

+1  A: 

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.

paxdiablo
Well the user sees the hom directory, and I think they'd be more likely to delete the file if they see it in ~ not knowing what it was
Falmarri
@Falmarri: And what is the danger in that? If you really need the PID again, you can always look in the process table. The PID file is just a convenience.
Aaron Digulla
That's why you put a `.` in front of it. Users who don't know what they're doing will probably never even know that it exists. And if they do regularly see the hidden files, just one mistake deleting `.bashrc` will teach them the error of their ways :-) If you are _really_ paranoid, put the PID into `~/.dont_EVER_delete_me_or_you_WILL_be_sorry/.daemon.pid`.
paxdiablo
A: 

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.

dogbane