Guest User

Untitled

a guest
Jun 19th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. cat /etc/init.d/adergunov
  2. #! /bin/sh
  3. ### BEGIN INIT INFO
  4. # Provides: Adergunov
  5. # Default-Start: 2 3 4 5
  6. # Default-Stop: 0 1 6
  7. # Short-Description: Initscript for adergunov
  8. # Description: This file should be used to construct scripts for
  9. # adergunov to be placed in /etc/init.d.
  10. ### END INIT INFO
  11.  
  12. # Author: Alexander Ivanov <alexander.vl.ivanov@gmail.com>
  13.  
  14. # Do NOT "set -e"
  15.  
  16. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  17. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  18. DESC="Daemon of the adergunov"
  19. NAME=adergunov
  20.  
  21. RUN_DIR=/var/run/$NAME
  22. LOG_DIR=/var/log/$NAME
  23. UPLOAD_DIR=/srv/www/adergunov/media/upload
  24.  
  25. PIDFILE=$RUN_DIR/$NAME.pid
  26. SOCKET=$RUN_DIR/$NAME.socket
  27. #HOST=127.0.0.1
  28. #PORT=8080
  29.  
  30. RUN_AS_USER=www-data
  31. RUN_AS_GROUP=www-data
  32.  
  33. DAEMON=/usr/bin/env
  34. # Don`t and spaces or new-lines to DAEMON_ARGS
  35. DAEMON_ARGS="python /srv/www/adergunov/bin/django runfcgi pidfile=$PIDFILE socket=$SOCKET outlog=$LOG_DIR/out.log errlog=$LOG_DIR/err.log minspare=1 maxspare=2 maxchildren=5"
  36.  
  37. SCRIPTNAME=/etc/init.d/$NAME
  38.  
  39. # Exit if the package is not installed
  40. [ -x "$DAEMON" ] || exit 0
  41.  
  42. # Read configuration variable file if it is present
  43. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  44.  
  45. # Load the VERBOSE setting and other rcS variables
  46. . /lib/init/vars.sh
  47.  
  48. # Define LSB log_* functions.
  49. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  50. . /lib/lsb/init-functions
  51.  
  52. #
  53. # Function that starts the daemon/service
  54. #
  55. do_start()
  56. {
  57. # Return
  58. # 0 if daemon has been started
  59. # 1 if daemon was already running
  60. # 2 if daemon could not be started
  61. if ( [ -f $PIDFILE ] && ps --pid $(cat $PIDFILE) > /dev/null ); then
  62. echo -n "$NAME already running."
  63. return 1
  64. else
  65. if [ -f $PIDFILE ]; then
  66. rm -f $PIDFILE
  67. fi
  68.  
  69. # check directories and permissions
  70. mkdir -p $RUN_DIR $LOG_DIR $UPLOAD_DIR
  71. chown -R $RUN_AS_USER:$RUN_AS_GROUP $RUN_DIR $LOG_DIR
  72. chmod -R a-x,u=rwX,g=rX,o= $RUN_DIR $LOG_DIR
  73. find $UPLOAD_DIR ! -perm a-x,ug=rwX,o=rX -exec chmod a-x,ug=rwX,o=rX {} \;
  74. find $UPLOAD_DIR \( ! -user $RUN_AS_USER -or ! -group $RUN_AS_GROUP \) -exec chown $RUN_AS_USER:$RUN_AS_GROUP {} \;
  75.  
  76. start-stop-daemon --start --quiet --pidfile $PIDFILE \
  77. --chuid ${RUN_AS_USER} --group ${RUN_AS_USER}\
  78. --exec $DAEMON -- $DAEMON_ARGS \
  79. || return 2
  80. fi
  81. }
  82.  
  83. #
  84. # Function that stops the daemon/service
  85. #
  86. do_stop()
  87. {
  88. # Return
  89. # 0 if daemon has been stopped
  90. # 1 if daemon was already stopped
  91. # 2 if daemon could not be stopped
  92. # other if a failure occurred
  93. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
  94. RETVAL="$?"
  95. [ "$RETVAL" = 2 ] && return 2
  96. pkill -TERM -f "$DAEMON_ARGS" && sleep 5
  97. pkill -KILL -f "$DAEMON_ARGS" && sleep 1
  98. pgrep -f "$DAEMON_ARGS" && return 2
  99. # Many daemons don't delete their pidfiles when they exit.
  100. rm -f $PIDFILE
  101. return "$RETVAL"
  102. }
  103.  
  104. #
  105. # Function that sends a SIGHUP to the daemon/service
  106. #
  107. do_reload() {
  108. #
  109. # If the daemon can reload its configuration without
  110. # restarting (for example, when it is sent a SIGHUP),
  111. # then implement that here.
  112. #
  113. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
  114. sleep 1
  115. do_start
  116. [ "$?" = 2 ] && return 2
  117. return 0
  118. }
  119.  
  120. case "$1" in
  121. start)
  122. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  123. do_start
  124. case "$?" in
  125. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  126. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  127. esac
  128. ;;
  129. stop)
  130. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  131. do_stop
  132. case "$?" in
  133. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  134. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  135. esac
  136. ;;
  137. reload)
  138. #
  139. # If do_reload() is not implemented then leave this commented out
  140. # and leave 'force-reload' as an alias for 'restart'.
  141. #
  142. do_reload
  143. log_end_msg $?
  144. ;;
  145. restart|force-reload)
  146. #
  147. # If the "reload" option is implemented then remove the
  148. # 'force-reload' alias
  149. #
  150. log_daemon_msg "Restarting $DESC" "$NAME"
  151. do_stop
  152. case "$?" in
  153. 0|1)
  154. do_start
  155. case "$?" in
  156. 0) log_end_msg 0 ;;
  157. 1) log_end_msg 1 ;; # Old process is still running
  158. *) log_end_msg 1 ;; # Failed to start
  159. esac
  160. ;;
  161. *)
  162. # Failed to stop
  163. log_end_msg 1
  164. ;;
  165. esac
  166. ;;
  167. *)
  168. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  169. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  170. exit 3
  171. ;;
  172. esac
  173.  
  174. :
Add Comment
Please, Sign In to add comment