2

Hi everyone the situation is the following:
I am connetected to an ubuntu-based EC2 machine of AWS ( and I am currently working on Ubuntu 18.04). I can manage files inside the machine and run scripts from terminal but I want the machine to run a script even when I am not connected. So I thought about a service.

Using systemd I located this file on /lib/systemd/system :

[Unit] Description=Test Service After=network.target
[email protected]

[Service] Type=simple ExecStart=/usr/bin/python3 /home/ubuntu/GreenHouse/Catalog/Catalog_REST.py
StandardInput=tty-force

[Install] WantedBy=multi-user.target

I started the service,ut when I check the status:

 sudo systemctl status CATALOG_REST-py.service

I receive this error:

● CATALOG_REST-py.service - Test Service Loaded: loaded (/lib/systemd/system/CATALOG_REST-py.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2021-08-22 16:54:13 UTC; 1s ago Process: 23968 ExecStart=/usr/bin/python3 /home/GreenHouse/Catalog/Catalog_REST.py (code=exited, status=1/FAILURE) Main PID: 23968 (code=exited, status=1/FAILURE)

Aug 22 16:54:13 ip-172-31-13-245 systemd[1]: Started Test Service. Aug 22 16:54:13 ip-172-31-13-245 systemd[1]: CATALOG_REST-py.service: Main process exited, code=exited, status=1/FAIL Aug 22 16:54:13 ip-172-31-13-245 systemd[1]: CATALOG_REST-py.service: Failed with result 'exit-code'.

I want to say that if I run in terminal python3 /home/GreenHouse/Catalog/Catalog_REST.py , it works.

Do you know some ways to obtain a better explanation of the error?

1 Answer 1

1

As better described in here, the issue may be related to the runtime environment.

In that case, a possible quick solution in my experience is to replace your service with the following one (it only differs for the ExecStart line):

[Unit] 
Description=Test Service After=network.target
[email protected]

[Service] 
Type=simple 
ExecStart=/bin/sh -c "/usr/bin/python3 /home/ubuntu/GreenHouse/Catalog/Catalog_REST.py"
StandardInput=tty-force

[Install] 
WantedBy=multi-user.target

Then reload the systemd manager configuration and restart your service:

sudo systemctl daemon-reload
sudo systemctl restart CATALOG_REST-py.service
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for you interest. At the end, I changed the strategy: I decided to use tmux sessions in order to run different codes simultaneously, even when I wasn't connected. It worked at the end, even if it was quite computationally heavy. In fact, the EC2 used to crash when many tmux sessions were on. However, I don't know if it actually depends on tmux and if the results would have been the same with a different approach. Anyway, I finished the university project and tmux was a useful and quick solution!
That did not work for me. After reboot, process is still killed. When starting the process manually with "systemctl start" after boot, all fine. Strange.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.