<-

ubuntu 如何将任何app run为服务

 

这里有些服务要用:

1. app 的安装位置

2. app要添加到环境变量path里面

3. app 要添加服务,需要在systemd/system/下面添加app的service

sudo nano /etc/systemd/system/myapp.service

[Unit]
Description=My Application Service
After=network.target

[Service]
Type=simple
User=username  # 替换为运行应用的用户
ExecStart=/path/to/your/application  # 例如 /usr/bin/python3 /path/to/myapp.py
Restart=on-failure
Environment="PYTHONPATH=/path/to/your/python/modules"  # 如果需要设置环境变量

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload

sudo systemctl start myapp.service

sudo systemctl enable myapp.service

sudo systemctl status myapp.service

journalctl -u myapp.service

 

posted @ 2026-04-06 09:00  calochCN  阅读(5)  评论(0)    收藏  举报