Пример #1
0
def main():
    # Invalid executions
    if len(sys.argv) < 2 or sys.argv[1] not in [
            COMMAND_START, COMMAND_STOP, COMMAND_RESTART
    ]:
        usage()
        exit()

    daemon = ''
    pidfile = 0

    if sys.argv[1] == COMMAND_START:
        daemon = yapdi.Daemon(pidfile='/var/run/serial-log.pid')
        # Check whether an instance is already running
        if daemon.status():
            print("An instance is already running.")
            exit()
        retcode = daemon.daemonize()

        # Execute if daemonization was successful else exit
        if retcode == yapdi.OPERATION_SUCCESSFUL:
            report("Started")
            log()
        else:
            print('Daemonization failed')

    elif sys.argv[1] == COMMAND_STOP:
        daemon = yapdi.Daemon(pidfile='/var/run/serial-log.pid')

        # Check whether no instance is running
        if not daemon.status():
            print("No instance running.")
            exit()

        retcode = daemon.kill()
        report("Stopping")
        if retcode == yapdi.OPERATION_FAILED:
            print('Trying to stop running instance failed')
            report("Failed to kill previous instance")

    elif sys.argv[1] == COMMAND_RESTART:
        daemon = yapdi.Daemon()
        retcode = daemon.restart()

        # Execute if daemonization was successful else exit
        if retcode == yapdi.OPERATION_SUCCESSFUL:
            report("Restarted")
            log()
        else:
            print('Daemonization failed')
            report("Error on restart")
Пример #2
0
def main():
    #. logger
    logging.basicConfig(
        filename=LOGFILE,
        format='%(asctime)s - %(levelname)s - %(message)s',
        #datefmt='%Y-%M-%d %H:%M:%S',
        level=logging.DEBUG,
    )
    #. parse arg
    parser = argparse.ArgumentParser()
    parser.add_argument('action', choices=['start', 'stop'])
    args = parser.parse_args()
    daemon = yapdi.Daemon(pidfile=PIDFILE, stderr=LOGFILE)
    if args.action == 'start':
        print "Start %s ..." % (BOTNAME)
        #. daemonize
        if daemon.status():
            print "%s is already running!" % (BOTNAME)
            exit()
        retcode = daemon.daemonize()
        if retcode == yapdi.OPERATION_SUCCESSFUL:
            try:
                signal.signal(signal.SIGTERM, sigterm_handler)
                #. mailbot
                global mailbot_instance
                mailbot_instance = MailBot(BIND_ADDRESS, (SMTP_ADDRESS))
                mailbot_instance.start()
                while mailbot_instance:
                    if DEBUG:
                        mailbot_instance.stats()
                    time.sleep(1)
            #. If something error, we can use CTRL+C to force the bot stop.
            except KeyboardInterrupt:
                mailbot_instance.stop()
            except Exception, e:
                mailbot_instance.notice(text="Exception: %s" % (str(e)),
                                        subject="%s error!" % (BOTNAME))
        else:
            print('Daemonization failed!')
Пример #3
0
    usage()
    exit()


def count():
    ''' Outputs a counting value to syslog. Sleeps for 1 second between counts '''
    i = 0
    while 1:
        syslog.openlog("yapdi-example.info", 0, syslog.LOG_USER)
        syslog.syslog(syslog.LOG_NOTICE, 'Counting %s' % (i))
        i += 1
        time.sleep(1)


if sys.argv[1] == COMMAND_START:
    daemon = yapdi.Daemon()

    # Check whether an instance is already running
    if daemon.status():
        print("An instance is already running.")
        exit()
    retcode = daemon.daemonize()

    # Execute if daemonization was successful else exit
    if retcode == yapdi.OPERATION_SUCCESSFUL:
        count()
    else:
        print('Daemonization failed')

elif sys.argv[1] == COMMAND_STOP:
    daemon = yapdi.Daemon()
Пример #4
0
            # mal profile update requests queue is empty.
            self.info['last_run_time'] = datetime.datetime.now(tz=pytz.utc)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("action",
                        choices=["start", "stop", "restart"],
                        help="start, stop, or restart the daemon")
    parser.add_argument("--config",
                        default='./config.txt',
                        help="path to a config textfile")
    args = parser.parse_args()

    if args.action == "start":
        daemon = yapdi.Daemon(pidfile='/var/run/animurecs_bot.pid')

        # Check whether an instance is already running
        if daemon.status():
            print("An instance is already running.")
            exit()
        retcode = daemon.daemonize()
        # Execute if daemonization was successful else exit
        if retcode == yapdi.OPERATION_SUCCESSFUL:
            bot = animurecs('animurecs',
                            animurecs_modules,
                            config_file=args.config)
            bot.run()
        else:
            syslog.syslog(syslog.LOG_CRIT, 'Daemonization failed')
Пример #5
0
@app.get('/socket.io/<path:path>')
def socketio_service(path):
    """socket.io connect path.
    """
    socketio_manage(bottle.request.environ, {'/log': LogNameSpace},
                    bottle.request)


###############################################################################
# Main
###############################################################################

if __name__ == '__main__':
    ctrls = ['start', 'stop', 'status', 'dev']
    daemon = yapdi.Daemon(pidfile=config.PIDFILE, stderr=config.LOGFILE)
    if len(sys.argv) == 2 and sys.argv[1] in ctrls:
        arg = sys.argv[1]
        if arg == 'start':
            if daemon.status():
                print "Pidfile exist: %s, %s(%s) is running already!" % (
                    config.PIDFILE, config.APPNAME, daemon.status())
                exit()
            retcode = daemon.daemonize()
            if retcode == yapdi.OPERATION_SUCCESSFUL:
                try:
                    run(dev=False)
                except KeyboardInterrupt:
                    exit()
        if arg == 'stop':
            if not daemon.status():