Advertisement
schenette

OC Deamon

Oct 7th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides: twistedplugin
  5. # Required-Start: $all
  6. # Required-Stop: $all
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: Starts a service for the Twisted plugin 'ocapi'
  10. # Description: Service to interface with OC API
  11. ### END INIT INFO
  12. # Author: Stephan Chenette <removed>
  13.  
  14. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  15. DAEMON=/usr/bin/twistd
  16. RUNAS=root
  17. SERVICE_NAME=ocapi
  18. SERVICE_PATH=/usr/sbin/ocapi.py
  19. PIDFILE=/var/run/ocapi.pid
  20. LOGFILE=/var/log/ocapi.log
  21. DAEMON_OPTS="--umask=000 --pidfile=${PIDFILE} --logfile=${LOGFILE} --python ${SERVICE_PATH}"
  22.  
  23. # Set python path so twistd can find the plugin
  24. # See: http://twistedmatrix.com/projects/core/documentation/howto/plugin.html
  25. export PYTHONPATH=$SERVICE_DIR
  26.  
  27. if [ ! -x $DAEMON ]; then
  28. echo "ERROR: Can't execute $DAEMON."
  29. exit 1
  30. fi
  31.  
  32. if [ ! -x $SERVICE_PATH ]; then
  33. echo "ERROR: Can't execute: $SERVICE_PATH"
  34. exit 1
  35. fi
  36.  
  37. start_service() {
  38. echo -n " * Starting $SERVICE_NAME... "
  39. start-stop-daemon -Sq --chuid ${RUNAS} --group ${RUNAS} -p $PIDFILE -x $DAEMON -- $DAEMON_OPTS
  40. e=$?
  41. if [ $e -eq 1 ]; then
  42. echo "already running"
  43. return
  44. fi
  45.  
  46. if [ $e -eq 255 ]; then
  47. echo "couldn't start :("
  48. return
  49. fi
  50.  
  51. echo "done"
  52. }
  53.  
  54. stop_service() {
  55. echo -n " * Stopping $SERVICE_NAME... "
  56. start-stop-daemon -Kq -R 10 -p $PIDFILE
  57. e=$?
  58. if [ $e -eq 1 ]; then
  59. echo "not running"
  60. return
  61. fi
  62.  
  63. echo "done"
  64. }
  65.  
  66. case "$1" in
  67. start)
  68. start_service
  69. ;;
  70. stop)
  71. stop_service
  72. ;;
  73. restart)
  74. stop_service
  75. start_service
  76. ;;
  77. *)
  78. echo "Usage: /etc/init.d/$SERVICE_NAME {start|stop|restart}" >&2
  79. exit 1
  80. ;;
  81. esac
  82.  
  83. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement