How to add more command arguments to python-daemon?
<p>I have a basic Python daemon created using older version of python-daemon and this code:</p>

<pre><code>import time
from daemon import runner

class App():
    def __init__(self):
        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/tty'
        self.stderr_path = '/dev/tty'
        self.pidfile_path =  '/tmp/foo.pid'
        self.pidfile_timeout = 5
    def run(self):
        while True:
            print("Howdy!  Gig'em!  Whoop!")
            time.sleep(10)

app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()
</code></pre>

<p>Now everything works fine but I need to add one more possible command to my daemon. Current default commands are "start, stop, restart". I need fourth command "mycommand" that will only run this code when executed:</p>

<pre><code>my_function()
print "Function was successfully run!"
</code></pre>

<p>I have tried Googling and researching but couldn't figure it out on my own. I tried picking up arguments manually without sinking into python-daemon code, with <code>sys.argv</code> but couldn't make it work.</p>

<p>Looking at the code of the runner module, the following should work... I have problems with defining the stdout and stderr... could you test it?</p>

<pre><code>from daemon import runner
import time

# Inerith from the DaemonRunner class to create a personal runner
class MyRunner(runner.DaemonRunner):

    def __init__(self, *args, **kwd):
        super().__init__(*args, **kwd)

    # define the function that execute your stuff...
    def _mycommand(self):
        print('execute my command')

    # tell to the class how to reach that function
    action_funcs = runner.DaemonRunner.action_funcs
    action_funcs['mycommand'] = _mycommand


class App():
    def __init__(self):
        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/tty'
        self.stderr_path = '/dev/tty'
        self.pidfile_path =  '/tmp/foo.pid'
        self.pidfile_timeout = 5
    def run(self):
        while True:
            print("Howdy!  Gig'em!  Whoop!")
            time.sleep(10)

app = App()
# bind to your "MyRunner" instead of the generic one
daemon_runner = MyRunner(app)
daemon_runner.do_action()
</code></pre>

python python-2.7 daemon python-daemon