Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 13th, 2012  |  syntax: Bash  |  size: 2.33 KB  |  views: 136  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2. #
  3. # Ian - 16/11/2011
  4. # /etc/init.d/newznab: start and stop the newznab update script
  5. #
  6. # run update-rc.d newznab_ubuntu.sh defaults
  7.  
  8.  
  9. ### BEGIN INIT INFO
  10. # Provides:          Newznab
  11. # Required-Start:    $remote_fs $syslog
  12. # Required-Stop:     $remote_fs $syslog
  13. # Default-Start:     2 3 4 5
  14. # Default-Stop:      0 1 6
  15. # Short-Description: Start newznab at boot time
  16. # Description:       Enable newznab service provided by daemon.
  17. ### END INIT INFO
  18.  
  19. RED=$(tput setaf 1)
  20. GREEN=$(tput setaf 2)
  21. NORMAL=$(tput sgr0)
  22.  
  23. col=20
  24.  
  25.  
  26. # Newznab variables
  27. NN_PATH="/var/www/misc/update_scripts"
  28. NN_BINUP="update_binaries.php"
  29. NN_RELUP="update_releases.php"
  30. NN_SLEEP_TIME="10" # in seconds . 10sec is good for 100s of groups. 600sec might be a good start for fewer.
  31. NN_PID_PATH="/var/run/"
  32. SCREEN_NAME="newznab"
  33. PGREP_SEARCH="SCREEN -dmS $SCREEN_NAME"
  34. PIDFILE="newznab.pid"
  35. PRETTY_NAME="Newznab binaries update"
  36.  
  37. test -f /lib/lsb/init-functions || exit 1
  38. . /lib/lsb/init-functions
  39.  
  40.  
  41. do_start() {
  42.         if pgrep -f "$PGREP_SEARCH" > /dev/null
  43.         then
  44.            echo "$PRETTY_NAME is already running.";
  45.            return 1;
  46.         fi
  47.         echo -n "Starting $PRETTY_NAME ... "
  48.         screen -dmS ${SCREEN_NAME} /var/www/misc/update_scripts/nix_scripts/newznab_local.sh &
  49.         PID=`echo $!`
  50.         echo $PID > ${NN_PID_PATH}${PIDFILE}
  51.         sleep 1
  52.         if pgrep -f "$PGREP_SEARCH" > /dev/null
  53.         then
  54.           printf '%s%*s%s\n' "$GREEN" $col '[OK]' "$NORMAL"
  55.         else
  56.           printf '%s%*s%s\n' "$RED" $col '[FAILED]' "$NORMAL"
  57.         fi
  58. }
  59.  
  60. do_stop() {
  61.         echo -n "Stopping Newznab binaries update ... "
  62.         if pgrep -f "$PGREP_SEARCH" > /dev/null
  63.         then
  64.           kill -9 `pgrep -f "$PGREP_SEARCH"`
  65.           screen -wipe
  66.         fi
  67.         printf '%s%*s%s\n' "$GREEN" $col '[OK]' "$NORMAL"
  68. }
  69.  
  70. do_status() {
  71.         if  pgrep -f "$PGREP_SEARCH" > /dev/null
  72.         then
  73.           echo "$PRETTY_NAME is running."
  74.         else
  75.           echo "$PRETTY_NAME is not running."
  76.         fi
  77. }
  78.  
  79.  
  80. case "$1" in
  81.   start)
  82.         do_start
  83.         ;;
  84.   stop)
  85.         do_stop
  86.         ;;
  87.   status)
  88.         do_status
  89.         ;;
  90.   restart)
  91.         do_stop
  92.         do_start
  93.         ;;
  94.   *)
  95.         echo "Usage: $0 [start|stop|status|restart]"
  96.         exit 1
  97. esac
clone this paste RAW Paste Data