[Twisted-Python] Implementing startup sanity-checks for twistd services.

Tim Allen tim at commsecure.com.au
Mon Jun 30 04:08:50 EDT 2008


The system I'm working on at the moment is talking to MySQL, and in
order to get reasonable behaviour, I need to make sure the "SQL_MODE"
variable is set on both the database connection, and on the stored
procedures I'll be calling. If this is not set up correctly, I expect
to be plagued with silent data corruption issues. I can force the
SQL_MODE per-connection when I connect to the database, but I need to
double-check the procedures whenever I start up.

Ideally, my system would follow a startup procedure something like this:

 - Read configuration
 - Connect to the configured database.
 - Check the SQL_MODE associated with any stored procedures.
 - If everything checks out OK, continue the startup process.
 - Otherwise, log a noisy error and shut down.

Of course, I'd prefer to do things the Twisted Way if at all possible.

I've had some ideas about how to implement this, but none of them seem
terribly useful:

If I launch my queries at startup, and only add my service to the
master Application object if they return successfully, then by the time
I try to start my service twistd will have (I assume) already dropped
privileges and chroot'd and so forth.

If I attach my service to the master Application object at startup
*then* launch my queries, then I might wind up accepting queries before
my sanity checks have completed, defeating the point.

Also, if my service has started and my sanity-checks fail, how can I
cleanly shut down twistd from inside? If my service is just one of
possibly many running inside the master Application object, it seems a
bit rude for me to call reactor.stop(); on the other hand, if I just
stop my service then twistd keeps happily running - confusing
operations staff who often use 'ps' to check whether systems are up.

Is there a better way to do this?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20080630/5562910c/attachment.pgp 


More information about the Twisted-Python mailing list