Ubuntu/Debian Nginx init.d脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu/Debian Nginx init.d脚本相关的知识,希望对你有一定的参考价值。

  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

以上是关于Ubuntu/Debian Nginx init.d脚本的主要内容,如果未能解决你的问题,请参考以下文章

如何将 init.d 脚本从 Ubuntu/Debian Linux 转换为 Solaris?

Windows10 WSL2 Ubuntu / Debian # 无网络

sh Ubuntu / Debian包管理

sh ubuntu debian备份恢复包

Ubuntu/Debian查看已经安装的软件包

Ubuntu/Debian下的安装包装换工具—alien