如何通过systemctl在Ubuntu 20.04上启动服务?
我有一个运行 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用以下方法下载单元文件并部署它:
I ended up using below method to download a unit file and deploy it: