Systemd

参考链接
Systemd 入门教程:命令篇

在以下地址新建自定义service

#推荐地址
/usr/lib/systemd/system/

#系统执行过程中所产生的服务脚本,这些脚本的优先级比上面的高
/run/systemd/system/

#管理员根据主机系统的需求所建立的执行脚本,优先级比上面的高
/etc/systemd/system/
# 创建service
$ touch /usr/lib/systemd/system/YOUR_SERVICE_NAME.service

# 编辑service,填写以下内容
[Unit]
After=network.service

[Service]
ExecStart=YOUR_SHELL_FILE_PATH/YOUR_SHELL_FILE.sh

[Install]
WantedBy=default.target

# 让service生效
$ systemctl daemon-reload

# 启动service
$ sudo systemctl start YOUR_SERVICE_NAME.service

# 重新启动service
$ sudo systemctl restart YOUR_SERVICE_NAME.service

# 停止service
$ sudo systemctl stop YOUR_SERVICE_NAME.service

# 设置service为开机启动项
$ sudo systemctl enable YOUR_SERVICE_NAME.service

# 取消设置service为开机启动项
$ sudo systemctl disable YOUR_SERVICE_NAME.service

# 启动并设置service为开机启动项
$ sudo systemctl enable --now YOUR_SERVICE_NAME.service

# 查看service运行状态
$ systemctl status YOUR_SERVICE_NAME.service

你可能感兴趣的:(Systemd)