Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: php-fastcgi
  4. # Required-Start: $all
  5. # Required-Stop: $all
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: Start and stop php-cgi in external FASTCGI mode
  9. # Description: Start and stop php-cgi in external FASTCGI mode
  10. ### END INIT INFO
  11.  
  12. # Do NOT "set -e"
  13.  
  14. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. DESC="php-cgi in external FASTCGI mode"
  16. NAME=php-fastcgi
  17. DAEMON=/usr/bin/php-cgi
  18. PIDFILE=/var/run/$NAME.pid
  19. SCRIPTNAME=/etc/init.d/$NAME
  20. PHP_CONFIG_FILE=/etc/php5/cgi/php.ini
  21.  
  22. # Exit if the package is not installed
  23. [ -x "$DAEMON" ] || exit 0
  24.  
  25. # Read configuration variable file if it is present
  26. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  27.  
  28. # Load the VERBOSE setting and other rcS variables
  29. . /lib/init/vars.sh
  30.  
  31. # Define LSB log_* functions.
  32. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  33. . /lib/lsb/init-functions
  34.  
  35. # If the daemon is not enabled, give the user a warning and then exit,
  36. # unless we are stopping the daemon
  37. if [ "$START" != "yes" -a "$1" != "stop" ]; then
  38. log_warning_msg "To enable $NAME, edit /etc/default/$NAME and set START=yes"
  39. exit 0
  40. fi
  41.  
  42. # Process configuration
  43. export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS
  44. DAEMON_ARGS="-q -b $FCGI_HOST:$FCGI_PORT -c $PHP_CONFIG_FILE"
  45.  
  46. do_start()
  47. {
  48. # Return
  49. # 0 if daemon has been started
  50. # 1 if daemon was already running
  51. # 2 if daemon could not be started
  52. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  53. || return 1
  54. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
  55. --background --make-pidfile --chuid $EXEC_AS_USER --startas $DAEMON -- \
  56. $DAEMON_ARGS \
  57. || return 2
  58. }
  59.  
  60. do_stop()
  61. {
  62. # Return
  63. # 0 if daemon has been stopped
  64. # 1 if daemon was already stopped
  65. # 2 if daemon could not be stopped
  66. # other if a failure occurred
  67. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE > /dev/null # --name $DAEMON
  68. RETVAL="$?"
  69. [ "$RETVAL" = 2 ] && return 2
  70. # Wait for children to finish too if this is a daemon that forks
  71. # and if the daemon is only ever run from this initscript.
  72. # If the above conditions are not satisfied then add some other code
  73. # that waits for the process to drop all resources that could be
  74. # needed by services started subsequently. A last resort is to
  75. # sleep for some time.
  76. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  77. [ "$?" = 2 ] && return 2
  78. # Many daemons don’t delete their pidfiles when they exit.
  79. rm -f $PIDFILE
  80. return "$RETVAL"
  81. }
  82. case "$1" in
  83. start)
  84. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  85. do_start
  86. case "$?" in
  87. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  88. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  89. esac
  90. ;;
  91. stop)
  92. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  93. do_stop
  94. case "$?" in
  95. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  96. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  97. esac
  98. ;;
  99. restart|force-reload)
  100. log_daemon_msg "Restarting $DESC" "$NAME"
  101. do_stop
  102. case "$?" in
  103. 0|1)
  104. do_start
  105. case "$?" in
  106. 0) log_end_msg 0 ;;
  107. 1) log_end_msg 1 ;; # Old process is still running
  108. *) log_end_msg 1 ;; # Failed to start
  109. esac
  110. ;;
  111. *)
  112. # Failed to stop
  113. log_end_msg 1
  114. ;;
  115. esac
  116. ;;
  117. *)
  118. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
  119. exit 3
  120. ;;
  121. esac
Add Comment
Please, Sign In to add comment