Centos7.x的版本的服务都是以
systemctl start xxxx
来启动的,如何制作自己的开机启动脚本?可参考/usr/lib/systemd/system
目录中的其它服务来修改即可
使用说明
可参考nginx.service
cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
说明
[Unit]
Description=描述信息
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking#运行方式
PIDFile=PID进程文件
ExecStartPre=开启准备
ExecStart=开启脚本
ExecReload=重启脚本
KillSignal=停止信号量
TimeoutStopSec=停止超时时间
KillMode=杀掉模式
PrivateTmp=独立空间
[Install]
WantedBy=multi-user.target#脚本启动模式,多用户多网络
例子demo
cat /root/user-start.sh
#!/bin/bash
echo "123" > /root/hello.txt
vim /usr/lib/systemd/system/user-start.service
[Unit]
Description=这是开机启动脚本
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/user-start.pid
ExecStart=/root/user-start.sh
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target
设置脚本开始启动
systemctl enable user-start
禁止开启启动
systemctl disable user-start
常规命令
systemctl start
systemctl reload
systemctl stop
网友评论