Guest User

Untitled

a guest
Nov 1st, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. root@DS715:~# more /var/packages/AutoSub-BootstrapBill/scripts/start-stop-status
  2. #!/bin/sh
  3.  
  4. # Package
  5. PACKAGE="autosub-bootstrapbill"
  6. DNAME="AutoSub-BootstrapBill"
  7.  
  8. # Others
  9. INSTALL_DIR="/usr/local/${PACKAGE}"
  10. PYTHON_DIR="/usr/local/python"
  11. PYTHON=${PYTHON_DIR}/bin/python
  12. PATH="${PYTHON_DIR}/bin:/usr/local/bin:/bin:/usr/bin:/usr/syno/bin"
  13. RUNAS="${PACKAGE}"
  14. PROG_PY="${INSTALL_DIR}/AutoSub.py"
  15. LOG_FILE="${INSTALL_DIR}/AutoSubService.log"
  16. PID_FILE="${INSTALL_DIR}/autosub.pid"
  17.  
  18. start_daemon ()
  19. {
  20. # Launch the application in the background
  21. if [ -f ${INSTALL_DIR}/config.properties ]
  22. then
  23. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -c "${INSTALL_DIR}/config.properties" -d -l"
  24. echo `ps aux | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $2}' > $PID_FILE`
  25. else
  26. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -d -l"
  27. echo `ps aux | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $2}' > $PID_FILE`
  28.  
  29. fi
  30.  
  31. }
  32.  
  33. stop_daemon ()
  34. {
  35. # Kill the application
  36. kill `cat ${PID_FILE}`
  37. wait_for_status 1 20
  38. rm -f ${PID_FILE}
  39. }
  40.  
  41. daemon_status ()
  42. {
  43. if [ -f ${PID_FILE} ] && [ -d /proc/`cat ${PID_FILE}` ]; then
  44. return
  45. fi
  46. return 1
  47. }
  48.  
  49. run_in_console ()
  50. {
  51. # Launch the application in the foreground
  52. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -c "${INSTALL_DIR}/config.properties" -l"
  53. echo `ps aux | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $2}' > $PID_FILE`
  54. }
  55.  
  56. wait_for_status ()
  57. {
  58. counter=$2
  59. while [ ${counter} -gt 0 ]; do
  60. daemon_status
  61. [ $? -eq $1 ] && break
  62. let counter=counter-1
  63. sleep 1
  64. done
  65. }
  66.  
  67. case $1 in
  68. start)
  69. if daemon_status; then
  70. echo ${DNAME} is already running
  71. exit 0
  72. else
  73. echo Starting ${DNAME} ...
  74. start_daemon
  75. exit $?
  76. fi
  77. ;;
  78. stop)
  79. if daemon_status; then
  80. echo Stopping ${DNAME} ...
  81. stop_daemon
  82. exit $?
  83. else
  84. echo ${DNAME} is not running
  85. exit 0
  86. fi
  87. ;;
  88. restart)
  89. stop_daemon
  90. start_daemon
  91. exit $?
  92. ;;
  93. status)
  94. if daemon_status; then
  95. echo ${DNAME} is running
  96. exit 0
  97. else
  98. echo ${DNAME} is not running
  99. exit 1
  100. fi
  101. ;;
  102. console)
  103. run_in_console
  104. exit $?
  105. ;;
  106. log)
  107. echo ${LOG_FILE}
  108. exit 0
  109. ;;
  110. *)
  111. exit 1
  112. ;;
  113. esac
  114. root@DS715:~#
Advertisement
Add Comment
Please, Sign In to add comment