Redhat services in Python
Stuart D. Gathman
stuart at bmsi.com
Wed Dec 11 21:49:43 EST 2002
I have no problem writing AIX services in python. However, Linux with
sysv-initscript (e.g. Redhat) is driving me crazy. The standard service
wrappers communicate via signals. Simple enough. I can start a
python service no problem - but which pid (there is one for each thread)
to kill for terminate? If I save the child PID after forking the python
interpreter, I get the same value as calling os.getpid() - but sending
signals to this PI has no effect. Generally, the 3rd PID in a ps listing
is the one to send signals to. But how can I get that PID reliably? Is
it necessary to write a C wrapper for python services in RedHat?
Here is an example start script for a service:
#!/bin/sh
cd /var/log/milter
exec >>milter.log 2>&1
python2 bms.py &
echo $! >milter.pid
The python code does:
print "bms milter startup, PID =",os.getpid()
and the output is:
bms milter startup, PID = 1195
Here are the running processes (PPID is shown via indent):
RUSER PID STIME TTY TIME CMD
root 1 Dec09 ? 0:07init [3]
#mail 1195 21:32 pts/1 0:00 python2 bms.py
#mail 1198 21:32 pts/1 0:00 python2 bms.py
#mail 1199 21:32 pts/1 0:00 python2 bms.py
The contents of milter.pid is also 1195. However, to terminate python
requires "kill 1199".
How do other people solve this problem?
--
Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
More information about the Python-list
mailing list