https://www.cnblogs.com/jhxxb/p/10654554.html
https://www.jb51.net/article/100457.htm
https://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
示例1:
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
示例2:
1、编辑systemd
并加载:
vim /usr/lib/systemd/system/mine.service
systemctl daemon-reload
2、设置开机启动:
systemctl enable mine
3、取消开机启动:
systemctl disable mine
4、测试:
systemctl start mine.service
mine.service :
[Unit]
Description=描述
Environment=环境变量或参数(系统环境变量此时无法使用)
After=network.target
[Service]
Type=forking
EnvironmentFile=所需环境变量文件或参数文件
ExecStart=启动命令(需指定全路径)
ExecStop=停止命令(需指定全路径)
User=以什么用户执行命令
[Install]
WantedBy=multi-user.target
这里有个nacos自动启动的例子:
[Unit]
Description=nacos-cluster
After=network.target
[Service]
Type=forking
ExecStart=/bin/bash /usr/local/nacos/deploy/start_nacos.sh
ExecStop=/bin/bash /usr/local/nacos/deploy/stop_nacos.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target