Systemd Service Simple Webserver: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 1: Zeile 1:
 
=Python Script=
 
=Python Script=
 +
*usr/local/bin/webserver.py
 
<pre>
 
<pre>
 
#!/usr/bin/env python3
 
#!/usr/bin/env python3
Zeile 16: Zeile 17:
 
httpd.server_forever()
 
httpd.server_forever()
 
</pre>
 
</pre>
 +
 
=Service File=
 
=Service File=
 
cat /etc/systemd/system/webserver.service
 
cat /etc/systemd/system/webserver.service

Version vom 25. Oktober 2017, 13:35 Uhr

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('', 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