in reply to Re^2: How run a daemon as non-root user
in thread How run a daemon as non-root user

Unless the programs the OP wants to run need root-permissions to do whatever it is they do, there isn't any need to run them as root. Daemonizing does not require root permissions in any sane system.

  • Comment on Re^3: How run a daemon as non-root user

Replies are listed 'Best First'.
Re^4: How run a daemon as non-root user
by halfbaked (Sexton) on Dec 06, 2008 at 01:46 UTC
    Well the pid is stored in /var/run and I can't put together the information to create a user like postgres or apache that can create a pid in /var/run other than root.

    I realize this is probably a silly question, so I can't imagine the answer would be too complicated. It's probably more of a OS issue than Perl, like I said I'm running Debian/Linux.

      Well, there are a couple of ways to solve this.
      1. Start the daemon as root, let it create the pid file, then drop the priviledges.
      2. Make /var/run group owned by the group 'daemons' (with group write permission). Start the deamon as a user that belongs to the group 'daemons'.
      3. Use file ACLs to allow the process to write to /var/run.
      4. Make /var/run world writable.
      5. Make a subdirectory in /var/run that's owned by the user running the daemon. Have the daemon use that subdirectory to write the pidfile into. (Any other directory works as well). You might consider putting a symlink from /var/run pointing to the new location.
      6. Create a (permanent) pidfile in /var/run that's owned by the user running the daemon. Let the daemon clear the pidfile when it exists upon removal. And where it currently associates a meaning to the (non-)existance of the pidfile, let it now associate a meaning to it being of (non-)zero size.