NGINX SHELL脚本   放到/etc/init.d/下取名nginx

#!/bin/sh
#
# 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
# chkconfig: 2345 90 91
# description: nginx web server
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/nginx.pid # Source function library.
. /etc/init.d/functions # Source networking configuration.
. /etc/sysconfig/network if [ -f /etc/sysconfig/nginx ];then
. /etc/sysconfig/nginx
fi # 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
killall -9 nginx
} 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)
$1
;;
test)
configtest
;;
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|test}"
exit 2
esac

   PHP-FPM SHELL脚本  放到/etc/init.d/下 取名php-fpm

#!/bin/bash
# php-fpm startup script for the php-fpm
# php-fpm version:5.5.0-alpha6
# chkconfig: - 85 15
# description: php-fpm is very good
# processname: php-fpm
# pidfile: /var/run/php-fpm.pid
# config: /usr/local/php/etc/php-fpm.conf php_command=/usr/local/php/sbin/php-fom
php_config=/usr/local/php/etc/php-fpm.conf
php_pid=/usr/local/php/var/run/php-fpm.pid
RETVAL=0
prog="php-fpm" #start function
php_fpm_start() {
/usr/local/php/sbin/php-fpm
} start(){
if [ -e $php_pid ]
then
echo "php-fpm already start..."
exit 1
fi
php_fpm_start
} stop(){
if [ -e $php_pid ]
then
parent_pid=`cat $php_pid`
all_pid=`ps -ef | grep php-fpm | awk '{if('$parent_pid' == $3){print $2}}'`
for pid in $all_pid
do
kill $pid
done
kill $parent_pid
fi
exit 1
} restart(){
stop
start
} # See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
exit 1
esac
exit $RETVAL

  

后续处理:

##  添加执行权限
chmod a+x /etc/init.d/nginx #755
chmod a+x /etc/init.d/php-fpm #755 ## 加入服务
chkconfig --add nginx
chkconfig --add php-fpm ## 开机自启
chkconfig nginx on
chkconfig php-fpm on

  

NGINX、PHP-FPM开机自动启动的更多相关文章

  1. nginx设置成开机自动启动服务

    1.nginx的安装目录 /usr/local/nginx 启动nginx cd /usr/local/nginx/sbin./nginx 更改配置重启nginxcd /usr/local/nginx ...

  2. Window下将nginx配置为开机自动启动

    前两天看到公司window服务器上面有个nginx在跑,重启服务器后没有自动启动,需要手动运行nginx,甚是麻烦呀 上网找了一下关于将nginx配置为系统服务并且开机自动启动的解决方案,这里mark ...

  3. nginx linux 下开机自动启动

    这里使用的是编写shell脚本的方式来处理 vi /etc/init.d/nginx  (输入下面的代码) #!/bin/bash# nginx Startup script for the Ngin ...

  4. nginx + fastDFS 设置开机自动启动

    由于在服务器上有太多的软件 不可能每次启动都要重新启动服务吧(每晚断电...必须重启电脑) vim /etc/rc.d/rc.local 添加下列脚本 /usr/bin/fdfs_trackerd / ...

  5. centos将nginx服务设置为开机自动启动

    centos将nginx服务设置为开机自动启动 1.在/etc/init.d下创建文件nginx 发现原来就有并且配置就是默认的,而且是正确的 命令为: vim /etc/init.d/nginx 需 ...

  6. Nginx设置成服务并开机自动启动

    在/etc/init.d下创建文件nginx [root@localhost ~]# vim /etc/init.d/nginx 其内容参考nginx官方文档 需要注意的配置: nginx=”/usr ...

  7. php-fpm开机自动启动脚本其实源码包里边就有

    网上有各种版本的php-fpm开机自动启动脚本, 其实你编译后源目录已经生成自动脚本.不用做任何修改即用.cp {php-5.5.x-source-dir}/sapi/fpm/init.d.php-f ...

  8. [转] ubuntu16.04添加系统 service, 并设置开机自动启动

    转:https://www.jianshu.com/p/1958878646bd 1. 创建pfly.service文件 2.  执行 systemctl daemon-reload 3. 执行 sy ...

  9. linux启动SSH及开机自动启动

    本文地址 分享提纲: 1.查看是否启动 2. 设置自动启动 1.[查看是否启动] 启动SSH服务 “/etc/init.d/sshd start”.然后用netstat -antulp | grep ...

随机推荐

  1. thinphp下拉获取更多瀑布流效果

    html页面 <body> <script type="text/javascript" src="jquery.min.js">< ...

  2. for循环中i--的妙用 及 两变量互换数值的问题

    int[] array = new int[4]; for(int i = 0; i < array.length; i++){ array[i] = (int)(Math.random() * ...

  3. BZOJ 3196 Tyvj 1730 二逼平衡树 ——树状数组套主席树

    [题目分析] 听说是树套树.(雾) 怒写树状数组套主席树,然后就Rank1了.23333 单点修改,区间查询+k大数查询=树状数组套主席树. [代码] #include <cstdio> ...

  4. Hdu 3564 Another LIS 线段树+LIS

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. AMR 转mp3 失败

    private void changeToMp3(String sourcePath) { File source = new File(sourcePath); String mp3TargetPa ...

  6. JavaScript调用函数的方法

    摘要:这篇文章详细的介绍了Javascript中各种函数调用的方法及其原理,对于理解JavaScript的函数有很大的帮助! 一次又一次的,我发现,那些有bug的Javascript代码是由于没有真正 ...

  7. javascript面向对象(二):构造函数的继承

    本文来自阮一峰 这个系列的第一部分,主要介绍了如何"封装"数据和方法,以及如何从原型对象生成实例. 今天要介绍的是,对象之间的"继承"的五种方法. 比如,现在有 ...

  8. scrollview 嵌套 折叠效果

    ------------------------------- --@ CreateDate: 2015.08.05 --@ Author:     王成成 --@ FileName:   BaoSh ...

  9. Python环境安装

    Windows: 1.Python安装包下载 可以去官网下载安装包:https://www.python.org/downloads/ 2.Python安装 默认安装路径:C:\python27:也可 ...

  10. eclipse从下载到使用

    经常遇到有同学问我: 为啥我的eclipse没有你说的那个东西? 那是咱两选择的平台不一样 我的eclipse为啥和你的那个长的不一样? 那是咱两选择的版本不一样 为什么我的打开报XXX错误? ... ...