linux systemctl设置服务并开机启动

作者: cayman 分类: 服务器技术 发布时间: 2018-06-29 00:00

以frp为例子

先创建


# vi /etc/systemd/system/myapp.service 
----------------------------------------------------
#如果/etc/systemd/system/myapp.service有过修改,需要进行更新,执行下面这个命令
#systemctl daemon-reload
#查看服务是否被正确识别
#systemctl list-unit-files|grep myapp
[Unit]
#服务描述,写有意义的内容,便于识别
Description=myapp

[Service]
Type=simple
#设置应用的工作目录
WorkingDirectory=/myapp_path
ExecStart=/myapp_path/startMyApp.sh
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

查看系统服务文件是否被识别

systemctl list-unit-files|grep myapp

启动系统服务

systemctl start myapp.service

设置开机启动

sudo systemctl enable myapp.service

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注