Guest User

Untitled

a guest
Mar 26th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. DS211> 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 w | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $1}' > $PID_FILE`
  25. else
  26. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -d -l"
  27. echo `ps w | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $1}' > $PID_FILE`
  28. fi
  29.  
  30. }
  31.  
  32. stop_daemon ()
  33. {
  34. # Kill the application
  35. kill `cat ${PID_FILE}`
  36. wait_for_status 1 20 || kill -9 `cat ${PID_FILE}`
  37. rm -f ${PID_FILE}
  38. }
  39.  
  40.  
  41. daemon_status ()
  42. {
  43. if [ -f ${PID_FILE} ] && kill -0 `cat ${PID_FILE}` > /dev/null 2>&1; then
  44. return
  45. fi
  46. rm -f ${PID_FILE}
  47. return 1
  48. }
  49.  
  50. run_in_console ()
  51. {
  52. # Launch the application in the foreground
  53. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -c "${INSTALL_DIR}/config.properties" -l"
  54. echo `ps w | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $1}' > $PID_FILE`
  55. }
  56.  
  57. case $1 in
  58. start)
  59. if daemon_status; then
  60. echo ${DNAME} is already running
  61. exit 0
  62. else
  63. echo Starting ${DNAME} ...
  64. start_daemon
  65. exit $?
  66. fi
  67. ;;
  68. stop)
  69. if daemon_status; then
  70. echo Stopping ${DNAME} ...
  71. stop_daemon
  72. exit $?
  73. else
  74. echo ${DNAME} is not running
  75. exit 0
  76. fi
  77. ;;
  78. status)
  79. if daemon_status; then
  80. echo ${DNAME} is running
  81. exit 0
  82. else
  83. echo ${DNAME} is not running
  84. exit 1
  85. fi
  86. ;;
  87. console)
  88. run_in_console
  89. exit $?
  90. ;;
  91. log)
  92. echo ${LOG_FILE}
  93. exit 0
  94. ;;
  95. *)
  96. exit 1
  97. ;;
  98. esac
  99. DS211>
Advertisement
Add Comment
Please, Sign In to add comment