下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
#!/bin/bash
#
# Startup script for Nginx - this script starts and stops the Nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server,HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: Nginx
# config: /usr/local/Nginx/conf/Nginx.conf
# pidfile: /usr/local/Nginx/logs/Nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
Nginx="/usr/local/Nginx/sbin/Nginx"
prog=$(basename $Nginx)
Nginx_CONF_FILE="/usr/local/Nginx/conf/Nginx.conf"
[ -f /etc/sysconfig/Nginx ] && . /etc/sysconfig/Nginx
lockfile=/var/lock/subsys/Nginx
start() {
[ -x $Nginx ] || exit 5
[ -f $Nginx_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $Nginx -c $Nginx_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $Nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$Nginx -t -c $Nginx_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
编辑好后保存,执行以下命令
sudo chmod +x /etc/init.d/Nginx
sudo /sbin/chkconfig Nginx on
# 检查一下
sudo /sbin/chkconfig --list Nginx
Nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!可以使用以下命令管理Nginx了
service Nginx start
service Nginx stop
service Nginx restart
service Nginx reload
/etc/init.d/Nginx start
/etc/init.d/Nginx stop
/etc/init.d/Nginx restart
/etc/init.d/Nginx reload
二、PHP-FPM启动脚本/etc/init.d/PHP-fpm
#!/bin/bash
#
# Startup script for the PHP-FPM server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: PHP-fpm
# config: /usr/local/PHP/etc/PHP.ini
# Source function library.
. /etc/rc.d/init.d/functions
PHP_PATH=/usr/local
DESC="PHP-fpm daemon"
NAME=PHP-fpm
# PHP-fpm路径
DAEMON=$PHP_PATH/PHP/sbin/$NAME
# 配置文件路径
CONFIGFILE=$PHP_PATH/PHP/etc/PHP-fpm.conf
# PID文件路径(在PHP-fpm.conf设置)
PIDFILE=$PHP_PATH/PHP/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
rh_start() {
$DAEMON -y $CONFIGFILE || echo -n " already running"
}
rh_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
rh_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
rh_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
rh_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
rh_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
rh_stop
sleep 1
rh_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
编辑好后保存,执行以下命令
sudo chmod +x /etc/init.d/PHP-fpm
sudo /sbin/chkconfig PHP-fpm on
# 检查一下
sudo /sbin/chkconfig --list PHP-fpm
PHP-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
完成!可以使用以下命令管理PHP-fpm了
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。