#functions 公共函数
/etc/init.d/functions
#调用函数
source /etc/init.d/functions . /etc/init.d/functions
#以守护进程形式启动
daemon /usr/local/nginx-1.16.0/sbin/nginx
#退出当前进程
killproc /usr/local/nginx-1.16.0/sbin/nginx
#查看进程
pidofproc /usr/local/nginx-1.16.0/sbin/nginx
#简单的启动脚本
#!/bin/bash #chkconfig: 345 61 61 #description: nginx #=================================== #this is script to manage the nginx #author: xianwei #date: 2019-6-1 #================================== #include the functions . /etc/init.d/functions #define the paramaters: path,file,programm exec=/usr/local/nginx-1.16.0/sbin/nginx lock=/var/lock/subsys/nginx prog=nginx # start action start(){ pidofproc $exec > /dev/null [ $? = 0 ] && echo "$prog is already running" && exit daemon $exec [ $? = 0 ] && echo "start $prog success" && touch $lock } # reload action reload(){ pidofproc $exec > /dev/null [ $? = 0 ] && echo "$prog is running" && killproc $exec -HUP [ $? != 0 ] && echo "$prog does not run" && daemon $exec } # stop action stop(){ pidofproc $exec > /dev/null [ $? != 0 ] && echo "$prog have been stopped" && exit killproc $exec [ $? = 0 ] && echo "stop $prog success" && rm -rf $lock } # add the restart method case $1 in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; *) echo "USAGE: nginx {start |stop |restart |reload }" ;; esac exit 0
#复制脚本到init.d目录
cp /home/shell/nginx.sh /etc/init.d/nginx
#查看当前系统启动数据
chkconfig --list systemctl list-unit-files
#设置非系统级别的开机自启动
chkconfig --add nginx
#添加启动失败原因
用命令chkconfig加载自启动.提示"**服务不支持chkconfig".开头一般要这样写 #!/bin/bash #chkconfig:345 61 61 //此行的345参数表示,在哪些运行级别启动,启动序号(S61);关闭序号(K61) #description:Apache //此行必写,描述服务. 把脚本拷贝至/etc/init.d/目录下,执行命令: #ln -s /etc/init.d/ #ln -s /etc/init.d/ #ln -s /etc/init.d/ 再执行 #chkconfig --levels httpd 345 on