Created
November 16, 2015 23:00
-
-
Save danechitoaie/f2bb03fd0c2d6b803878 to your computer and use it in GitHub Desktop.
Virtualenv Systemd Service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Python Virtualenv service example | |
After=network.target | |
[Service] | |
User=my_user | |
Group=my_group | |
Environment=VIRTUAL_ENV=/home/my_user/.virtualenvs/my_venv | |
Environment=PATH=$VIRTUAL_ENV/bin:$PATH | |
ExecStart=$VIRTUAL_ENV/bin/my_entrypoint | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target |
@jcaesar you are right: I'm getting the following error (when trying to start the unit):
systemd[1]: Executable path is not absolute, ignoring: $VIRTUAL_ENV/bin/my_entrypoint
systemd[1]: Service lacks both ExecStart= and ExecStop= setting. Refusing.
So a fix would be:
- ExecStart=$VIRTUAL_ENV/bin/my_entrypoint
+ ExecStart=/home/my_user/.virtualenvs/my_venv/bin/my_entrypoint
See also: https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart=
Systemd does not expand environment variables.
You end up with literal $VIRTUAL_ENV
and $PATH
inside the PATH variable
and in path to the executable.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just stumbled onto this… I wonder, this can't work, right? ExecStart paths have to be absolute, after all…