Exemplo n.º 1
0
def ensure_stopped( config ):
   """
   Stop all syndicated instances for this mountpoint.
   """
   
   mountpoint_dir = config['mountpoint_dir']
   
   # is the daemon running?
   procs = watchdog.find_by_attrs( "syndicate-automount-daemon", {"mounts": mountpoint_dir} )
   
   if len(procs) > 0:
      
      failed = signal_all( procs, signal.SIGTERM )
      
      # wait for signals to be delivered
      time.sleep(1.0)
      
      procs = watchdog.find_by_attrs( "syndicate-automount-daemon", {"mounts": mountpoint_dir} )
      
      if len(procs) > 0 or len(failed) > 0:
         
         failed = signal_all( procs, signal.SIGKILL )
         if len(failed) > 0:
            log.error("Failed to stop automount daemons %s" % (",".join( [str(watchdog.get_proc_pid( p )) for p in procs] )))
            
            return False 
         
   return True
Exemplo n.º 2
0
def get_pids_of_daemons_for_dir( mountpoint_dir ):
   """
   Get the PIDs of all automount daemons running on a mountpoint.
   """
   procs = watchdog.find_by_attrs( "syndicate-automount-daemon", {"mounts": mountpoint_dir} )
   
   ret = [ watchdog.get_proc_pid(p) for p in procs ]
   
   return ret
Exemplo n.º 3
0
def signal_all( procs, signum ):
   """
   Send signum to all of a list of processes.
   Return the ones where we couldn't deliver the signal.
   """
   
   failed = []
   
   for proc in procs:
      pid = watchdog.get_proc_pid( proc )
      
      log.info("Send signal %s to %s" % (signum, pid))
      try:
         os.kill( pid, signum )
      except OSError, oe:
         log.exception(oe)
         log.error("Failed to send signal %s to %s, errno = %s" % (signum, pid, oe.errno))
         
         failed.append( proc )
Exemplo n.º 4
0
def ensure_running( config ):
   """
   Verify that there is an automount daemon servicing a mountpoint.
   If there isn't, start one.
   If we're configured to run in the foreground, this method never returns.
   """
   
   mountpoint_dir = config['mountpoint_dir']
   
   # is the daemon running?
   procs = watchdog.find_by_attrs( "syndicate-automount-daemon", {"mounts": mountpoint_dir} )
   if len(procs) > 0:
      # it's running
      print "Syndicate automount daemon already running for %s (PID(s): %s)" % (mountpoint_dir, ",".join( [str(watchdog.get_proc_pid(p)) for p in procs] ))
      return True
   
   if config.get("foreground", None):
      main( config )
      
   else:
      logfile_path = None 
      pidfile_path = config.get("pidfile", None)
      
      if config.has_key("logdir"):
         logfile_path = os.path.join( config['logdir'], "syndicated.log" )
      
      title = watchdog.attr_proc_title( "syndicate-automount-daemon", {"mounts" : mountpoint_dir} )
      setproctitle.setproctitle( title )
      
      daemon.daemonize( lambda: main(config), logfile_path=logfile_path, pidfile_path=pidfile_path )
      
      return True