目录
一.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