模板 :template.service
[Unit]
Description="服务描述"
After=network.target
[Service]
Type=forking
Restart=no
KillMode=control-group
ExecStart="启动命令"
ExecStop="停止命令"
ExecReload="重载命令"
[Install]
WantedBy=multi-user.target
注意:
服务安装成功后,如果想要自启动: 需要配置 :chkconfig {serverName} on
centOS 环境
步骤
- 根据模板文件创建一个服务文件,特别注意启动命令中如果是文件,需要注意文件中使用的相对路径.
- 将服务文件 copy to :
/usr/lib/systemd/system
- 使用
systemctl daemon-reload
重启载入一遍服务 - 执行
systemctl start {serverName}
尝试启动下服务 - 执行
systemctl status {serverName}
查看服务状态 - 如果服务状态如下所示: 需要执行,
systemctl enable {serverName}
hatom-py.service - hatom-server
Loaded: loaded (/usr/lib/systemd/system/***.service; disabled; vendor preset: disabled)
Active: inactive (dead)
网友评论