Advertisement
Guest User

Untitled

a guest
Apr 30th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.70 KB | None | 0 0
  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          rssdler
  4. # Required-Start:    $local_fs $remote_fs $network $syslog $named
  5. # Required-Stop:     $local_fs $remote_fs $network $syslog $named
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      0 1 6
  8. # X-Interactive:     true
  9. # Short-Description: Start/stop rssdler
  10. # Description:       Runs rssdler as a background daemon. Edit /etc/init.d/rssdler to reflect local paths and configuration files.
  11. ### END INIT INFO
  12.  
  13. # You must change user
  14. # if you installed with setup.py
  15. # and keep your config in ~/.rssdler/config.txt
  16. # that is all you need to change here
  17. # otherwise, edit  NAME, DAEMON, CONFIGFILE to suit needs
  18. # chmod 755 /etc/init.d/rssdler
  19. # sudo chown root:root /etc/init.d/rssdler
  20. # sudo update-rc.d rssdler defaults
  21.  
  22. ########
  23. #BEGIN CONFIG
  24. ########
  25. # user to run RSSDler as
  26. user='ANVÄNDARE'
  27. #where is the config file found
  28. CONFIGFILE="`su -c 'echo $HOME' $user`/.rssdler/config.txt"
  29. # name you saved RSSDler to
  30. NAME='rssdler.py'
  31. DIRECTORY="`su -c 'echo $HOME' $user`/.rssdler/rssdler042"
  32. #directory you put rssdler, plus $NAME is the name of it
  33. DAEMON="${DIRECTORY}/${NAME}"
  34. # options to pass to RSSDler
  35. DAEMON_ARGS="-d -c '$CONFIGFILE'"
  36. #where to log errors from this script
  37. logfile="/var/log/rssdler.log"
  38. ########
  39. #END CONFIG
  40. ########
  41.  
  42. WORKINGDIR=`cat "$CONFIGFILE" | grep -i "^workingDir" | sed -r "s/^workingDir\s*=\s*(.*)/\1/i"`
  43. if [ -z $WORKINGDIR ] ; then
  44.   WORKINGDIR="`su -c 'echo $HOME' $user`/.rssdler/"
  45. fi
  46. PIDFILE=`cat "$CONFIGFILE" | grep -i "^daemonInfo" | sed -r "s/^daemonInfo\s*=\s*(.*)/\1/i"`
  47. if [ -z $PIDFILE ] ; then
  48.   PIDFILE="$WORKINGDIR/daemon.info"
  49. fi
  50. PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin
  51. DESC="RSSDler"
  52. SCRIPTNAME=/etc/init.d/rssdler
  53.  
  54. # Exit if the package is not installed
  55. cd / # make sure we aren't looking at rssdler init script
  56. exists=0
  57. if ! [ -x "$DAEMON" ]  ; then
  58. for i in `echo "$PATH" | tr ':' '\n'` ; do
  59.     if [ -f $i/$DAEMON ] ; then
  60.         exists=1
  61. #   DAEMON=$i/$DAEMON
  62.         break
  63.     fi
  64. done
  65. if [ $exists -eq 0 ] ; then
  66.     echo "cannot find daemon $DAEMON in PATH $PATH" | tee -a "$logfile" >&2
  67.     exit 3
  68. fi
  69. fi
  70.  
  71. if [ -z $PIDFILE ] ; then
  72.     echo "you didn't specify daemonInfo in your config file, nor is it where I expect"  | tee -a "$logfile" >&2
  73.     exit 1
  74. fi
  75.  
  76. if [ -z $WORKINGDIR ] ; then
  77.     echo "you didn't specify a workingDir in your config file"  | tee -a "$logfile" >&2
  78.     exit 1
  79. fi
  80.  
  81. if ! [ -d "$WORKINGDIR" ] ; then
  82.     echo "the workingDir you specified does not exist"  | tee -a "$logfile" >&2
  83.     exit 1
  84. fi
  85.  
  86. cd "$WORKINGDIR"
  87.  
  88. # Load the VERBOSE setting and other rcS variables
  89. #. /lib/init/vars.sh
  90.  
  91. # Define LSB log_* functions.
  92. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  93. #. /lib/lsb/init-functions
  94.  
  95. do_start()  {
  96.     if su -c "$DAEMON -s -c $CONFIGFILE > /dev/null 2>&1" $user; then
  97.         echo "already running" | tee -a "$logfile" >&2
  98.         return 1 # daemon already running
  99.     fi
  100.     su -c "$DAEMON $DAEMON_ARGS" $user || return 2
  101. }
  102.  
  103. do_stop()
  104. { # don't run as root so that PIDFILE is always writable by user
  105.     su -c "$DAEMON -k -c '$CONFIGFILE'" $user || return 2
  106. }
  107.  
  108. cd "$WORKINGDIR"
  109.  
  110. case "$1" in
  111.   start)
  112.     echo "Starting $DESC: $NAME" | tee -a "$logfile"
  113.     do_start
  114.     echo "."
  115.     ;;
  116.   stop)
  117.     echo "Stopping $DESC: $NAME" | tee -a "$logfile"
  118.     do_stop
  119.     echo "."
  120.     ;;
  121.   restart|force-reload)
  122.     echo "Restarting $DESC: $NAME" | tee -a "$logfile"
  123.     do_stop
  124.     case "$?" in
  125.       0|1)
  126.         do_start
  127.         ;;
  128.     esac
  129.     echo "."
  130.     ;;
  131.   *)
  132.     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  133.     exit 3
  134.     ;;
  135. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement