Last active
March 10, 2020 16:35
-
-
Save girol/fa671681897a194e64b86e8302b01506 to your computer and use it in GitHub Desktop.
Python script SystemD example
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
from time import sleep | |
import os | |
hi = os.environ.get('HELLO') | |
seconds = 1 | |
while(True): | |
sleep(1) | |
print("logging...", seconds, "Env Var: ", hi) | |
seconds +=1 |
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
HELLO='Chambering The Chamber' |
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=SystemD Test Service! | |
After=network.target | |
[Service] | |
User=chambers | |
Group=chambers | |
EnvironmentFile=/etc/default/superlogger | |
WorkingDirectory=/home/my_user/my_project/systemd-templates | |
ExecStart=/usr/bin/python3 -u app.py | |
Restart=on-failure | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Notes
-u
parameter starts Python inunbuffered mode
, chaining theprint()
output tojournalctl
WorkingDirectory
is where the scriptapp.py
is locatedsuperlogger
environment file inside/etc/default