Exemplo n.º 1
0
def main():
    if len(sys.argv) != 2:
        _print_usage_and_exit()
    action = sys.argv[1]
    if action == 'start':
        daemon.start()
    elif action == 'stop':
        daemon.stop()
    elif action == 'status':
        daemon.status()
    else:
        _print_usage_and_exit()
Exemplo n.º 2
0
            logger.info("Exiting Main thread due to Keyboard interrupt.")
            sys.exit(0)
        except Exception as e:
            logger.exception("Exception in main thread")
            keyLoggerThread.stop()
            keyLoggerThread.join()
            logger.warn("Exiting Main thread due to exception.")


      
if __name__ == "__main__":
    daemon = PiWriterDaemon('/tmp/pi-writer-daemon-example.pid', stdout="/home/pi/stdout.log", stderr="/home/pi/stderr.log")
    if len(sys.argv) == 2:
        if 'start' == sys.argv[1]:
            daemon.start()
        elif 'stop' == sys.argv[1]:
            daemon.stop()
        elif 'restart' == sys.argv[1]:
            daemon.restart()
        elif 'status' == sys.argv[1]:
            daemon.status()
        else:
            print "Unknown command"
            sys.exit(2)
        logger.debug("Exiting daemon normally")
        sys.exit(0)
    else:
        print "usage: %s start|stop|restart" % sys.argv[0]
        sys.exit(2)
    
Exemplo n.º 3
0
    parser.add_argument("-d", "--daemon", help="run as a daemon")
    parser.add_argument("-a",
                        "--address",
                        default=smtp_server_domain,
                        help="bind address")
    parser.add_argument("-p",
                        "--port",
                        type=int,
                        default=smtp_server_port,
                        help="bind port")
    args = parser.parse_args()

    if not args.daemon:
        set_foreground_logger()
        _setup_db()
        # not daemon, just run in foreground.
        log.info("Starting smtp listener on as %s:%s", smtp_server_domain,
                 str(smtp_server_port))
        smtp_server.start()
    else:
        daemon = PseudoSMTPDaemon('/tmp/pseudo_smtp.pid')
        if args.daemon == 'start':
            _setup_db()
            daemon.start()
        elif args.daemon == 'stop':
            daemon.stop()
        elif args.daemon == 'restart':
            daemon.restart()
        elif args.daemon == 'status':
            daemon.status()