Search code examples
ubuntusystemctl

How to start a service on Ubuntu 20.04 via systemctl?


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?


Solution

  • 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