I have a basic upstart script in /etc/init that is used to run a python script upon system startup/reboot.
description "simple python script"
start on runlevel [2345]
stop on runlevel [06]
respawn
env MY_ENVIRONMENT_VAR='/path/to/file.config'
chdir /path/to/script/
exec python script.py
How would I achieve the same thing using the systemd service management system in Ubuntu 16.04?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Figured it out - here’s the equivalent systemd script:
This file was in my app directory, so I created a dynamic link to it in the systemd directory:
by doing:
If you get a “Too many levels of symbolic links” error: See @nabito answer below, just copy the file into the
/etc/systemd/system/
folder with acp
instead of creating a symbolic link.Then I can start it with:
Thanks, for this conversation i have same problem and i have resolved it but i also want to have a log file for that python script so is there any way to add log file??
Thanks for the tip, however I followed your steps and got an error due to symlink the .service when trying to ‘systemctl enable my_systemd_script.service’
This is in Ubuntu 16.04.1 LTS upgraded from 14.04. The solution I took is to put the actual .service in /etc/systemd/system. Seems systemctl will try to create another symlink for it, as seen in the success output from ‘systemctl enable’ command.