ibrdtn.init 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2007 OpenWrt.org
  3. START=90
  4. start() {
  5. # check if the daemon is disabled
  6. if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
  7. /bin/echo "dtnd is disabled"
  8. return
  9. fi
  10. /bin/echo -n "running dtnd ..."
  11. # startup the safety-wrapper for the daemon
  12. /usr/sbin/dtnd-safety-wrapper.sh &
  13. # store the pid of the process in uci states
  14. /sbin/uci -P/var/state -q set ibrdtn.safetypid=`echo $!`
  15. /bin/echo " done"
  16. }
  17. stop() {
  18. # check if the daemon is disabled
  19. if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
  20. /bin/echo "dtnd is disabled"
  21. return
  22. fi
  23. /bin/echo -n "stopping dtnd ..."
  24. # set state to None, this indicates a clear shutdown to the safety-wrapper.
  25. /sbin/uci -P/var/state -q set ibrdtn.state=None
  26. # stop the safety-wrapper
  27. if [ -n "`/sbin/uci -P/var/state -q get ibrdtn.safetypid`" ]; then
  28. /usr/bin/kill `/sbin/uci -P/var/state -q get ibrdtn.safetypid` 2> /dev/null >/dev/null
  29. fi
  30. # finally kill really all safety-wrapper!
  31. /bin/sleep 2
  32. /usr/bin/killall -9 dtnd-safety-wrapper.sh
  33. # send a kill signal to the daemon
  34. /usr/bin/killall dtnd 2> /dev/null >/dev/null
  35. # wait for some time
  36. TIMEOUT=0;
  37. # check if the daemon is running
  38. while [ -n "`ps | grep dtnd | grep -v grep`" ]; do
  39. # check if the daemon is still running
  40. if [ $TIMEOUT -ge 10 ]; then
  41. /bin/echo " killing"
  42. # kill all processes of dtnd
  43. /usr/bin/killall -9 dtnd 2> /dev/null >/dev/null
  44. return
  45. fi
  46. # increment timeout
  47. TIMEOUT=`expr $TIMEOUT + 1`
  48. echo -n "."
  49. # wait some time
  50. /bin/sleep 1
  51. done
  52. echo " done"
  53. }