Ubuntu

touch: cannot touch `/var/run/test.pid': Permission denied

I am starting start-stop-daemon and like to write the PID file in /var/run start-stop-daemon is run as my-program-user

/var/run setting is drwxr-xr-x 9 root root

I like to avoid putting my-program-user in the root group.

link|improve this question
feedback

5 Answers

up vote 12 down vote accepted

By default, you can only write to /var/run as a user with an effective user ID of 0 (ie as root). This is for good reasons, so whatever you do, don't go and change the permissions of /var/run... Instead, as root, create a directory under /var/run:

# mkdir /var/run/mydaemon

Then change its ownership to the user/group under which you wish to run your process:

# chown myuser:myuser /var/run/mydaemon

Now specify to use /var/run/mydaemon rather than /var/run.

You can always test this by running a test as the user in question.

link|improve this answer
feedback

You can try this. Create a directory /var/run/test/ and then change the permission of this directory to the same user as your program runs. " chown /var/run/test/" . Now in your application change the location of the PID file to /var/run/test/test.pid. This should get things working for you.

link|improve this answer
feedback

What about using the "sticky" bit on /var/run ?

chmod +t /var/run ?

Probably mess up some other apps, but it seems like it would be another solution.

I'll stick with creating a separate /var/run folder for now, however.

link|improve this answer
feedback

The directory /var/run/mydaemon does not survive a reboot :(

link|improve this answer
until now, i'm not allowed to comment answers from other persons. – maletin Mar 23 '11 at 12:58
feedback

To avoid putting your program-user in the root group, allow others write access:

# chmod 757
link|improve this answer
1  
Never do a chmod 757 on /var/run! This would cause a serious security problem – michel Dec 2 '10 at 10:57
This is a terrible idea. It would cause a potentially massive security problem – Tom O'Connor Dec 2 '10 at 11:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.