Advertisement
Binomico

pyLoad startup script QNAP

Jan 5th, 2012
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. ##########################################################################
  4. # pyLoad STARTUP SCRIPT for QNAP pyload-noarch.ipk
  5. # AUTOSTART pyLoad as DAEMON - UPDATE PROGRAM FILES
  6. # <./S99pyload info>  for  more  details  and  help
  7. ##########################################################################
  8.  
  9. PATH=/opt/bin:/opt/sbin:/opt/share/pyload:/sbin:/bin:/usr/sbin:/usr/bin
  10. DAEMON="pyLoadCore --daemon"
  11. DAEMON_OPTS="--debug"
  12. QUIT="pyLoadCore --quit"
  13. STATUS="pyLoadCore --status"
  14. VERSION="pyLoadCore --version"
  15. UPDATE_SRC="https://bitbucket.org/spoob/pyload/get/tip.zip"
  16.  
  17.  
  18. ##########################################################################
  19. # COMMANDS START
  20. ##########################################################################
  21.  
  22. start()
  23. {
  24.         if [ `$STATUS` = false ]; then
  25.           echo "try to start `$VERSION`"
  26.           echo "`$VERSION`" `$DAEMON`
  27.           sleep 2
  28.         else
  29.         echo "`$VERSION` is already up, nothing to do!"
  30.         fi
  31.                if [ `$STATUS` != false ]; then
  32.                    echo "`$VERSION` successfully started"
  33.                else
  34.                   `$DAEMON`
  35.                fi
  36. }
  37.  
  38. ##########################################################################
  39.  
  40. stop()
  41. {
  42.           if [ `$STATUS` != false ]; then
  43.           echo "try to stop `$VERSION`"
  44.           echo "`$QUIT`"
  45.           else
  46.         echo "`$VERSION` is not running, nothing to do!"
  47.         fi
  48. }
  49.  
  50. ##########################################################################
  51.  
  52. update()
  53. {
  54.         if [ `$STATUS` != false ];then
  55.         stop; sleep 5;
  56.         else
  57.         echo "try to update `$VERSION`"
  58.         fi
  59.         cd /opt #edit path
  60.         wget --no-check-certificate -q `$UPDATE_SRC`
  61.               if [ $? -eq 0 ] ; then
  62.                  echo "successfully loaded dev version"
  63.               else
  64.                  update
  65.               fi
  66.               unzip-unzip -q tip.zip; rm tip.zip
  67.               if [ $? -eq 0 ] ; then
  68.                  echo "archive unzipped and removed"; sleep 2
  69.               else
  70.                  update
  71.               fi
  72.                  rsync -qr /opt/spoob*/ /opt/share/pyload/ # edit path
  73.               if [ $? -eq 0 ] ; then
  74.                  echo "`$VERSION` successfully updated"
  75.               else
  76.                  update
  77.               fi
  78.                 # rm -rf /opt/spoob*/
  79.         echo "`date '+%d.%m.%Y %T'` INFO      Update complete"
  80.               start
  81. }
  82.  
  83. ###############################################################################
  84.  
  85. debug()
  86. {
  87.     if [ `$STATUS` != false ]; then
  88.         echo "restart `$VERSION`"
  89.         stop
  90.         sleep 5
  91.         debug
  92.     else
  93.         echo "try to start in debug mode and print out debug log"
  94.         echo "`$VERSION`:" `$DAEMON $DAEMON_OPTS`
  95.         sleep 2
  96.         if [ `$STATUS` != false ]; then
  97.                echo "successfully started debug mode"
  98.                echo ""
  99.                echo "***** ctrl + c to STOP OUTPUT and return *****"
  100.                echo ""
  101.                tail -f $LOG
  102.         else
  103.                `$DAEMON $DAEMON_OPTS`
  104.         fi
  105.     fi
  106. }
  107.  
  108. ##########################################################################
  109.  
  110. info()
  111. {
  112.      if [ `$STATUS` != false ];then
  113.           echo "`$VERSION` Process ID is `$STATUS`"
  114.           echo ""
  115. echo -e '\e[33m####################################################################\e[0m'
  116. echo -e '\e[33m# OPERATIONS\e[0m'
  117. echo -e '\e[33m# start   = start pyLoad (default)\e[0m'
  118. echo -e '\e[33m# stop    = stop pyLoad\e[0m'
  119. echo -e '\e[33m# restart = stop and start pyLoad\e[0m'
  120. echo -e '\e[33m# debug   = enable debug mode + output\e[0m'
  121. echo -e '\e[33m# info    = print out PID and status of pyLoad\e[0m'
  122. echo -e '\e[33m# show    = print out Logfile while executing\e[0m'
  123. echo -e '\e[33m####################################################################\e[0m'
  124.  
  125.      else
  126.            echo "`$VERSION` process is not active, nothing to do!"
  127.      fi
  128. }
  129.  
  130. ##########################################################################
  131.  
  132. show()
  133. {
  134.      start
  135.      while [ `$STATUS` != false ]; do
  136.         echo ""
  137.         echo "***** ctrl + c to STOP OUTPUT and return *****"
  138.         echo ""
  139.         tail -f $LOG
  140.      done
  141. }
  142.  
  143. ##########################################################################
  144.  
  145. case "$1" in
  146.       start)
  147.               start
  148.               ;;
  149.       stop)
  150.               stop
  151.               ;;
  152.       restart)
  153.               stop
  154.               sleep 5
  155.               start
  156.               ;;
  157.       update)
  158.               update
  159.               ;;
  160.       debug)
  161.               debug
  162.               ;;
  163.       info)
  164.               info
  165.               ;;
  166.       show)
  167.               show
  168.               ;;
  169.       *)
  170. echo "Usage: (start|stop|restart|update|debug|info|show)" >&2
  171.               exit 1
  172.               ;;
  173. esac
  174.  
  175.  
  176. exit 0
  177. ##########################################################################
  178. # End of script
  179. ##########################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement