目的:讓nginx随伺服器啟動
作業系統:
<code>
Linux localhost.localdomain 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux
</code>
以下内容儲存為檔案nginx到/etc/init.d/目錄下
<code>
#! /bin/sh
# chkconfig: - 58 74
# description: nginx is the Nginx daemon.
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'sudo update-rc.d nginx defaults', or use the appropriate command on your
# distro.
#
# Author: Ryan Norbauer
# Modified: Geoffrey Grosenbach http://topfunky.com
# Modified: David Krmpotic http://davidhq.com
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -c $CONFIGFILE || echo -en "\n already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -en "\n not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
d_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# One second might not be time enough for a daemon to stop,
# if this happens, d_start will fail (and dpkg will break if
# the package is being upgraded). Change the timeout if needed
# be, or change d_stop to have start-stop-daemon use --retry.
# Notice that using --retry slows down the shutdown process
somewhat.
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
</code>
然後
1
sudo chmod +x nginx
然後
1
sudo /sbin/chkconfig --level 345 nginx on
這裡說明需要說明一下,
# chkconfig: - 58 74
# description: nginx is the Nginx daemon.
腳本中這兩句注釋一定要的,表明是chkconfig支援的格式。不然會有類似下面的提示:
service nginx does not support chkconfig
進一步可參考這裡
完成,reboot就可以看到nginx自動啟動。
Ubuntu可參考:nginx.sh 和 這裡
Update(2008-1-31):關于chkconfig的更多資訊,看這裡
收藏、分享這篇文章!
Related posts:
1. 使用Nginx和Mongrel Cluster部署Rails應用 本文介紹在Linux上以Nginx為前端、Mongrel Cluster為後端部署Rails應用的方法及步驟。 平台:Ubuntu 7.10 (Gutsy Gibbon) Nginx簡介Nginx是由俄羅斯人Igor Sysoev開發的一款HTTP伺服器。它有以下特點:輕量小巧(相對于Apache等) 快速高效...
2. shoulda on rails 在新項目中配置shoulda rails shoulda_demo -d mysql cd shoulda_demo/ script/plugin install git://github.com/thoughtbot/shoulda.git...
3. Satellite: a self-syncing distributed wiki 介紹 satellite is a self-syncing distributed wiki with file uploads...
Related posts brought to you by Yet Another Related Posts Plugin.