#!/usr/bin/env

'''Watchdog script to keep a krad_radio instance running'''

import subprocess
import time

class Daemon:
  def __init__(self):
    self.cmd = 'krad_radio_daemon'
    self.station = 'test'
    self.running = False

  def log(self, msg):
    timestamp = time.strftime('%Y-%M-%d %H:%M:%S', time.gmtime())
    print '--- %s - %s ---\n' % (timestamp, msg)

  def run(self, cmd=None):
    if not cmd:
      cmd = self.cmd
    self.running = True
    while self.running:
      self.log('running %s' % cmd)
      ret = subprocess.call([cmd, self.station])
      self.log('finished return ' + str(ret))

if __name__ == '__main__':
  job = Daemon();
  job.run()

@@ -198,16 +198,71 @@
  'test'%0A
+    self.config = %5B'krad_radio', self.station, 'info'%5D%0A
     self
@@ -545,20 +545,22 @@
 lf.log('
-runn
+launch
 ing %25s' 
@@ -572,19 +572,20 @@
 )%0A      
-ret
+proc
  = subpr
@@ -594,12 +594,13 @@
 ess.
-call
+Popen
 (%5Bcm
@@ -627,34 +627,223 @@
     
-self.log('finished
+time.sleep(0.5)%0A      self.log('configuring')%0A      ret = subprocess.call(self.config)%0A      self.log('configuration exited with return code ' + str(ret))%0A      ret = proc.wait();%0A      self.log('exited with
  return 
 ' + 
@@ -838,16 +838,21 @@
  return 
+code 
 ' + str(
@@ -903,16 +903,72 @@
 emon();%0A
+  #job.station = 'test2'%0A  #job.config = './capture.sh'%0A
   job.ru

Add a config/setup script to the watchdog script.