You are not logged in.
Hello,
I've created a rc.d script to run rtorrent at boot. Please, note that i don't know programing, so the script is poor, but at least, it does what i want:
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
USER="theuser"
case "$1" in
start)
stat_busy "Starting rtorrent"
su -c "screen -S rtorrent -md /usr/bin/rtorrent &" $USER
stat_done
;;
stop)
stat_busy "Stopping rtorrent"
PID=`pidof -o %PPID /usr/bin/rtorrent`
kill -s INT $PID
stat_done
;;
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
I've put it in the rc.conf file, so starts at boot with the line "Starting rtorrent...". Nice. But, when i halt or reboot the system, there is no line saying "Stopping rtorrent". Why?
Thanks!!
Offline
But, when i halt or reboot the system, there is no line saying "Stopping rtorrent". Why?
I think because the daemon is not explicitly added with an add_daemon line in the script.
Try to use one of the scripts already in /etc/rc.d and modify it to do what you want (some are more basic than others so probably you want to use those to start with)
Offline
How could your system know which daemon is running and which not?
add_daemon (in /etc/rc.d/functions) creates a file named as the rc script in /var/run/daemons/.
This directory is then checked by this code in rc.shutdown:
if [ "$PREVLEVEL" = "3" -o "$PREVLEVEL" = "5" ]; then
# Shutdown daemons
let i=${#DAEMONS[@]}
while [ $i -ge 0 ]; do
if [ "${DAEMONS[$i]:0:1}" != '!' ]; then
ck_daemon ${DAEMONS[$i]#@} || /etc/rc.d/${DAEMONS[$i]#@} stop
fi
let i=i-1
done
# find any leftover daemons and shut them down in reverse order
if [ -d /var/run/daemons ]; then
for daemon in $(/bin/ls -1t /var/run/daemons); do
/etc/rc.d/$daemon stop
done
fi
fi
Offline
I think because the daemon is not explicitly added with an add_daemon line in the script.
Try to use one of the scripts already in /etc/rc.d and modify it to do what you want (some are more basic than others so probably you want to use those to start with)
Thanks, I'll try tomorrow this way:
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
USER="theuser"
case "$1" in
start)
stat_busy "Starting rtorrent"
su -c "screen -S rtorrent -md /usr/bin/rtorrent &" $USER
add_daemon rtorrentd
stat_done
;;
stop)
stat_busy "Stopping rtorrent"
PID=`pidof -o %PPID /usr/bin/rtorrent`
kill -s INT $PID
rm_daemon rtorrentd
stat_done
;;
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0
Bye!
Last edited by dienadel (2008-05-05 21:42:43)
Offline
How could your system know which daemon is running and which not?
add_daemon (in /etc/rc.d/functions) creates a file named as the rc script in /var/run/daemons/.
UPS! I thought that at reboot or halt, arch takes a look at rc.conf at stop the daemon in reverse order :-)
thanks
Offline