Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

Programm not starting at reboot

Sun Nov 22, 2015 4:05 pm

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

User avatar
DougieLawson
Posts: 40594
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Programm not starting at reboot

Sun Nov 22, 2015 4:10 pm

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.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

Re: Programm not starting at reboot

Sun Nov 22, 2015 4:17 pm

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

Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

Re: Programm not starting at reboot

Sun Nov 22, 2015 4:21 pm

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?

User avatar
DougieLawson
Posts: 40594
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Programm not starting at reboot

Sun Nov 22, 2015 4:31 pm

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.
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Canedje
Posts: 265
Joined: Thu Mar 26, 2015 7:18 am

Re: Programm not starting at reboot

Sun Nov 22, 2015 4:49 pm

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

Return to “Troubleshooting”