目錄
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 設置開機自啓動