halfbaked has asked for the wisdom of the Perl Monks concerning the following question:

I have a couple of perl Daemons that I'd like to run as non-root users.

I'm using Proc::PID::File

I can't seem to figure out how to run these daemons as non-root.

I think I should be able to create special user that has access to run just these daemons but can't figure it out for some reason.

I'm running Debian Linux.

Replies are listed 'Best First'.
Re: How run a daemon as non-root user
by fmerges (Chaplain) on Dec 05, 2008 at 20:40 UTC

    Hi,

    I think you're a bit confused... the fact that you use Proc::PID::File has nothing to do with a daemon, is just to make more handy the manipulation of pid files, like File::Pid does.

    Easy way to convert a program into a daemon is using Proc::Daemon.

    Then for Debian and derivates, like Ubuntu see the man page of start-stop-daemon and be ready to write a small Bash script, it even allows you to create the pid file, or "daemonize" your process.

    Regards,

    fmerges at irc.freenode.net
Re: How run a daemon as non-root user
by SilasTheMonk (Chaplain) on Dec 05, 2008 at 20:12 UTC
    How exactly are you starting the daemon process? I would probably use the files in /etc/init.d and /etc/r.*. These in turn depend on start-stop-daemon, which has a man page. I think you would want the --chuid option.
      Yeah I'm starting them with /etc/init.d

      I think my issue is that I don't know how to create a user with the proper permissions to create a pid /var/run

      Maybe I should be searching Debian docs on how to do this.

      Thanks for everyone's help.
        OK, I figured it out. It wasn't a Perl question, but rather a Linux question.

        All I had to was to chown the pid file to the user that's starting the process. It seems so obvious now.

        Thanks everyone. You'd think that after working in technology for almost 12 years that I wouldn't have to ask stupid questions, but ... Linux admin has never been my strong suit.
Re: How run a daemon as non-root user
by zentara (Cardinal) on Dec 05, 2008 at 20:49 UTC
    Ubuntu lets users control root programs with sudo. What you do is put your username and program in the /etc/sudoers file, and I believe there is a nopasswd option, so you don't need to enter the passwd everytime, like with su.

    Google for "/etc/sudoers" and read the tutorials. If you set it up right, you keep the root perms on the daemon script, and run it, as a user, with "sudo myscript". It should launch with root permissions.


    I'm not really a human, but I play one on earth Remember How Lucky You Are
      Unless I read the original post incorrectly, the poster is explicitly trying to avoid launching the daemons with root permissions...