Esempio n. 1
0
def cmd_status(params):
    """ Check if the bot is running."""

    print "wikibot_%s:" % params['USK_HASH']
    print "storage: %s" % params['BOT_STORAGE_DIR']

    # Attribution:
    # http://stackoverflow.com/questions/38056/how-do-you-check-in-linux-with- \
    #       python-if-a-process-is-still-running
    try:
        pid = int(open(make_bot_path(params['BOT_STORAGE_DIR'],
                                 'wikibot_' + params['USK_HASH'],
                                 'pid'), 'rb').read().strip())

        print "pid: %i" % pid
        os.kill(pid, 0)
        print "STATUS: Running"
    except IOError: # no pid file
        print "STATUS: Stopped"
    except OSError, err:
        if err.errno == errno.ESRCH:
            print "STATUS: Crashed!"
        elif err.errno == errno.EPERM:
            print "No permission to signal this process! Maybe run whoami?"
        else:
            print "Unknown error checking pid!"
Esempio n. 2
0
def cmd_stop(params):
    """ Stop the bot."""
    try:
        pid = int(open(make_bot_path(params['BOT_STORAGE_DIR'],
                                 'wikibot_' + params['USK_HASH'],
                                 'pid'), 'rb').read().strip())

        print "Stopping, pid: %i..." % pid
        os.kill(pid, signal.SIGINT)
        os.waitpid(pid, 0)
        print "Stopped."
    except IOError: # no pid file
        print "Not running."
    except OSError, err:
        if err.errno ==  errno.ECHILD:
            # Process died before waitpid.
            print "Stopped."
        else:
            print "Failed: ", err