You are not logged in.

#1 2008-05-05 20:33:40

dienadel
Member
Registered: 2005-12-23
Posts: 179

Daemon not closing at shutdown

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

#2 2008-05-05 21:03:41

pressh
Developer/TU
From: Netherlands
Registered: 2005-08-14
Posts: 1,719

Re: Daemon not closing at shutdown

dienadel wrote:

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

#3 2008-05-05 21:41:23

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: Daemon not closing at shutdown

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

#4 2008-05-05 21:41:48

dienadel
Member
Registered: 2005-12-23
Posts: 179

Re: Daemon not closing at shutdown

pressh wrote:

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

#5 2008-05-05 21:45:58

dienadel
Member
Registered: 2005-12-23
Posts: 179

Re: Daemon not closing at shutdown

carlocci wrote:

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

Board footer

Powered by FluxBB