0

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?

James O'Gorman
  • 5,249
  • 2
  • 23
  • 28
Ion
  • 278
  • 2
  • 3
  • 10
  • 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

3 Answers3

4

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.

S19N
  • 1,693
  • 1
  • 17
  • 28
2

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.

venzen
  • 155
  • 6
0

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.

Stuart Woodward
  • 1,343
  • 4
  • 14
  • 29