Reputation: 5599
When I write a twisted service that will run with the twistd
daemon I also want to make it configurable and run separate daemons, for the same service, with different configurations. But the twistd
daemon does not accept (at least I don't see how) custom arguments from the command line, so what I do is to pass the configuration file in the standard input:
twisd -y myservice.py < my.cfg
and then in the myservice.py
I have the following:
cfg = parseConfig(sys.stdin.read())
application = Application('myapp')
MyService(a=cfg.a, b=cfg.b).setServiceParent(application)
This is working just fine for me, but I'm wondering if there is The Right Way for doing this?
Upvotes: 0
Views: 567
Reputation: 5599
I also want to add one more option without the plugin mechanism, and avoiding the stdio
- namely via the env variables:
CONFIG my.cfg twisd -y myservice.py
with the modified code:
cfg = parseConfig(open(os.environ['CONFIG']).read())
(I didn't think of this earlier because of my limited linux experience.)
Upvotes: 0
Reputation: 28036
It looks as if the Twisted way of doing this is documented here:
https://twistedmatrix.com/documents/12.0.0/core/howto/tap.html
You write plugins that add 'subcommands' which can be used via the CLI
Upvotes: 1