Index: src/daemon/gnuboat
===================================================================
--- src/daemon/gnuboat	(revision 7549de9ec8140161842e3d3cf75dd3471a0852b8)
+++ src/daemon/gnuboat	(revision c53f31a6bc677465032fb7237420e709c7980a70)
@@ -26,4 +26,6 @@
 import os
 import dateutil
+import getopt
+import sys
 from EPD import EPD
 from PIL import Image
@@ -35,8 +37,10 @@
 marginVertical = 10
 marginHorizontal = marginVertical
-rrdFile = "/home/joachim/public_html/gnuboat/webservice/data/log-webservice.rrd"
-shutdownFile = "/var/spool/gnuboat/shutdown.request"
-logPeriod = 1
-displayPeriod = 5
+
+# default values for command line arguments
+rrdfile = "/var/www/gnuboat/webservice/data/log-webservice.rrd"
+shutdownfile = "/var/spool/gnuboat/shutdown.request"
+logperiod = 1
+displayperiod = 5
 
 shutdownRequested = None
@@ -66,8 +70,9 @@
    
   def run(self):
+    global logperiod
     try:
       while self._running:
         self._currentValue = self._session.next()
-        time.sleep(float(logPeriod)/2.0)
+        time.sleep(float(logperiod)/2.0)
     except StopIteration:
       pass
@@ -89,5 +94,5 @@
 
   if not os.path.isfile(databaseFile):
-    rrdtool.create(rrdFile,
+    rrdtool.create(databaseFile,
                    "--start",
                    "N",
@@ -143,6 +148,6 @@
   epd.update()
 
-def checkShutdownRequest():
-  global shutdownRequest
+def checkShutdownRequest(shutdownFile):
+  global shutdownRequested
   # have look for new shutdown requests
   if os.path.isfile(shutdownFile):
@@ -156,6 +161,66 @@
       os.system("sudo shutdown -r now")
 
-if __name__ == '__main__':
-  createDatabase(rrdFile)
+def usage():
+  print "Usage of gnuboat daemon:"
+  print "  gnuboat -r PATH_TO_RRD_DATABAE_FILE -s PATH_TO_SHUTDOWN_REQUEST_FILE [-l [LOG_UPDATE_PERIOD] [-d DISPLAY_UPDATE_PERIOD]"
+  print ""
+  print "  -h --help              Display this help"
+  print "  -r --rrdfile           Path to the rrd database used by the webservice to serve the clients"
+  print "  -s --shutdownfile      Path to the shutdown request file, used by the webservice to request a shutdown of the system running gnuboat"
+  print "  -l --logperiod         Time in seconds to update the logs"
+  print "  -d --displayperiod     Timein seconds to update the display"
+
+def main(argv):
+  global rrdfile
+  global shutdownfile
+  global logperiod
+  global displayperiod
+
+  try:                                
+    opts, args = getopt.getopt(argv, "hr:s:l:d:", ["help", "rrdfile=", "shutdownfile=", "logperiod=", "displayperiod="]) 
+  except getopt.GetoptError:           
+    usage()                          
+    sys.exit(2)
+
+  for option, argument in opts:
+    if option == ("-h", "--help"):
+      usage()
+      sys.exit()
+    elif option in ("-r", "--rrdfile"):
+       rrdfile = argument
+    elif option in ("-s", "--shutdownfile"):
+      shutdownfile = argument
+    elif option in ("-l", "--logperiod"):
+      logperiod = argument
+    elif option in ("-d", "--displayperiod"):
+      displayperiod = argument
+    else:
+      assert False, "unhandled option"
+
+  if not os.path.exists(os.path.dirname(rrdfile)):
+    print "rrd database directory not found %s" % os.path.dirname(rrdfile)
+    print ""
+    usage()
+    sys.exit(2)
+
+  if not os.path.exists(os.path.dirname(shutdownfile)):
+    print "Shutdown request directory not found %s" % os.path.dirname(shutdownfile)
+    print ""
+    usage()
+    sys.exit(2)
+
+  if logperiod < 1:
+    print "Log period must be >= 1"
+    print ""
+    usage()
+    sys.exit(2)
+
+  if displayperiod < 1 or displayperiod < logperiod:
+    print "Display period must be >= 1 and could not be faster than log period"
+    print ""
+    usage()
+    sys.exit(2)
+
+  createDatabase(rrdfile)
 
   epd = EPD()
@@ -168,5 +233,5 @@
     while True:
       # In the main thread, every logPeriod seconds print the current value
-      time.sleep(logPeriod)
+      time.sleep(logperiod)
       latitude = gpsp.latitude()
       longitude = gpsp.longitude()
@@ -178,12 +243,15 @@
       
       # update rrd database for the webservice
-      rrdtool.update(rrdFile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix))
+      rrdtool.update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix))
       # update display, if needed
-      if time.time() % displayPeriod == 0:
+      if round(time.time(),0) % displayperiod == 0:
         displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)
       #check for shutdown request
-      checkShutdownRequest()
+      checkShutdownRequest(shutdownfile)
        
   except (KeyboardInterrupt, SystemExit): #when you press ctrl+c
     gpsp.stop()
     gpsp.join() # wait for the thread to finish what it's doing
+
+if __name__ == "__main__":
+  main(sys.argv[1:])
