コード例 #1
0
ファイル: londiste.py プロジェクト: carriercomm/xztech
    def send_signal(self, sig):
        """ Londiste can launch other process for copy, so manages it here """
        if sig in (signal.SIGTERM, signal.SIGINT):
            # kill copy process if it exists before stopping
            copy_pidfile = self.pidfile + ".copy"
            if os.path.isfile(copy_pidfile):
                self.log.info("Signaling running COPY first")
                skytools.signal_pidfile(copy_pidfile, signal.SIGTERM)

        # now resort to DBScript send_signal()
        skytools.DBScript.send_signal(self, sig)
コード例 #2
0
 def cmd_start(self, job_name):
     if job_name not in self.job_map:
         self.log.error('Unknown job: ' + job_name)
         return 1
     job = self.job_map[job_name]
     if job['disabled']:
         self.log.info("Skipping %s" % job_name)
         return 0
     self.log.info('Starting %s' % job_name)
     os.chdir(job['cwd'])
     pidfile = job['pidfile']
     if not pidfile:
         self.log.warning("No pidfile for %s cannot launch")
         return 0
     if os.path.isfile(pidfile):
         if skytools.signal_pidfile(pidfile, 0):
             self.log.warning("Script %s seems running" % job_name)
             return 0
         else:
             self.log.info("Ignoring stale pidfile for %s" % job_name)
     cmd = "%(script)s %(config)s %(args)s -d" % job
     res = os.system(cmd)
     self.log.debug(res)
     if res != 0:
         self.log.error('startup failed: %s' % job_name)
         return 1
     else:
         return 0
コード例 #3
0
    def launch_copy(self, tbl_stat):
        """Run paraller worker for copy."""
        self.log.info("Launching copy process")
        script = sys.argv[0]
        conf = self.cf.filename
        cmd = [script, conf, 'copy', tbl_stat.name, '-d']

        # pass same verbosity options as main script got
        if self.options.quiet:
            cmd.append('-q')
        if self.options.verbose:
            cmd.append('-v')

        # let existing copy finish and clean its pidfile,
        # otherwise new copy will exit immidiately.
        # FIXME: should not happen on per-table pidfile ???
        copy_pidfile = "%s.copy.%s" % (self.pidfile, tbl_stat.name)
        while skytools.signal_pidfile(copy_pidfile, 0):
            self.log.warning("Waiting for existing copy to exit")
            time.sleep(2)

        # launch and wait for daemonization result
        self.log.debug("Launch args: " + repr(cmd))
        res = os.spawnvp(os.P_WAIT, script, cmd)
        self.log.debug("Launch result: " + repr(res))
        if res != 0:
            self.log.error("Failed to launch copy process, result=%d" % res)
コード例 #4
0
ファイル: jobmgr.py プロジェクト: postsql/cc
 def handle_timer(self):
     if self.proc:
         self.log.debug('checking on %s (%i)', self.jname, self.proc.pid)
         data = self.proc.stdout.read()
         if data:
             self.log.info('Job %s stdout: %r', self.jname, data)
         rc = self.proc.poll()
         if rc is not None:
             self.log.debug('proc exited with %s', rc)
             self.proc = None
     else:
         # daemonization successful?
         live = skytools.signal_pidfile(self.pidfile, 0)
         if live:
             self.log.debug('%s is alive', self.jname)
             if self.start_count > 1 and time.time(
             ) > self.start_time + self.watchdog_reset:
                 self.log.debug('resetting watchdog')
                 self.start_count = 1
         else:
             self.log.warning('%s is dead', self.jname)
             if self.dead_since is None:
                 self.dead_since = time.time()
             if time.time() >= self.dead_since + self._watchdog_wait():
                 self.timer.stop()
                 self.timer = None
                 self.start()
コード例 #5
0
def run_single_process(runnable, daemon, pidfile):
    """Run runnable class, possibly daemonized, locked on pidfile."""

    # check if another process is running
    if pidfile and os.path.isfile(pidfile):
        if skytools.signal_pidfile(pidfile, 0):
            print("Pidfile exists, another process running?")
            sys.exit(1)
        else:
            print("Ignoring stale pidfile")

    # daemonize if needed
    if daemon:
        daemonize()

    # clean only own pidfile
    own_pidfile = False

    try:
        if pidfile:
            data = str(os.getpid())
            skytools.write_atomic(pidfile, data)
            own_pidfile = True

        runnable.run()
    finally:
        if own_pidfile:
            try:
                os.remove(pidfile)
            except:
                pass
コード例 #6
0
ファイル: jobmgr.py プロジェクト: postsql/cc
 def handle_timer(self):
     if self.proc:
         self.log.debug('checking on %s (%i)', self.jname, self.proc.pid)
         data = self.proc.stdout.read()
         if data:
             self.log.info('Job %s stdout: %r', self.jname, data)
         rc = self.proc.poll()
         if rc is not None:
             self.log.debug('proc exited with %s', rc)
             self.proc = None
     else:
         # daemonization successful?
         live = skytools.signal_pidfile(self.pidfile, 0)
         if live:
             self.log.debug ('%s is alive', self.jname)
             if self.start_count > 1 and time.time() > self.start_time + self.watchdog_reset:
                 self.log.debug ('resetting watchdog')
                 self.start_count = 1
         else:
             self.log.warning ('%s is dead', self.jname)
             if self.dead_since is None:
                 self.dead_since = time.time()
             if time.time() >= self.dead_since + self._watchdog_wait():
                 self.timer.stop()
                 self.timer = None
                 self.start()
コード例 #7
0
ファイル: playback.py プロジェクト: mrrusof/skytools
    def launch_copy(self, tbl_stat):
        """Run parallel worker for copy."""
        self.log.info("Launching copy process")
        script = sys.argv[0]
        conf = self.cf.filename
        cmd = [script, conf, 'copy', tbl_stat.name, '-d']

        # pass same verbosity options as main script got
        if self.options.quiet:
            cmd.append('-q')
        if self.options.verbose:
            cmd += ['-v'] * self.options.verbose

        # let existing copy finish and clean its pidfile,
        # otherwise new copy will exit immediately.
        # FIXME: should not happen on per-table pidfile ???
        copy_pidfile = "%s.copy.%s" % (self.pidfile, tbl_stat.name)
        while skytools.signal_pidfile(copy_pidfile, 0):
            self.log.warning("Waiting for existing copy to exit")
            time.sleep(2)

        # launch and wait for daemonization result
        self.log.debug("Launch args: %r", cmd)
        res = os.spawnvp(os.P_WAIT, script, cmd)
        self.log.debug("Launch result: %r", res)
        if res != 0:
            self.log.error("Failed to launch copy process, result=%d", res)
コード例 #8
0
ファイル: scriptmgr.py プロジェクト: digideskio/skytools
 def cmd_start(self, job_name):
     if job_name not in self.job_map:
         self.log.error('Unknown job: '+job_name)
         return 1
     job = self.job_map[job_name]
     if job['disabled']:
         self.log.info("Skipping %s" % job_name)
         return 0
     self.log.info('Starting %s' % job_name)
     os.chdir(job['cwd'])
     pidfile = job['pidfile']
     if not pidfile:
         self.log.warning("No pidfile for %s cannot launch")
         return 0
     if os.path.isfile(pidfile):
         if skytools.signal_pidfile(pidfile, 0):
             self.log.warning("Script %s seems running" % job_name)
             return 0
         else:
             self.log.info("Ignoring stale pidfile for %s" % job_name)
     cmd = "%(script)s %(config)s %(args)s -d" % job
     res = os.system(cmd)
     self.log.debug(res)
     if res != 0:
         self.log.error('startup failed: %s' % job_name)
         return 1
     else:
         return 0
コード例 #9
0
ファイル: scripting.py プロジェクト: cesterlizi/skytools
def run_single_process(runnable, daemon, pidfile):
    """Run runnable class, possibly daemonized, locked on pidfile."""

    # check if another process is running
    if pidfile and os.path.isfile(pidfile):
        if skytools.signal_pidfile(pidfile, 0):
            print("Pidfile exists, another process running?")
            sys.exit(1)
        else:
            print("Ignoring stale pidfile")

    # daemonize if needed
    if daemon:
        daemonize()

    # clean only own pidfile
    own_pidfile = False

    try:
        if pidfile:
            data = str(os.getpid())
            skytools.write_atomic(pidfile, data)
            own_pidfile = True

        runnable.run()
    finally:
        if own_pidfile:
            try:
                os.remove(pidfile)
            except: pass
コード例 #10
0
 def send_signal(self, sig):
     if not self.pidfile:
         self.log.warning("No pidfile in config, nothing to do")
     elif os.path.isfile(self.pidfile):
         alive = skytools.signal_pidfile(self.pidfile, sig)
         if not alive:
             self.log.warning("pidfile exists, but process not running")
     else:
         self.log.warning("No pidfile, process not running")
     sys.exit(0)
コード例 #11
0
ファイル: scripting.py プロジェクト: cesterlizi/skytools
 def send_signal(self, sig):
     if not self.pidfile:
         self.log.warning("No pidfile in config, nothing to do")
     elif os.path.isfile(self.pidfile):
         alive = skytools.signal_pidfile(self.pidfile, sig)
         if not alive:
             self.log.warning("pidfile exists, but process not running")
     else:
         self.log.warning("No pidfile, process not running")
     sys.exit(0)
コード例 #12
0
ファイル: taskrunner.py プロジェクト: gamato/hots-cc
 def watchdog (self):
     live = skytools.signal_pidfile (self.pidfile, 0)
     if live:
         self.log.debug ('%s is alive', self.name)
         if self.heartbeat:
             self.send_reply ('running')
     else:
         self.log.info ('%s is over', self.name)
         self.dead_since = time.time()
         self.timer.stop()
         self.timer = None
         self.send_reply ('stopped')
コード例 #13
0
ファイル: taskrunner.py プロジェクト: kitsemets/hots-cc
 def watchdog(self):
     live = skytools.signal_pidfile(self.pidfile, 0)
     if live:
         self.log.debug('%s is alive', self.name)
         if self.heartbeat:
             self.send_reply('running')
     else:
         self.log.info('%s is over', self.name)
         self.dead_since = time.time()
         self.timer.stop()
         self.timer = None
         self.send_reply('stopped')
コード例 #14
0
ファイル: scriptmgr.py プロジェクト: David-Gould/skytools
 def wait_for_stop (self, job_name):
     job = self.get_job_by_name (job_name)
     if isinstance (job, int):
         return job # ret.code
     msg = False
     while True:
         if skytools.signal_pidfile (job['pidfile'], 0):
             if not msg:
                 self.log.info ("Waiting for %s to stop", job_name)
                 msg = True
             time.sleep (0.1)
         else:
             return 0
コード例 #15
0
ファイル: scriptmgr.py プロジェクト: olsender/skytools
 def wait_for_stop(self, job_name):
     job = self.get_job_by_name(job_name)
     if isinstance(job, int):
         return job  # ret.code
     msg = False
     while True:
         if skytools.signal_pidfile(job['pidfile'], 0):
             if not msg:
                 self.log.info("Waiting for %s to stop" % job_name)
                 msg = True
             time.sleep(0.1)
         else:
             return 0
コード例 #16
0
ファイル: playback.py プロジェクト: priitkustala/skytools-dev
    def launch_copy(self, tbl_stat):
        """Run paraller worker for copy."""
        self.log.info("Launching copy process")
        script = sys.argv[0]
        conf = self.cf.filename
        cmd = [script, conf, 'copy', tbl_stat.name, '-d', '-q']
        if self.options.verbose:
            cmd.append('-v')

        # let existing copy finish and clean its pidfile,
        # otherwise new copy will exit immidiately.
        # FIXME: should not happen on per-table pidfile ???
        copy_pidfile = "%s.copy.%s" % (self.pidfile, tbl_stat.name)
        while skytools.signal_pidfile(copy_pidfile, 0):
            self.log.warning("Waiting for existing copy to exit")
            time.sleep(2)

        self.log.debug("Launch args: "+repr(cmd))
        pid = os.spawnvp(os.P_NOWAIT, script, cmd)
        self.log.debug("Launch result: "+repr(pid))
コード例 #17
0
ファイル: scriptmgr.py プロジェクト: David-Gould/skytools
 def cmd_start(self, job_name):
     job = self.get_job_by_name (job_name)
     if isinstance (job, int):
         return job # ret.code
     self.log.info('Starting %s', job_name)
     pidfile = job['pidfile']
     if not pidfile:
         self.log.warning("No pidfile for %s, cannot launch", job_name)
         return 0
     if os.path.isfile(pidfile):
         if skytools.signal_pidfile(pidfile, 0):
             self.log.warning("Script %s seems running", job_name)
             return 0
         else:
             self.log.info("Ignoring stale pidfile for %s", job_name)
     os.chdir(job['cwd'])
     cmd = "%(script)s %(config)s %(args)s -d" % job
     res = launch_cmd(job, cmd)
     self.log.debug(res)
     if res != 0:
         self.log.error('startup failed: %s', job_name)
         return 1
     else:
         return 0
コード例 #18
0
ファイル: scriptmgr.py プロジェクト: olsender/skytools
 def cmd_start(self, job_name):
     job = self.get_job_by_name(job_name)
     if isinstance(job, int):
         return job  # ret.code
     self.log.info('Starting %s' % job_name)
     os.chdir(job['cwd'])
     pidfile = job['pidfile']
     if not pidfile:
         self.log.warning("No pidfile for %s, cannot launch" % job_name)
         return 0
     if os.path.isfile(pidfile):
         if skytools.signal_pidfile(pidfile, 0):
             self.log.warning("Script %s seems running" % job_name)
             return 0
         else:
             self.log.info("Ignoring stale pidfile for %s" % job_name)
     cmd = "%(script)s %(config)s %(args)s -d" % job
     res = os.system(cmd)
     self.log.debug(res)
     if res != 0:
         self.log.error('startup failed: %s' % job_name)
         return 1
     else:
         return 0
コード例 #19
0
ファイル: taskrunner.py プロジェクト: kitsemets/hots-cc
 def stop(self):
     try:
         self.log.info('Signalling %s', self.name)
         skytools.signal_pidfile(self.pidfile, signal.SIGINT)
     except:
         self.log.exception('signal_pidfile failed: %s', self.pidfile)
コード例 #20
0
ファイル: jobmgr.py プロジェクト: postsql/cc
 def stop(self):
     try:
         self.log.info('Signalling %s', self.jname)
         skytools.signal_pidfile(self.pidfile, signal.SIGINT)
     except:
         self.log.exception('signal_pidfile failed: %s', self.pidfile)