嗖一下,答案就来了!

导航:奇妙博客/代码程序/ Linux通过Systemd让程序开机启动并后台运行的一种方法记录

Linux通过Systemd让程序开机启动并后台运行的一种方法记录

Linux通过Systemd让程序开机启动并后台运行的一种方法记录-奇妙博客
最近在折腾这种GO语言开发的程序,单一文件,下载下来直接运行就能使用,真心简洁强大。
但同时遇到一个问题,就是不能后台运行,不能开机启动。
所以这里收藏了一下cloudreve官方的进程守护教程,备查。

一、编辑配置文件

vim /usr/lib/systemd/system/cloudreve.service
这里的 cloudreve.service 可以自定义

二、粘贴如下内容,将 PATH_TO_CLOUDREVE 更换为程序所在目录

[Unit]
Description=Cloudreve
After=network.target
After=mysqld.service
Wants=network.target

[Service]
WorkingDirectory=/PATH_TO_CLOUDREVE
ExecStart=/PATH_TO_CLOUDREVE/cloudreve
Restart=on-abnormal
RestartSec=5s
KillMode=mixed

StandardOutput=null
StandardError=syslog

[Install]
WantedBy=multi-user.target

这里的Description、WorkingDirectory、ExecStart都需要自定义

三、通过systemctl命令启动程序后台运行,并设置开机启动

systemctl daemon-reload # 更新配置
systemctl start cloudreve # 启动服务
systemctl enable cloudreve # 设置开机启动
systemctl disenable cloudreve # 禁用开机启动

四、systemctl命令常用功能

systemctl start cloudreve # 启动服务
systemctl stop cloudreve # 停止服务
systemctl restart cloudreve # 重启服务
systemctl status cloudreve # 查看状态

 

0 收藏 分享

Linux通过Systemd让程序开机启动并后台运行的一种方法记录

https://v2ez.com

点击图片即可下载

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。

评论 | 0 条评论

登录之后才可留言,前往登录

CopyRight © 2024     奇妙博客.All Rights Reserved.             QUI-Pure主题 · Theme By:QUX&七娃博客    网站响应速度0.109