Page 1 of 1

Programm not starting at reboot

Posted: Sun Nov 22, 2015 4:05 pm
by Canedje
Hello every body

I try to startup a python programm called "webserver.py" at reboot or startup (after halt) of the raspberry at the background

I added the next line to my crontab -e:

@reboot /usr/bin/python /home/ewh/webserver.py &
This is not working?
What am I doing wrong

Thanks

Re: Programm not starting at reboot

Posted: Sun Nov 22, 2015 4:10 pm
by DougieLawson
Nobody knows.

What you need to do is add some print statements to your program and run it with

Code: Select all

@reboot /usr/bin/python /home/ewh/webserver.py 1>/tmp/webbything.output  2> /tmp/webbything.errors&
Then when it fails you'll be able to look at those logfiles to see where it failed.

Re: Programm not starting at reboot

Posted: Sun Nov 22, 2015 4:17 pm
by Canedje
DougieLawson wrote:Nobody knows.

What you need to do is add some print statements to your program and run it with

Code: Select all

@reboot /usr/bin/python /home/ewh/webserver.py 1>/tmp/webbything.output  2> /tmp/webbything.errors&
Then when it fails you'll be able to look at those logfiles to see where it failed.
Thanks I will try

Re: Programm not starting at reboot

Posted: Sun Nov 22, 2015 4:21 pm
by Canedje
It looks like that my SQL is not started yet or something like that.
The error code is:

Code: Select all

Traceback (most recent call last):
  File "/home/ewh/webserver.py", line 75, in <module>
    con = mdb.connect('127.0.0.1', 'pi', 'raspberry', 'tempdb');
  File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (111)")
Is there something I can do to avoid this?

Re: Programm not starting at reboot

Posted: Sun Nov 22, 2015 4:31 pm
by DougieLawson
Add

Code: Select all

auto lo
iface lo inet loopback
back into your /etc/network/interfaces file and reboot.

Add a

Code: Select all

try:
  # ... stuff to connect to MySQL here
except:
  # ... stuff to handle the exception here
block into your code.

Re: Programm not starting at reboot

Posted: Sun Nov 22, 2015 4:49 pm
by Canedje
Thank you

I did already make a "work around"
By calling a launcher.sh script including a sleep function at the @reboot of the crontab
It's working fine now