Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have been running a service (a python script using twistd library) as a non-root user that stays in the background. I've been noticing that it crashes at random times and I want to understand why. As far as I know it doesn't use any specific log file on its own, so can you tell me where I can get more information about what's going on? Either a program/application/event log file or a python-related one?

share|improve this question
    
I'm not a programmer, but could strace help? –  petrus Dec 31 '11 at 13:49
    
How do you know it is crashing? You can have a look at system logs /var/log/messages and /var/log/syslog. –  Khaled Dec 31 '11 at 13:49
    
@Khaled I have the same script running on two systems, in one of them the script is always there (ps x) after I executed it once, in the other is not. I've been starting it again and again, it seems to run for some hours every time but next day when I login to the system to check it's not there anymore. –  Ion Dec 31 '11 at 14:02
    
@Khaled I've searched the log files you mentioned but I haven't encountered anything related to the specific script... –  Ion Dec 31 '11 at 14:18
    
It is a good idea to follow @S19N answer and try to run the script by redirecting output and error to a log file and see it after every while. –  Khaled Dec 31 '11 at 15:43
add comment

3 Answers 3

If the script does not record any log by itself, this can be accomplished by redirecting standard output and error to a known file at launch. In bash use

script.py > /var/log/script.log 2>&1

The nohup utility or shell builtin may also help.

share|improve this answer
add comment

I find it useful to always include logging functionality (via the Python logging module) at the top of my scripts.

Here is the official Python logging doc.

Here are some good examples for various types of logging.

share|improve this answer
add comment

I suspect that it is crashing due to an uncaught Exception somewhere. Try catching and logging the exceptions at the highest level in the script that you can. It may give you some clues.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.