I'm calling my program using twistd, like this: # twistd -y /usr/lib/python2.4/site-packages/apolicy/server.py -q --logfile /var/log/twistd.log --pidfile=/var/run/twistd.pid
All right, no problem. But my program makes some tests while starting the service, like loading configuration files, etc. If there is any exception twistd keeps running, so I tried calling reactor.stop(), but I get an RuntimeError saying that it is not possible to stop the reactor because it is not running. So I tried calling sys.exit(1). twistd exits, but the code I'm passing is not returned by twistd, witch returns 0. This messes with my init scripts, so if my user calls 'service mydaemon start' the system will print an 'OK', but twistd will not be running in case of any errors.
How can I proceed to avoid this behavior?