#!/usr/bin/env python3
# Copyright (c) 2006 Arastra, Inc.  All rights reserved.
# Arastra, Inc. Confidential and Proprietary.

# until such time that Sysdb restart does not cause all agents to
# restart, clean up the ProcMgr process configuration file whenever
# this Sysdb is loaded. See BUG12137
try:
   procMgrConfigsPath = "/etc/ProcMgr.d/run/ownedByLauncher"
   import os, time
   if os.access( procMgrConfigsPath, os.F_OK ):
      agentConfigs = os.listdir( procMgrConfigsPath )
      for agentConfig in agentConfigs:
         if agentConfig != "SysdbMonitor":
            # SysdbMonitor will not exit immediately after Sysdb exits.
            # When Sysdb exits, we want to give an already running SysdbMonitor
            # time to handle SSO switchover then exit. So we don't want to remove
            # SysdbMonitor agentConfig so that ProcMgr won't kill SysdbMontior
            os.remove( os.path.join( procMgrConfigsPath, agentConfig ) )
      # kick procMgr  
      os.system( "service ProcMgr reload" )
      time.sleep( 1 )
except OSError:
   pass

import Tac, Sysdb # pylint: disable=import-self
Sysdb.main() # pylint: disable=c-extension-no-member
