Hi guys.
I noticed when i wanted to install amuled as a boot daemon that it is hard to make it run under another user.
I tried the following to start amule at boot time (on slackware) :
#!/bin/sh
# Start/stop/restart amuled
#
# To start amuled and amuleweb at boot, be sure to chmod 755 /etc/rc.d/rc.amule
amuled_start() {
if [ -x /usr/local/bin/amuled ]; then
if [ -r /var/run/amuled.pid ]; then
if ! ps axc | grep amuled 1> /dev/null 2>/dev/null; then
echo "Cleaning up old /var/run/amule/amuled.pid."
rm -f /var/run/amuled.pid
fi
fi
/usr/local/bin/amuled -o 2>&1 >/var/log/amuled.log &
echo "$!" > /var/run/amuled.pid
fi
}
amuled_stop() {
# If there is no PID file, ignore this request...
if [ -r /var/run/amuled.pid ]; then
kill `cat /var/run/amuled.pid`
wait `cat /var/run/amuled.pid`
rm -f /var/run/amuled.pid
fi
}
amuled_restart() {
amuled_stop
amuled_start
}
case "$1" in
'start')
amuled_start
;;
'stop')
amuled_stop
;;
'restart')
amuled_restart
;;
*)
echo "Usage $0 start|stop|restart"
esac
In order to avoid amuled (and so amuleweb) running as root, I have setuid amuled, and given it to a fake user 'amule'. However, this does not work well, because amuled tries to read configuration files from ~/.aMule, which points to /root/.aMule. Second issue is that it is a security breach to allow amule user to modify /usr/local/bin/amuled binary (as it is the owner of the file, for setuid, whatever the file is chmoded does not change anything).
I suggest that amuled includes a new feature :
1) detach from controling tty.
2) perform setuid trough the setuid system call, thus loosing root privileges.
3) read configuration file from ~/.amule or from a command line argument specified path (what's not possible for now).
Good job for amuled, that rocks !