Systemd Service Simple Webserver: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 14: Zeile 14:
 
     return [text.encode('utf-8')]
 
     return [text.encode('utf-8')]
  
httpd = make_server('', 8000, hello_world_app)
+
httpd = make_server('0.0.0.0', 8000, hello_world_app)
 
httpd.server_forever()
 
httpd.server_forever()
 
</pre>
 
</pre>

Version vom 25. Oktober 2017, 13:36 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('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