$ sudo vim /etc/init.d/nginx
Вставляем нижеследующий код (помним про команду ‘set :paste’ для вставки в VIM):
#!/bin/sh ### BEGIN INIT INFO # Provides: nginx # Required-Start: $remote_fs $syslog $named $network $time # Required-Stop: $remote_fs $syslog $named $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start nginx at boot time # Description: Enable service provided by nginx. ### END INIT INFO # $Id$ NGINXHOME=/usr/local/nginx NGINXPID=$NGINXHOME/logs/nginx.pid PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=$NGINXHOME/sbin/nginx NAME=nginx DESC=nginx if [ ! -x $DAEMON ] then echo "Couldn't find $DAEMON. Please set path to DAEMON." exit 0 fi # Include nginx defaults if available if [ -f /etc/default/nginx ] ; then . /etc/default/nginx fi set -e case "$1" in start) echo -n "Starting $DESC: " start-stop-daemon --start --pidfile $NGINXPID \ --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --pidfile $NGINXPID \ --exec $DAEMON echo "$NAME." ;; restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --pidfile \ $NGINXHOME/run/$NAME.pid --exec $DAEMON sleep 1 start-stop-daemon --start --pidfile \ $NGINXPID --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " start-stop-daemon --stop --signal HUP --pidfile $NGINXPID \ --exec $DAEMON echo "$NAME." ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0
Сохраняем скрипт и выходим из vim.
Делаем скрипт исполняемым:
$ sudo chmod 755 /etc/init.d/nginx
Указываем, что nginx нужно запускать при запуске и остановке сервера:
$ sudo /usr/sbin/update-rc.d -f nginx defaults
UPD: Блок, заключенный между строками
### BEGIN INIT INFO ### END INIT INFO
обеспечивает LSB-совместимость. Подробнее см. http://wiki.debian.org/LSBInitScripts
[...] Взято с http://www.shatlovsky.ru [...]