複製以下教程到 nano /etc/init.d/nginx 做啓動
#! /bin/sh
#chkconfig:345 60 60
#description:nginx
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/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
今天發現blog打不開了,ping了下IP,可以ping通,然後PUTTY連接到服務器,uptime發現服務器昨天18點重啓過,哎,國內的VPS商真的是不能用啊,技術太差,真的想自己買幾臺服務器,來搞VPS出租,絕對比他們專業,不會動不動就重啓,動不動就連接不上。可能是我租用的這家是用的免費版的vmware吧。好了不發牢騷了,說下重點。知道服務器重啓過,發現是nginx、mysql、php-fpm沒起來。上寫完腳本後。我只直接用了下 chkconfig name on 沒想到根本沒起作用,自己大意了,說下我是如何解決的吧。
chkconfig --help
chkconfig 版本 1.3.30.1 - 版權 (C) 1997-2000 Red Hat, Inc. 在 GNU 公共許可的條款下,本軟件可以被自由發行。 用法: chkconfig --list [name] chkconfig --add chkconfig --del chkconfig [--level ]
我就按照幫助來添加 nginx 服務
chkconfig --add nginx
nginx 服務不支持 chkconfig
#爲什麼不支持呢。 /etc/init.d/nginx start 是沒問題的服務能起來。隨後我就看下SSH服務腳本,看是否我的寫法有問題。
vim /etc/init.d/sshd
# chkconfig: 2345 55 25 # description: OpenSSH server daemon
###看到 腳本前有 這兩行。。。。原來是這麼回事,要告訴 chkconfig 的啓動停止順序,和服務描述
修改腳本 nginx 在 #!/bin/bash 下添加如下
vim /etc/init.d/nginx
#!/bin/bash #chkconfig:345 60 60 #description:nginx
修改腳本 mysqld 在 #!/bin/bash 下添加如下
vim /etc/init.d/mysqld #!/bin/bash #chkconfig:345 62 62 #description:mysqld
修改腳本 php-fpm 在 #!/bin/bash 下添加如下
vim /etc/init.d/php-fpm #! /bin/bash #chkconfig:345 61 61 #description:php-fpm
隨後我們添加服務
chkconfig --add nginx
chkconfig --add php-fpm
chkconfig --add mysqld
chkconfig --list nginx nginx 0:關閉 1:關閉 2:關閉 3:啓用 4:啓用 5:啓用 6:關閉
chkconfig --list mysqld mysqld 0:關閉 1:關閉 2:關閉 3:啓用 4:啓用 5:啓用 6:關閉
chkconfig --list php-fpm php-fpm 0:關閉 1:關閉 2:關閉 3:啓用 4:啓用 5:啓用 6:關閉