Changeset 4066

Show
Ignore:
Timestamp:
02/15/09 22:21:55 (4 years ago)
Author:
gpolo
Message:

Adapted umit-scheduler to run on background

Location:
branch/NetworkInventory
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branch/NetworkInventory/umit-scheduler

    r4034 r4066  
    11#!/usr/bin/env python 
    22# -*- coding: utf-8 -*- 
    3 # 
     3 
    44# Copyright (C) 2007 Insecure.Com LLC. 
    55# 
     
    1010# the Free Software Foundation; either version 2 of the License, or 
    1111# (at your option) any later version. 
    12 # 
     12#  
    1313# This program is distributed in the hope that it will be useful, 
    1414# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1515# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1616# GNU General Public License for more details. 
    17 # 
     17#  
    1818# You should have received a copy of the GNU General Public License 
    1919# along with this program; if not, write to the Free Software 
     
    5959    Show help 
    6060    """ 
    61     print _("Use:") + (" %s start|stop|cleanup <config_dir>" % __file__) 
     61    print _("Use:") + (" %s start|stop|cleanup <config_dir>" % sys.argv[0]) 
    6262 
    6363 
     
    128128        log.debug(">>> Scheduler is stopped already, removing control file..") 
    129129        remove_controlfile() 
    130          
     130 
    131131    log.debug(">>> Cleanup finished") 
    132     
     132 
    133133 
    134134def start(): 
     
    139139        sys.exit(0) 
    140140 
    141     process = subprocess.Popen([sys.executable, Scheduler.__file__, 
    142                                 sys.path[0], 'start', HOME_CONF]) 
     141    from umitCore import Scheduler 
     142    from umitCore.BGProcess import run_on_background 
    143143 
    144     pid = process.pid 
     144    run_on_background() 
    145145 
    146     log.debug(">>> Starting Scheduler..") 
    147     log.debug(">>> Writing pid (%d) to %s" % (pid, RUNNING_FILE)) 
     146    pid = os.getpid() 
    148147 
    149148    f_run = open(RUNNING_FILE, 'w') 
    150149    f_run.write("%d" % pid) 
    151150    f_run.close() 
     151 
     152    Scheduler.main('start', sys.path[0], HOME_CONF) 
    152153 
    153154 
  • branch/NetworkInventory/umitCore/Scheduler.py

    r4034 r4066  
    88# the Free Software Foundation; either version 2 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program; if not, write to the Free Software 
     
    2727import signal 
    2828import warnings 
    29 from os.path import join 
    3029from ConfigParser import ConfigParser 
    3130 
     
    5857    def check_for_changes(self): 
    5958        """ 
    60         If schemas file or profiles file changed since last check,  
     59        If schemas file or profiles file changed since last check, 
    6160        reparse schemas. 
    6261        """ 
     
    630629    if running_scans: 
    631630        scans_count = len(running_scans) 
    632         log.debug("%d scan%s to cleanup" % (scans_count,  
     631        log.debug("%d scan%s to cleanup" % (scans_count, 
    633632                                            (scans_count > 1) and 's' or '')) 
    634633 
     
    666665 
    667666 
    668 if __name__ == "__main__":     
    669     sys.path.insert(0, sys.argv[1]) 
    670  
     667def main(cmd, base_path, home_conf): 
     668    sys.path.insert(0, base_path) 
    671669    from umitCore.Paths import Path 
    672     Path.set_umit_conf(join(sys.argv[3]), True) 
     670    Path.set_umit_conf(home_conf, True) 
    673671 
    674672    from umitCore.UmitLogging import file_log 
     
    680678 
    681679    log = file_log(Path.sched_log) 
    682      
    683     umitdb_ng = Path.umitdb_ng 
     680 
     681    globals().update(locals()) 
    684682 
    685683    if os.name == "posix": 
    686684        signal.signal(signal.SIGHUP, safe_shutdown) 
    687          
    688685    signal.signal(signal.SIGTERM, safe_shutdown) 
    689686    signal.signal(signal.SIGINT, safe_shutdown) 
    690687 
    691     cmds = { "start": start } 
    692  
    693     cmds[sys.argv[2]]() 
    694  
     688    cmds = {'start': start} 
     689    cmds[cmd]() 
     690 
     691if __name__ == "__main__": 
     692    main(*sys.argv)