0

I have a Ubuntu 16.04 machine. I have written a very simple systemd service.

The purpose of this is to create a service that will start once the booting process is done and run a python script. It should also restart the python script if the python script crashes.

This is how my systemd script looks like.

[Unit]
Description=My Python Script
Requires=multi-user.target
After=multi-user.target

[Service]
Type = forking
WorkingDirectory=/path/to/my/python/script/
ExecStart=/usr/bin/python /path/to/my/python/script/mypythonscript.py
Restart=always

[Install]
WantedBy=multi-user.target

This script has been written using this tutorial. I followed the steps there just changed names.

I now have a service that I can stat manually. If I do sudo service myservice start I am able to start my service. However, the service does not start when the machine boots. It needs to be started manually.

Do you know how I can fix that?

What is the correct way to have a service start after the machine boots, on a Ubuntu 16.04 OS?

Thanks!

mayk93
  • 115
  • 2
  • 5

1 Answers1

3

Did you enable the service?

systemctl enable myservice

should suffice.

You can check it running systemctl status myservice, it should tell you right there if the service is enabled or not.

natxo asenjo
  • 5,641
  • 2
  • 25
  • 27
  • Yes, I did that. And after reading that multi-user.target, or targets in general are run levels, I modified the script slightly. I now how `After=multi-user.target reboot.target` and removed the `[Install]` section. After running `systemctl enable myservice` again, I get `Failed to start reboot.target: Transaction order is cyclic. See system logs for details.` when I try to reboot. – mayk93 May 10 '17 at 11:58
  • what's in syslog? And after modifying the unit you should disable/enable the service or reload the systemctl (https://www.freedesktop.org/software/systemd/man/systemctl.html#daemon-reload) – natxo asenjo May 10 '17 at 12:16
  • I found the problem. It's not that it wasn't starting on boot. It was trying to start but it was failing more than 5 times in 10 seconds, which is the default. I changed the `StartLimitIntervalSec` and `StartLimitBurst` settings and now it starts as expected. However, I still have the `Transaction order is cyclic` problem that I'm trying to fix now. – mayk93 May 10 '17 at 12:39