[Twisted-Python] twistd and init.d

On Wed, Apr 21, 2010 at 01:38:09PM +0200, Don Schoeman wrote:
I haven't written an init-script for twistd myself, I just use the one auto-generated by tap2rpm. You can compare your script to the template tap2rpm uses and see if that gives you any clues: http://twistedmatrix.com/trac/browser/trunk/twisted/scripts/tap2rpm.py#L17 It surprises me that you say you can tell that the script runs at boot because you can see it in /var/log/messages - although most Linux distros hide the boot-script messages by default, they usually provide a way to display them for debugging purposes such as these (different distributions use different actions to trigger boot messages; if you can't find instructions for your distribution online, you might try hitting Escape a few times at different parts of the boot sequence). Finally, in my limited experience of diagnosing scripts that work from an interactive shell but not at boot time, you might want to look for code that uses environment variables. $EMPLOYER once had some scripts that got some particular setting from an environment variable that was only set by interactive shells - so if you ssh'd to the machine and ran the code, it'd be fine, but it crashed when run at bootup. CentOS (and perhaps other Linux distributions) has a tool called /sbin/service. If you run "/sbin/service ghserver start" rather than "/etc/init.d/ghserver start", /sbin/service will start the service in a clean, boot-like environment and you might get more debugging clues that way.

My understanding is the twistd will have a default log twistd.log. Thanks, Garyc --- On Wed, 4/21/10, Don Schoeman <don@delphexonline.com> wrote: From: Don Schoeman <don@delphexonline.com> Subject: Re: [Twisted-Python] twistd and init.d To: "Twisted general discussion" <twisted-python@twistedmatrix.com> Date: Wednesday, April 21, 2010, 7:54 AM Sorry, I mean't to say I will use the full path to twistd (i.e. /usr/bin/twistd) and see if that works. Don Schoeman wrote: Thanks for the tips guys, Maartin, I have a feeling that you may be correct. I'm going to see if I can't set the python path within the script. Tim, the only reason I can see anything in /var/logs/messages is because I use the "logger" tool to log those messages directly from the bash shell script. See the script below. Kind Regards, Don Don Schoeman wrote: Hi guys, My application is being executed using twistd as per documentation. All is working fine but I need to have the service start automatically at boot time. So as a test I've created a script in /etc/init.d/ which looks like this: #! /bin/sh ### BEGIN INIT INFO # Provides: ghserver # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop GHServer server ### END INIT INFO logger "GHServer: Start script executed" GH_SERVER_PATH="/home/myname/Python/ghserver" export PYTHONPATH="$GH_SERVER_PATH:$PYTHONPATH" case "$1" in start) logger "GHServer: Starting" echo "Starting GHServer..." twistd -y "$GH_SERVER_PATH/ghserverapp.py" -l "$GH_SERVER_PATH/ghserver.log" --pidfile "$GH_SERVER_PATH/twistd.pid" ;; stop) logger "GHServer: Stopping" echo "Stopping GHServer..." kill `cat $GH_SERVER_PATH/twistd.pid` ;; *) logger "GHServer: Invalid usage" echo "Usage: /etc/init.d/ghserver {start|stop}" exit 1 ;; esac exit 0 This works fine when running /etc/init.d/ghserver start and /etc/init.d/ghserver stop. The script also run when I boot since the logger actually logs the "GHServer: Starting" text to the /var/log/messages file. However, my service actually does not start. There is no pid to be found anywhere, there are no error logs anywhere, just nothing. I might be doing something wrong here but is there someone who's gone through this process and can provide some samples how they did it? Any help will be greatly appreciated. Kind Regards, Don _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python -----Inline Attachment Follows----- _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

I think Itamar was suggesting that you use "/bin/bash -x" as your init script interpreter and examine that output. It may also make sense to find someone who knows about writing init scripts for your platform and ask them some questions. It seems like this is an issue with the environment around twistd, not with twistd itself. Jean-Paul

Hey Guys, I apologise in advance but this is is not the correct platform. Essentially I'm porting my server to a new VPS and the platform is enough to cause me headaches to resurrect my twisted server. I'm using open-ssl however I'm seeing mismatches: [root@1003100U6H1Z pyOpenSSL-0.9]# python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
What is this PyUnicodeUCS2_Decode? Has anybody else seen this blighter? Thanks, Garyc

On Apr 21, 2010, at 2:47 PM, gary clark wrote:
undefined symbol: PyUnicodeUCS2_Decode
What is this PyUnicodeUCS2_Decode? Has anybody else seen this blighter?
When you build Python, you either build its Unicode support with support for UCS2 (2-byte, 16-bit code points) or UCS4 (4-byte, 32-bit code points). Extension modules must be built in the same configuration as the Python interpreter in order to be loaded and dynamically linked correctly, since UCS4 python is missing the UCS2 symbols and vice versa. It looks like you have a UCS4 python and a UCS2 PyOpenSSL. You need to re-build PyOpenSSL against the Python installation that you are using, or at least one built with the same options. This is a pretty common build problem; if you search for mailing list threads about it on python-list or python-dev you should find plenty. Good luck, -glyph

Hi Don, Here's the init.d we use for Twisted on Ubuntu. Sets the full path to Twistd: http://gist.github.com/373978 -J On Wed, Apr 21, 2010 at 5:38 AM, Don Schoeman <don@delphexonline.com> wrote:

On Wed, Apr 21, 2010 at 01:38:09PM +0200, Don Schoeman wrote:
I haven't written an init-script for twistd myself, I just use the one auto-generated by tap2rpm. You can compare your script to the template tap2rpm uses and see if that gives you any clues: http://twistedmatrix.com/trac/browser/trunk/twisted/scripts/tap2rpm.py#L17 It surprises me that you say you can tell that the script runs at boot because you can see it in /var/log/messages - although most Linux distros hide the boot-script messages by default, they usually provide a way to display them for debugging purposes such as these (different distributions use different actions to trigger boot messages; if you can't find instructions for your distribution online, you might try hitting Escape a few times at different parts of the boot sequence). Finally, in my limited experience of diagnosing scripts that work from an interactive shell but not at boot time, you might want to look for code that uses environment variables. $EMPLOYER once had some scripts that got some particular setting from an environment variable that was only set by interactive shells - so if you ssh'd to the machine and ran the code, it'd be fine, but it crashed when run at bootup. CentOS (and perhaps other Linux distributions) has a tool called /sbin/service. If you run "/sbin/service ghserver start" rather than "/etc/init.d/ghserver start", /sbin/service will start the service in a clean, boot-like environment and you might get more debugging clues that way.

My understanding is the twistd will have a default log twistd.log. Thanks, Garyc --- On Wed, 4/21/10, Don Schoeman <don@delphexonline.com> wrote: From: Don Schoeman <don@delphexonline.com> Subject: Re: [Twisted-Python] twistd and init.d To: "Twisted general discussion" <twisted-python@twistedmatrix.com> Date: Wednesday, April 21, 2010, 7:54 AM Sorry, I mean't to say I will use the full path to twistd (i.e. /usr/bin/twistd) and see if that works. Don Schoeman wrote: Thanks for the tips guys, Maartin, I have a feeling that you may be correct. I'm going to see if I can't set the python path within the script. Tim, the only reason I can see anything in /var/logs/messages is because I use the "logger" tool to log those messages directly from the bash shell script. See the script below. Kind Regards, Don Don Schoeman wrote: Hi guys, My application is being executed using twistd as per documentation. All is working fine but I need to have the service start automatically at boot time. So as a test I've created a script in /etc/init.d/ which looks like this: #! /bin/sh ### BEGIN INIT INFO # Provides: ghserver # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop GHServer server ### END INIT INFO logger "GHServer: Start script executed" GH_SERVER_PATH="/home/myname/Python/ghserver" export PYTHONPATH="$GH_SERVER_PATH:$PYTHONPATH" case "$1" in start) logger "GHServer: Starting" echo "Starting GHServer..." twistd -y "$GH_SERVER_PATH/ghserverapp.py" -l "$GH_SERVER_PATH/ghserver.log" --pidfile "$GH_SERVER_PATH/twistd.pid" ;; stop) logger "GHServer: Stopping" echo "Stopping GHServer..." kill `cat $GH_SERVER_PATH/twistd.pid` ;; *) logger "GHServer: Invalid usage" echo "Usage: /etc/init.d/ghserver {start|stop}" exit 1 ;; esac exit 0 This works fine when running /etc/init.d/ghserver start and /etc/init.d/ghserver stop. The script also run when I boot since the logger actually logs the "GHServer: Starting" text to the /var/log/messages file. However, my service actually does not start. There is no pid to be found anywhere, there are no error logs anywhere, just nothing. I might be doing something wrong here but is there someone who's gone through this process and can provide some samples how they did it? Any help will be greatly appreciated. Kind Regards, Don _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python -----Inline Attachment Follows----- _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

I think Itamar was suggesting that you use "/bin/bash -x" as your init script interpreter and examine that output. It may also make sense to find someone who knows about writing init scripts for your platform and ask them some questions. It seems like this is an issue with the environment around twistd, not with twistd itself. Jean-Paul

Hey Guys, I apologise in advance but this is is not the correct platform. Essentially I'm porting my server to a new VPS and the platform is enough to cause me headaches to resurrect my twisted server. I'm using open-ssl however I'm seeing mismatches: [root@1003100U6H1Z pyOpenSSL-0.9]# python Python 2.5.2 (r252:60911, Sep 30 2008, 15:41:38) [GCC 4.3.2 20080917 (Red Hat 4.3.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
What is this PyUnicodeUCS2_Decode? Has anybody else seen this blighter? Thanks, Garyc

On Apr 21, 2010, at 2:47 PM, gary clark wrote:
undefined symbol: PyUnicodeUCS2_Decode
What is this PyUnicodeUCS2_Decode? Has anybody else seen this blighter?
When you build Python, you either build its Unicode support with support for UCS2 (2-byte, 16-bit code points) or UCS4 (4-byte, 32-bit code points). Extension modules must be built in the same configuration as the Python interpreter in order to be loaded and dynamically linked correctly, since UCS4 python is missing the UCS2 symbols and vice versa. It looks like you have a UCS4 python and a UCS2 PyOpenSSL. You need to re-build PyOpenSSL against the Python installation that you are using, or at least one built with the same options. This is a pretty common build problem; if you search for mailing list threads about it on python-list or python-dev you should find plenty. Good luck, -glyph

Hi Don, Here's the init.d we use for Twisted on Ubuntu. Sets the full path to Twistd: http://gist.github.com/373978 -J On Wed, Apr 21, 2010 at 5:38 AM, Don Schoeman <don@delphexonline.com> wrote:
participants (9)
-
Don Schoeman
-
exarkun@twistedmatrix.com
-
gary clark
-
Glyph Lefkowitz
-
Itamar Turner-Trauring
-
Jason J. W. Williams
-
Kevin Horn
-
Maarten ter Huurne
-
Tim Allen