Skip to content

Commit fc496f7

Browse files
committed
Add Python script and unit file
1 parent 861e5dd commit fc496f7

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Diff for: python_demo_service.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Python script for the Python Demo Service
2+
3+
if __name__ == '__main__':
4+
import time
5+
import systemd.daemon
6+
7+
print('Starting up ...')
8+
time.sleep(10)
9+
print('Startup complete')
10+
# Tell systemd that our service is ready
11+
systemd.daemon.notify('READY=1')
12+
13+
while True:
14+
print('Hello from the Python Demo Service')
15+
time.sleep(5)
16+

Diff for: python_demo_service.service

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# systemd unit file for the Python Demo Service
2+
3+
4+
[Unit]
5+
6+
# Human readable name of the unit
7+
Description=Python Demo Service
8+
9+
10+
[Service]
11+
12+
# Command to execute when the service is started
13+
ExecStart=/usr/bin/python /usr/local/lib/python_demo_service/python_demo_service.py
14+
15+
# Disable Python's buffering of STDOUT and STDERR, so that output from the
16+
# service shows up immediately in systemd's logs
17+
Environment=PYTHONUNBUFFERED=1
18+
19+
# Automatically restart the service if it crashes
20+
Restart=on-failure
21+
22+
# Our service will notify systemd once it is up and running
23+
Type=notify
24+
25+
# Use a dedicated user to run our service
26+
User=python_demo_service
27+
28+
29+
[Install]
30+
31+
# Tell systemd to automatically start this service when the system boots
32+
# (assuming the service is enabled)
33+
WantedBy=default.target
34+

0 commit comments

Comments
 (0)