Last active
September 24, 2024 12:51
-
-
Save raresteak/68492b6ffbc2d20c3adbcc5990d32532 to your computer and use it in GitHub Desktop.
Example systemd service file
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
# myservice.service | |
[Unit] | |
Description=Python HTTP server /tmp port 4848 | |
Documentation=man systemd.service | |
After=network.target #myservice.service requires networking be up first | |
[Service] | |
User=sam | |
ExecStartPre=sh -c 'echo TRUE > /tmp/TRUE'#not required, just an example | |
ExecStart=/usr/bin/python3 -m http.server -d /tmp 4848 | |
ExecStartPost=touch /tmp/index.html # prevent directory listing, not required, just an example | |
ExecStop=sh -c '/usr/bin/pkill -f "python3 -m http.server -d /tmp 4848"' #not required, just an example. systemd records the pid at start time and will kill it during stop. | |
Restart=always # what to do if the process dies | |
[Install] | |
WantedBy=multi-user.target # will start when system is in runlevel 2,3,4,5 | |
# more options list in man page | |
# man systemd.service | |
# Save myservice.service in /usr/lib/systemd/system/ | |
# systemctl daemon-reload | |
# systemctl start python3http4848 | |
# systemctl status -l python3http4848 | |
# systemctl stop python3http4848 | |
# systemctl enable python3http4848 | |
# systemctl disable python3http4848 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
minimum required template for a service that needs networking and system in mult-user mode.