老E的博客

  • 首页
  • 关于
  • 技术应用
    • VPS相关
    • AI相关
    • 盒子相关
    • 其他
  • 订阅Youtube频道
  • 网络加速
    • expressvpnNo.1 ExpressVPN
    • 最佳免费VPN-PrivadoVPN
    • NordVPN
    • 廉价王者-Surfshark
    • PrivateInternetAccess
    • 解锁一切-PrivateVPN
  • 公益资源
    • AI导航
    • 工具下载
    • Docker镜像加速
  • 友情链接
    • tickcloudTickcloud
老E的博客
专注记录并分享跨境技术应用及随想
  1. 首页
  2. 技术应用
  3. VPS相关
  4. 正文

基于systemd实现服务开机自启动的方法

2023年8月1日 1055次阅读 0条评论
clawcloud
expressvpn best vpn
privado vpn
surfshark vpn
private vpn
pia vpn
nord vpn

Debian/ubuntu系统中,开机自启有很多种实现方法,比如Startup Application、init.d开机脚本等,而systemd是目前Linux系统上主要的系统守护进程管理工具,由于init一方面对于进程的管理是串行化的,容易出现阻塞情况,另一方面init也仅仅是执行启动脚本,并不能对服务本身进行更多的管理。因此,我们一般都使用systemd对服务进行管理。有关systemd另行介绍,此处不做赘述,本文将gost配置为系统服务,从而实现开机自启。沿用前述文章中gost的启动参数,在/etc/systemd/system/目录下创建gost.service文件。

nano /etc/systemd/system/gost.service

gost.service文件内容如下:

[Unit]
Description=GOSTv3-Server of GO simple tunnel
Documentation=https://gost.run/
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/gost/gost -L relay+wss://username:password@:port_num
Restart=always
[Install]
WantedBy=multi-user.target

重新加载服务描述文件。

systemctl daemon-reload

设置gost开机自启动。此处的gost.service可省略为gost,下同。

systemctl enable gost.service    #gost.service可省略为gost,下同

启动gost服务。

systemctl start gost.service

可通过status选项查看服务状态。

systemctl status gost.service

使用systemctl管理gost服务的完整用例如下:

# 开机启动
systemctl enable gost.service
# 关闭开机启动
systemctl disable gost.service
# 启动服务
systemctl start gost.service
# 停止服务
systemctl stop gost.service
# 重启服务
systemctl restart gost.service
# 查看服务状态
systemctl status gost.service
systemctl is-active gost.service
# 结束服务进程(服务无法停止时)
systemctl kill gost.service

 

本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
标签: Linux系统运维 System O&M
最后更新:2024年5月28日

老E

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

站内搜索
归档
  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 8 月
  • 2024 年 7 月
  • 2024 年 6 月
  • 2024 年 5 月
  • 2024 年 4 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
  • 2023 年 11 月
  • 2023 年 10 月
  • 2023 年 9 月
  • 2023 年 8 月
  • 2023 年 7 月
  • 2023 年 6 月

Copyright ©2023-2025 Appscross. All Rights Reserved.