Guest User

Untitled

a guest
Mar 12th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Package
  4. PACKAGE="autosub-bootstrapbill"
  5. DNAME="AutoSub-BootstrapBill"
  6.  
  7. # Others
  8. INSTALL_DIR="/usr/local/${PACKAGE}"
  9. PYTHON_DIR="/usr/local/python"
  10. PYTHON=${PYTHON_DIR}/bin/python
  11. PATH="${PYTHON_DIR}/bin:/usr/local/bin:/bin:/usr/bin:/usr/syno/bin"
  12. RUNAS="${PACKAGE}"
  13. PROG_PY="${INSTALL_DIR}/AutoSub.py"
  14. LOG_FILE="${INSTALL_DIR}/AutoSubService.log"
  15. PID_FILE="${INSTALL_DIR}/autosub.pid"
  16.  
  17. start_daemon ()
  18. {
  19. # Launch the application in the background
  20. if [ -f ${INSTALL_DIR}/config.properties ]
  21. then
  22. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -c "${INSTALL_DIR}/config.properties" -d -l"
  23. echo `ps w | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $1}' > $PID_FILE`
  24. else
  25. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -d -l"
  26. echo `ps w | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $1}' > $PID_FILE`
  27. fi
  28.  
  29. }
  30.  
  31. stop_daemon ()
  32. {
  33. # Kill the application
  34. kill `cat ${PID_FILE}`
  35. wait_for_status 1 20 || kill -9 `cat ${PID_FILE}`
  36. rm -f ${PID_FILE}
  37. }
  38.  
  39.  
  40. daemon_status ()
  41. {
  42. if [ -f ${PID_FILE} ] && kill -0 `cat ${PID_FILE}` > /dev/null 2>&1; then
  43. return
  44. fi
  45. rm -f ${PID_FILE}
  46. return 1
  47. }
  48.  
  49. wait_for_status ()
  50. {
  51. counter=$2
  52. while [ ${counter} -gt 0 ]; do
  53. daemon_status
  54. [ $? -eq $1 ] && break
  55. let counter=counter-1
  56. sleep 1
  57. done
  58. }
  59.  
  60. run_in_console ()
  61. {
  62. # Launch the application in the foreground
  63. su - ${RUNAS} -c "PATH=${PATH} ${PYTHON} ${PROG_PY} -c "${INSTALL_DIR}/config.properties" -l"
  64. echo `ps w | grep ${PACKAGE} | grep -v -E 'grep' | awk '{print $1}' > $PID_FILE`
  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. status)
  89. if daemon_status; then
  90. echo ${DNAME} is running
  91. exit 0
  92. else
  93. echo ${DNAME} is not running
  94. exit 1
  95. fi
  96. ;;
  97. console)
  98. run_in_console
  99. exit $?
  100. ;;
  101. log)
  102. echo ${LOG_FILE}
  103. exit 0
  104. ;;
  105. *)
  106. exit 1
  107. ;;
  108. esac
Advertisement
Add Comment
Please, Sign In to add comment