def start_watchdog():
    # check here for watchdog exist 
    watchdog_pid = get_watchdog_pid()

    if not watchdog_pid:
        # setsid <prog> & daemonizes...
        cmd = 'setsid %s/safplus_watchdog.py &' % asp.get_asp_etc_dir()
        os.system(cmd)
    else:
        asp.fail_and_exit('SAFplus is already running on node [%s], pid [%s]' % (asp.get_asp_node_addr(), watchdog_pid), False)
def get_watchdog_pid():
    p = '%s/safplus_watchdog.py' % asp.get_asp_etc_dir()
    cmd = asp.sys_asp['get_amf_watchdog_pid_cmd'](p)
    result = asp.sys_asp['Popen'](cmd)

    # Eliminate the incorrect lines
    psLine = filter(lambda x: not "grep" in x, result)

    if len(psLine) == 0: # Its already dead
      return 0
    try:
      wpid = int(psLine[0].split()[0])
    except Exception, e:
      print "Exception: %s" % str(e)
      print "CMD: %s" % cmd
      print "data: %s" % result
      raise
def start_ams():
    #cmd = 'setsid %s/asp.py &' % asp.get_asp_etc_dir()
    cmd = '%s/asp.py &' % asp.get_asp_etc_dir()
    os.system(cmd)