-2

I've bought a VDS server some days ago just to have some Telegram Bots working 24/7.
I can't keep shell always open, so I've decided to use this "hack":
1. In Python script add #!/usr/bin/python3.4
2. sudo chmod u+x mybot.py sudo nohup ./mybot.py & Script successfully starts and works fine, however, in 8-10 hours it eventually stops responding! I see it in ps -aux output though.
To be sure that this is VDS's problem, I've started bots on my ODroid-C1 micro-computer for a day. No problems found, both scripts worked normal.

The main problem is that I can't figure out, why exactly these bots on VDS stop responding. Is there any way to find out?

P.S. Both ODroid and VDS have Ubuntu 14.04 installed.

Groosha
  • 113
  • 1
  • 7

1 Answers1

0

You can try 2 other ways:

First way, with screen:

sudo apt-get install screen

then start screen running same command, and run the script in 'screen' without nohup.

sudo ./mybot.py

Ctrl+A Ctrl+D to detach from screen, disconnect from ssh session. Next time when you see the application is hanged type

screen -r

to attach than screen session where you have running python application

Second - add redirecting from your script's stdout and stderr to log file(s)

sudo nohup ./mybot.py >> /var/log/mybot_out.log 2>>/var/log/mybot_err.log &

or into single file:

sudo nohup ./mybot.py >> /var/log/mybot_out.log 2>>&1 &

then investigate log file after next hangup.

EDIT: If you cannot see anything useful from application output to stdout, stderr when it's hanged - install strace, and attach it to process with your script:

strace -p <PID>

maybe you can find something useful from it. It if doesn't show anything useful (again) - restart the application from strace.

... strace ./mybot.py

better with output to log file, if you have enough free space. Then investigate last thousands of log lines (may contain many duplicates)

  • Could you please explain one thing? `Next time when you see the application is hanged type screen -r to attach than screen session where you have running python application` How this will help me find out the reason of hand? Error messages in terminal? – Groosha Jul 07 '15 at 20:18
  • Yes, exactly. And i extended my answer with checking system calls using strace utility, but it's after first 2 procedures... – Andrii Kupchanko Jul 07 '15 at 20:55