如何通过systemctl在Ubuntu 20.04上启动服务?

发布于 2025-01-13 02:13:05 字数 873 浏览 4 评论 0原文

我有一个运行 ubuntu 20.04 的实例。我已通过在线 GUI“连接”工具登录到控制台。在 ubuntu 实例上,我添加了一个包含以下内容的服务文件:

linux_setup

[Unit]
Description=my app
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=ubuntu
ExecStart=python3 app.py file:///$PWD/LOG --port 8080

[Install]
WantedBy=multi-user.target

我现在想在我的实例中启动它。为此,我执行以下步骤:

ubuntu@ip-172-31-1-50:~$ ls
app-folder
ubuntu@ip-172-31-1-50:~$ cd app-folder
ubuntu@ip-172-31-1-50:~/app-folder$ ls
LICENSE  LOG  README.md  datasource  app.py  linux_setup.service  requirements.txt  test
ubuntu@ip-172-31-1-50:~/app-folder$ sudo systemctl start linux_setup
Failed to start linux_setup.service: Unit linux_setup.service not found.
ubuntu@ip-172-31-1-50:~/app-folder$ 

显然,似乎没有找到 linux_setup.service - 但它应该在那里。如何正确启动这个安装文件?

I have an instance running ubuntu 20.04. I've logged into the console via the online GUI 'connect' tool. On the ubuntu instance I've added a service file with below contents:

linux_setup:

[Unit]
Description=my app
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=ubuntu
ExecStart=python3 app.py file:///$PWD/LOG --port 8080

[Install]
WantedBy=multi-user.target

I now want to start this within my instance. To do so I perform the below steps:

ubuntu@ip-172-31-1-50:~$ ls
app-folder
ubuntu@ip-172-31-1-50:~$ cd app-folder
ubuntu@ip-172-31-1-50:~/app-folder$ ls
LICENSE  LOG  README.md  datasource  app.py  linux_setup.service  requirements.txt  test
ubuntu@ip-172-31-1-50:~/app-folder$ sudo systemctl start linux_setup
Failed to start linux_setup.service: Unit linux_setup.service not found.
ubuntu@ip-172-31-1-50:~/app-folder$ 

As evident, it seems like the linux_setup.service is not found - yet it should be there. How do I correctly start up this setup file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

<逆流佳人身旁 2025-01-20 02:13:05

我最终使用以下方法下载单元文件并部署它:

sudo wget [your_file_url]
sudo cp service_name.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start service_name
sudo systemctl enable service_name
sudo journalctl -f -u service_name

I ended up using below method to download a unit file and deploy it:

sudo wget [your_file_url]
sudo cp service_name.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start service_name
sudo systemctl enable service_name
sudo journalctl -f -u service_name
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文