Best way to start python script on Linino restart

Hi!
Can one of the Linino experts please help me?

I would like to start my python script (which in turn uses tornado) on boot or, what may be even better, on restart of Linino so that it will get restarted too if one presses the Yun RST button.

python /www/sd/yun_tests/server.py

I read about making an init.d script. But what should I have to use for the START and STOP values?
What else to put in there?

And be warned, I'm no Linux guy!

I would think the best ways is to start a crontab like this :

crontab -e

opens vi to edit it

then add in the first line this:

 @reboot python /www/sd/yun_tests/server.py

This will run your script (/www/sd/yun_tests/server.py) at reboot if one presses the Yun RST button

Hope this helps.

Please remember to restart your yun after you add the crontab to take effect.

Thanks. Sound good. Will give it a try.
What exactly do you mean by "restart your yun after you add the crontab to take effect"?
Does it mean to power down or to press the Yun RST button?

Any of the two.... just reset for the crojob to take effect.
Although, in your case the yun would reset anyway for you to see if the cronjob is working since it is something that has to happen in startup so my comment was kinda useless :slight_smile:

according to this thread Problem programming cron tasks in YUN - #3 by roquec - Arduino Yún - Arduino Forum
I think it will not work.

any other suggestions, like init.d?

no idea with the init.d,
Another idea /hack would be to start a crontab with a script running every minute
the script, lets call it check.py will be looking if the server.py is running . If yes it does nothing. If no, it calls server.py
No code from me, but i bet somebody can help, i am just trying to think of ways to do it.
I guesss you can check from the PID like this post suggests:

hope this helps a little

Did a little search and it looks like one has to start and enable cron first.
Found this on superuser.com:
By default OpenWrt does not enable the cron service. To start it and enable automatic startup during subsequent reboots, you need to execute the following commands:

/etc/init.d/cron start
/etc/init.d/cron enable

There is a box at the bottom of the System->Startup page in luci where you put commands to execute at start up. You can edit /etc/rc.local if you prefer, they will do the same thing.

I made a script named test in /root:

#!/bin/ash
touch /root/started

made it executable:

chmod a+x /root/test

make rc.local look like this:

root@Yun:/# cat /etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/root/test


exit 0

after I reboot I get:

ls -l
-rw-r--r--    1 root     root             0 Nov 23 11:42 started
-rwxr-xr-x    1 root     root            32 Nov 23 11:20 test

showing me the last time I rebooted, a few minutes later I get

ls -l /root
-rw-r--r--    1 root     root             0 Nov 23 11:56 started
-rwxr-xr-x    1 root     root            32 Nov 23 11:20 test

This will be the VERY last thing done on startup, you need a little patience, I can actually get a console before the script is run, and see this:

root@Yun:/# ls -l /root
-rw-r--r--    1 root     root             0 Nov 23 11:42 started
-rwxr-xr-x    1 root     root            32 Nov 23 11:20 test
root@Yun:/# 
root@Yun:/# ls -l /root
-rw-r--r--    1 root     root             0 Nov 23 11:56 started
-rwxr-xr-x    1 root     root            32 Nov 23 11:20 test

Yep, will use this to start my python script:

(sleep 10;python /www/sd/fg100_yun/server.py)&

I have an additional line before "exit 0" in my rc.local. Do you put your launch script before or after "wifi-live-or-reset"?

I have flashed my Yun with a image I compiled from source so there are some details different on my Yun, evidently this is one, I don't have that line in my rc.local.

I believe wifi-live-or-reset will reboot the Linino if the wifi interface doesn't appear within a certain time. Some info here:Arduino Yun, power draw - #6 by federicofissore - Arduino Yún - Arduino Forum

In this case I don't think it matters but which ever one you want to run first, comes first.