Linux的systemd系统添加服务是在/usr/lib/systemd/system(kylin环境systemd路径可能变成了/lib/systemd/system)。无论路径如何变化,添加服务大同小异,只是配置的路径需要注意。添加自定义服务,简单配置可以如下:
# 创建myService.service文件
touch /usr/lib/systemd/system/myService.service
chmod 666 /usr/lib/systemd/system/myService.service
# 写服务配置
echo "[Unit]
Description=myService service
After=sysinit.target nfs-server.service
[Service]
ExecStart=/opt/myService/myservice start #我的服务放在/opt/myService
Type=simple
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/myService.service
# 创建软连接
ln -s /usr/lib/systemd/system/myService.service /usr/lib/systemd/system/local-fs.target.wants/myService.service
# 将服务加入开机启动
systemctl enable myService > /dev/null 2>&1
systemctl daemon-reload > /dev/null 2>&1
网友评论