Systemd Service Simple Webserver
Python Script
- usr/local/bin/webserver.py
#!/usr/bin/env python3
from wsgiref.simple_server import make_server
from datetime import datetime
def hello_world_app(environ, start_response):
status = '200 OK'
headers = [('Content-type', 'text/plain; charset=utf-8')]
start_response(status, headers)
text = 'Hello World @ {}'.format(datetime.now())
return [text.encode('utf-8')]
httpd = make_server('0.0.0.0', 8000, hello_world_app)
httpd.server_forever()
Service File
cat /etc/systemd/system/webserver.service
[Unit] Description=Simple WSGI Server [Service] Type=simple ExecStart=/usr/local/bin/webserver.py ExecStartPost=/bin/echo "Server gestartet" User=www-data [Install] WantedBy=multi-user.target