一、Nginx开机启动设置
1、在/etc/init.d/目录下创建脚本
vi /etc/init.d/nginx
2、更改脚本权限
chmod 775 /etc/init.d/nginx
3、编写脚本内容
#! /bin/sh
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
SCRIPTNAME=/etc/init.d/$NAME
PIDFILE=/var/run/$NAME.pid
# If the daemon file is not found, terminate the script.
test -x $DAEMON || exit 0
d_start() {
$DAEMON || echo -n " already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " could not 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 "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
# Sleep for two seconds before starting again, this should give the
# Nginx daemon some time to perform a graceful stop.
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
4、设置开机启动
这里说明,Ubuntu 中系统没有了RH系统中的 chkconfig 命令 !
可用一些小工具来管理 Ubuntu 的启动选项,rcconf:
#sudo apt-get rcconf
#sudo apt-get install rcconf
root 下运行: #sudo rcconf
功能更全的工具:sysv-rc-conf
#sudo apt-get update
#sudo apt-get install sysv-rc-conf
运行:#sudo sysv-rc-conf
也可以直接加入启动程序,例如把 /etc/init.d/red5 加入到系统自动启动列表中:
#sudo sysv-rc-conf red5 on
其他使用方法见: google::Ubuntu::sysv-rc-conf 命令用法
二、PHP开机启动设置
1、在/etc/init.d/目录下创建脚本
vi /etc/init.d/php-fpm
2、更改脚本权限
chmod 775 /etc/init.d/php-fpm
3、编写脚本内容
#!/bin/sh # # php-fpm - this script starts and stops the php-fpm daemin # # chkconfig: - 85 15 # processname: php-fpm # config: /usr/local/php/etc/php-fpm.conf set -e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="php-fpm daemon" NAME=php-fpm DAEMON=/usr/local/php5.6/sbin/$NAME CONFIGFILE=/usr/local/php5.6/etc/$NAME.conf PIDFILE=/var/run/php-fpm5.pid SCRIPTNAME=/etc/init.d/php-fpm5 # If the daemon file is not found, terminate the script. test -x $DAEMON || exit 0 d_start(){ $DAEMON -y $CONFIGFILE || echo -n " already running" } d_stop(){ kill -QUIT `cat $PIDFILE` || echo -n " no running" } d_reload(){ kill -HUP `cat $PIDFILE` || echo -n " could not 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 "Reloaded." ;; restart) echo -n "Restarting $DESC: $NAME" d_stop # Sleep for two seconds before starting again, this should give the nginx daemon some time to perform a graceful stop sleep 2 d_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload)" >&2 exit 3 ;; esac exit 0
4、通过上面的自启动方法来设置。
三、MySQL开机启动设置
1、复制相关文件
cp -a ./support-files/my-default.cnf /etc/my.cnf
cp -a ./support-files/mysql.server /etc/init.d/mysqld
2、设置如上
四、Redis开机启动设置
1、在/etc/init.d/目录下创建脚本
vi /etc/init.d/redis
2、更改脚本权限
chmod 775 /etc/init.d/redis
3、编写脚本内容
#!/bin/sh
# chkconfig: 2345 10 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF &
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
4、通过上面的自启动方法来设置。