Systemd Service Simple Webserver: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Thomas (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „=Python Script= <pre> #!/usr/bin/env python3 from wsgiref.simple_server import make_server from datetime import datetime def hello_world_app(environ, start_r…“) |
Thomas (Diskussion | Beiträge) |
||
| Zeile 15: | Zeile 15: | ||
httpd = make_server('', 8000, hello_world_app) | httpd = make_server('', 8000, hello_world_app) | ||
httpd.server_forever() | httpd.server_forever() | ||
| + | </pre> | ||
| + | =Service File= | ||
| + | cat /etc/systemd/system/webserver.service | ||
| + | <pre> | ||
| + | [Unit] | ||
| + | Description=Simple WSGI Server | ||
| + | |||
| + | [Service] | ||
| + | Type=simple | ||
| + | ExecStart=/home/BENUTZER/code/simple_wsgi_server.py | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
</pre> | </pre> | ||
Version vom 25. Oktober 2017, 13:28 Uhr
Python Script
#!/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=/home/BENUTZER/code/simple_wsgi_server.py [Install] WantedBy=multi-user.target