bbb lighttpd und python

Zum nachlesen

Kochbuch

$ sudo apt-get install lighttpd
  • diverse Änderungen in /etc/lighttpd/lig­httpd.conf
$ sudo nano /etc/lighttpd/lighttpd.conf
  • mod_cgi hinzufügen
server.modules = (
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
#       "mod_rewrite",
        "mod_cgi",
)
  • Python dem cgi-Modul zur Verfügung stellen
cgi.assign = ( ".py" => "/usr/bin/python" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".py" )
  • Das Verzeichnis /var/www/cgi-bin anlegen
$ sudo mkdir /var/www/cgi-bin
$ sudo /etc/init.d/lighttpd restart
  • In diesem Verzeichnis dieses Python Script ablegen (mit freundlicher Unterstützung von planzero.org
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#http://planzero.org/blog/2012/01/26/system_uptime_in_python,_a_better_way

from datetime import timedelta

print "Content-Type: text/html"
print
print "<title>Uptime des Beaglebone Black</title>"
print "<h1>Uptime des Beaglebone Black</h1>"

with open('/proc/uptime', 'r') as f:
    uptime_seconds = float(f.readline().split()[0])
    uptime_string = str(timedelta(seconds = uptime_seconds))

print(uptime_string)

Testaufruf mit http://bone.nfix.de/…wnfuptime.py