使用systemd增加linux 开机启动项

系统版本为 Ubuntu 20.04.3 LTS

创建service文件

在/etc/systemd/system 下创建一个 frp-core.service 文件

内容为:

[Unit]
#当前服务的简单描述
Description=Frp Core

[Service]
# 要执行的bash文件
ExecStart=/home/ubuntu/frp/frp_core/start.sh

# 后台执行
Type=oneshot
# 设为yes,表示进程退出以后,服务仍然保持执行
RemainAfterExit=yes


[Install]
WantedBy=multi-user.target

/home/ubuntu/frp/frp_core/start.sh:

#!/bin/sh  
# 一定要有上边那行 否则启动服务会报 203
 
echo '开机自启动' 

重新加载服务

添加或修改配置文件后,需要重新加载

# 添加或修改配置文件后,需要重新加载
systemctl daemon-reload
 
# 开机启动
systemctl enable frp-core
 
# 关闭开机启动
systemctl disable frp-core
 
# 启动服务
systemctl start frp-core
 
# 停止服务
systemctl stop frp-core
 
# 重启服务
systemctl restart frp-core
 
# 查看服务状态
systemctl status frp-core
 
# 结束服务进程(服务无法停止时)
systemctl kill frp-core
# taishi enterprise supervisord service for systemd (CentOS 7.0+)
[Unit]
Description=taishi Enterprise Supervisor daemon
After=taishi.service

[Service]
Type=forking
LimitNOFILE=655350
LimitNPROC=655350
ExecStart=/bin/bash /app/taishi/etc/start_taishi.sh
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=no
TimeoutSec=1200s

[Install]
WantedBy=multi-user.target
[Unit]
#当前服务的简单描述
Description=Frp Core

[Service]
# 要执行的bash文件
ExecStart=/bin/bash  /app/taishi/app/main/static/script/IP_update.sh

# 后台执行
Type=oneshot
# 设为yes,表示进程退出以后,服务仍然保持执行
RemainAfterExit=yes


[Install]
WantedBy=multi-user.target

  

 

posted @ 2022-11-15 15:47  舒然  阅读(133)  评论(0)    收藏  举报