unbuntu的systemd使用

一.systemd介绍

参考:systemd如何启动服务 systemd service

二.启动一个进程的步骤

1.创建服务单元文件

打开文本编辑器,创建一个新的文件,例如myapp.service,并填入以下内容:

[Unit]
Description=My Application
[Service]
EnvironmentFile=/path/to/your/myapp.env
ExecStart=/path/to/your/application.exe
Restart=always
[Install]
WantedBy=multi-user.target

把/path/to/your/application.exe替换为你的exe文件的实际路径。

2.保存文件

保存到/etc/systemd/system/目录或者用户的~/.config/systemd/user/目录中(取决于你想要的启动级别)。

3.重新加载systemd管理器配置

sudo systemctl daemon-reload

4.启动服务

sudo systemctl start myapp.service

5.查看服务状态

sudo systemctl status myapp.service

6.设置服务开机自启

sudo systemctl enable myapp.service

7.关闭服务

sudo systemctl stop myapp.service

8.启动的详细日志查看

journalctl -u myapp-service

三.常见问题

1./etc/systemd/system/下无法启动图形界面程序

解决方法有如下两种

1.1配置EnvironmentFile或者Environment

EnvironmentFile

EnvironmentFile=/mypath/my.env

Environment

Environment=“DISPLAY=:0”

1.2把service文件放到~/.config/systemd/user/中,以用户级别启动

systemctrl start --user my.service

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值