Exemple #1
0
def daemon(action):
    """
    Trigger the daemon, run the action command and return the daemon object
    if required.

    'action' is a string, either start, stop or status
    Returns an instance of deiman.Deiman
    """
    d = Deiman(options.pid)
    if action == "stop":
        d.stop()
        sys.exit(0)
    elif action == "status":
        d.status()
        sys.exit(0)
    if len(sys.argv) == 1:
        print_help()
        sys.exit(2)
    if action == "start":
        d.start()
        return d
    else:
        sys.exit(0)
Exemple #2
0
def daemon(action):
    """
    Trigger the daemon, run the action command and return the daemon object
    if required.

    'action' is a string, either start, stop or status
    Returns an instance of deiman.Deiman
    """
    d = Deiman(options.pid)
    if action == "stop":
        d.stop()
        sys.exit(0)
    elif action == "status":
        d.status()
        sys.exit(0)
    if len(sys.argv) == 1:
        print_help()
        sys.exit(2)
    if action == "start":
        d.start()
        return d
    else:
        sys.exit(0)
Exemple #3
0
# command.
if len(sys.argv) == 1 or sys.argv[1] not in ('start', 'stop', 'status'):
    print("Usage: python simple-daemon.py [start, stop, status]")
    sys.exit(2)

# Set the incoming action to a shorter variable name, lazy.
act = sys.argv[1]
# Action is start, so tell Deiman to fork itself off in to the
# background.
if act == "start":
    d.start()
# Action is stop, this will take the existing PID file, get the
# current process ID and stop the running process.
elif act == "stop":
    d.stop()
    sys.exit(0)
# Action is status, this will get the current status information
# of the process from /proc. It'll tell you if it's running or not
# and also if it's a zombie process.
elif act == "status":
    d.status()
    sys.exit(0)
else:
    print("Unknown option!")
    sys.exit(2)

# Now we loop to keep the process a live until it's stopped.
while True:
    # do something here, it will only run if action is start
    print("Lalala")