目录
0x00 nginx php apache 启动脚本:
因为之前已经弄好了mysql的启动脚本:
/etc/init.d/mysql start restart stop 所以这里就没有mysql了。
/etc/init.d/functions 是系统提供给我们一个公共的类,里面有很多现成的函数
例如:
只要将应用的启动文件的路径传给以上函数就可以使用了。演示如下:
#! /bin/bash
. /etc/init.d/functions
daemon /usr/local/nginx/sbin/nginx
#killproc /usr/local/nginx/sbin/nginx
pidofproc /usr/local/nginx/sbin/nginx
nginx.sh
#! /bin/bash
#==============================
#this is start nginx script
#author:Rerere
#date:2020 3 22
#==============================
#include functions
. /etc/init.d/functions
exec=/usr/local/nginx/sbin/nginx
function printColor(){
echo -e "\033[$1m $2 \033[0m"
}
#该文件标志着nginx已经启动成功
lock_file=/var/lock/subsys/nginx
function start(){
pidofproc $exec > /dev/null
[ $? -eq 0 ] && printColor 31 "nginx has already started" && exit
daemon $exec
#如果启动成功就创建一个文件来标志已经启动成功
[ $? -eq 0 ] && printColor 32 "start nginx successfully" && touch $lock_file
}
function stop(){
pidofproc $exec > /dev/null
[ $? -ne 0 ] && printColor 31 "nginx has already stoped" && exit
killproc $exec
[ $? -eq 0 ] && printColor 32 "kill nginx successfully"
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
printColor 31 "USAGE:nginx [start|stop|restart]"
;;
esac
cp nginx.sh /etc/init.d/nginx
cp php.sh /etc/init.d/php-fpm
0x01设置开机自启动
chkconfig --list 列出非系统的开机管理列表
只要3 4 5是开,那么就代表该进程是开机自启动的
systemctl list-unit-files 列出系统的开机管理列表
systemctl disable firewalld //禁止防火墙开机自启动
在脚本开始的 部分加上 #chkconfig: - 50 60
chkconfig --add nginx 添加到 开机管理列表
chkconfig nginx on 设置开机自启动