Running rc.d programs under a different user

jmscott at setspace.com jmscott at setspace.com
Sat Feb 6 23:17:19 PST 2010


On Sun, Feb 07, 2010 at 12:11:01AM -0600, Charles Solar wrote:
> LFS is working great, and I can safely say I know much more about linux then
> I did before going through the book, so thanks to all those who contributed.

I agree, great work by the LFS team.

> 
> I am wrapping up my fileserver built from LFS SVN 2010-01-09 and I am trying
> to find a way to run a daemon process as a different user.
> In the book we only used the apps config file to specify a different user,
> ex, svn, proftpd.  But I want to run Deluge under a different user and it
> does not have a config option for this.  So I am wondering if there is some
> way I am 'supposed' to setup the init script to do this.  I am trying to
> avoid installing any more unnecessary programs like daemon and
> start-stop-daemon so any advice is appreciated.

I never located such an option in loadprocess().
You can always use

	su user -c /path/to/daemon

which has been the tried and true way in unix for as long as I can remember.

I suppose one reason why a "-u login" option hasn't been added to loadprocess()
is because mapping the login id to a user id can get tricky in networked
PAM environments.  But I conjecture.  I haven't studied the rc functiions 
to carefully.

Nowadays it's not uncommon for the daemon itself to setuid from the 
root user to another user.  For example, apache/httpd changes the user id.
You might check to see if Deluge has such a capability.

That being said, even a server as well known as postgresql doesn't change uid.

Hope this helps-j

> 
> Basically I want to mimic the provided example init scripts from here
> http://dev.deluge-torrent.org/wiki/UserGuide/InitScript
> 
> This is what I am using at the moment
> #!/bin/sh
> # Deluge daemon startup
> 
> . /etc/sysconfig/rc
> . $rc_functions
> 
> case "$1" in
>         start)
>                 boot_mesg "Starting deluged service..."
>                 loadproc -p /var/run/deluged.pid /usr/sbin/deluged -c
> /etc/deluge/ -p 58840 -l /var/log/deluged.log
>                 RETVAL=$?
>                 if [ $RETVAL -eq 0 ] ; then
>                         boot_mesg "Starting deluge web ui..."
>                         loadproc -p /var/run/webluge.pid
> /usr/sbin/deluge-web -f -c /etc/deluge/ -l /var/log/webluged.log
>                 fi
>                 ;;
>         stop)
>                 boot_mesg "Stopping deluged service..."
>                 killproc /usr/sbin/deluged
>                 boot_mesg "Stopping deluge web ui..."
>                 killproc /usr/sbin/deluge-web
>                 ;;
>         restart)
>                 $0 stop
>                 sleep 1
>                 $0 start
>                 ;;
>         status)
>                 statusproc /usr/bin/deluged
>                 ;;
>         *)
>                 echo "Usage: $0 {start|stop|restart|status}"
>                 exit 1
>                 ;;
> esac
> 
> I checked out the functions library and did not see anything jump out at me.
> 
> Thanks

> -- 
> http://linuxfromscratch.org/mailman/listinfo/lfs-support
> FAQ: http://www.linuxfromscratch.org/lfs/faq.html
> Unsubscribe: See the above information page




More information about the lfs-support mailing list