Instantly share code, notes, and snippets.

Embed
What would you like to do?
A systemd file for a python SimpleHTTPServer
[Unit]
Description=Job that runs the python SimpleHTTPServer daemon
Documentation=man:SimpleHTTPServer(1)
[Service]
Type=simple
WorkingDirectory=/tmp/letsencrypt
ExecStart=/usr/bin/python -m SimpleHTTPServer 80 &
ExecStop=/bin/kill `/bin/ps aux | /bin/grep SimpleHTTPServer | /bin/grep -v grep | /usr/bin/awk '{ print $2 }'`
[Install]
WantedBy=multi-user.target
@chmouel

This comment has been minimized.

chmouel commented Oct 28, 2016

👍

@007lva

This comment has been minimized.

007lva commented Jan 28, 2017

Thanks!

@sarnobat

This comment has been minimized.

sarnobat commented Dec 29, 2017

In case anyone is still not clear, here is exactly what I did:

1) Create the unit file

sudo vi /etc/systemd/system/simplehttp.service
[Unit]
Description=My Miscellaneous Service
After=network.target

[Service]
Type=simple
User=sarnobat
WorkingDirectory=/home/sarnobat
ExecStart=/usr/bin/python -m SimpleHTTPServer 5000
Restart=on-abort

[Install]
WantedBy=multi-user.target

2) Detect your new service (twice you have to enter your password, and passwordless doesn't work...yuck)

systemctl daemon-reload
systemctl restart simplehttp.service

3) Find out why it didn't start

journalctl -u simplehttp.service

4) Turns out I didn't use an absolute path to my binary

sudo vi /etc/systemd/system/simplehttp.service

5) Try again

systemctl restart simplehttp.service

6) works

lsof -i:5000

Credits:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment