Posted By

funkmyer on 05/06/08


Tagged

ubuntu debian nginx initd


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

fugufish


Ubuntu/Debian Nginx init.d script


 / Published in: Bash
 

URL: http://www.feldpost.com/2007/1/21/boot-script-for-nginx-on-ubuntu-debian-etc

  1. #!/bin/sh
  2.  
  3. #This is a start script for nginx. Tested on Unbuntu Edge.
  4. #Should work on Ubuntu, Debian and probably a few other Linux distros.
  5. #Change DAEMON and CONFIG_FILE if neccessary
  6.  
  7. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  8.  
  9.  
  10. #Location of nginx binary. Change path as neccessary
  11. DAEMON=/usr/local/nginx/sbin/nginx
  12. #Location of configuration file. Change path as neccessary
  13. CONFIG_FILE=/usr/local/nginx/conf/nginx.conf
  14.  
  15.  
  16. DAEMON_OPTS="-c $CONFIG_FILE"
  17. NAME=nginx
  18. DESC="nginx web server"
  19. PIDFILE=/var/run/$NAME.pid
  20. SCRIPTNAME=/etc/init.d/$NAME
  21.  
  22.  
  23. #only run if binary can be found
  24. test -x $DAEMON || exit 0
  25.  
  26. set -e
  27.  
  28. #import init-functions
  29. . /lib/lsb/init-functions
  30.  
  31. case "$1" in
  32. start)
  33. log_daemon_msg "Starting $DESC" $NAME
  34. if ! start-stop-daemon --start --quiet\
  35. --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
  36. log_end_msg 1
  37. else
  38. log_end_msg 0
  39. fi
  40. ;;
  41. stop)
  42. log_daemon_msg "Stopping $DESC" $NAME
  43. if start-stop-daemon --quiet --stop --oknodo --retry 30\
  44. --pidfile $PIDFILE --exec $DAEMON; then
  45. rm -f $PIDFILE
  46. log_end_msg 0
  47. else
  48. log_end_msg 1
  49. fi
  50. ;;
  51. reload)
  52. log_daemon_msg "Reloading $DESC configuration" $NAME
  53. if start-stop-daemon --stop --signal 2 --oknodo --retry 30\
  54. --quiet --pidfile $PIDFILE --exec $DAEMON; then
  55. if start-stop-daemon --start --quiet \
  56. --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS ; then
  57. log_end_msg 0
  58. else
  59. log_end_msg 1
  60. fi
  61. else
  62. log_end_msg 1
  63. fi
  64. ;;
  65. restart|force-reload)
  66. $0 stop
  67. sleep 1
  68. $0 start
  69. ;;
  70. *)
  71. echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  72. exit 1
  73. ;;
  74. esac
  75.  
  76. exit 0

Report this snippet  

You need to login to post a comment.