Why does my Pi stop running services or programs?


2 posts
by Alligator » Fri Jan 25, 2013 10:05 pm
I set up a python script to run at startup by placing it in the init.d folder. I registered it, and it starts when the Pi boots. It will run for anywhere from 5 minutes to 10 minutes, then stops. How can I figure out why, and how can I make sure it keeps running (other than a crontab job starting every five minutes)?
User avatar
Posts: 49
Joined: Tue Jun 26, 2012 6:18 pm
by efflandt » Sat Jan 26, 2013 3:24 am
Why not redirect stdout and stderr to a log file, so you can see if an error tells you why it failed (as long as your script does not hide errors it traps). This is a simple demo. In reality you should probably have a full path to the script and location of log file. And if running other than root, the log file should be somewhere that user has permission to write to.

Simple test script that loops outputting date:
Code: Select all
#!/bin/sh
while true; do date; sleep 10; done

Redirection example forked into background with output and errors appended to log file:
Code: Select all
efflandt@XPS8100-1204:~$ dtest >> ~/dtest.log 2>&1 &
[1] 4865
efflandt@XPS8100-1204:~$ fg
dtest >> ~/dtest.log 2>&1
^C
efflandt@XPS8100-1204:~$ cat ~/dtest.log
Fri Jan 25 21:13:37 CST 2013
Fri Jan 25 21:13:47 CST 2013
Fri Jan 25 21:13:57 CST 2013
Fri Jan 25 21:14:07 CST 2013

When error was inserted and run the same way, the error went to log file:
Code: Select all
efflandt@XPS8100-1204:~$ cat bin/dtest
#!/bin/sh
while true; do date; sleep 10; what; done

efflandt@XPS8100-1204:~$ cat dtest.log
Fri Jan 25 21:27:28 CST 2013
/home/efflandt/bin/dtest: 2: /home/efflandt/bin/dtest: what: not found
Fri Jan 25 21:27:38 CST 2013
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA