Run python script at startup

7 posts
by Fezziwig » Fri Jan 04, 2013 12:06 am
Although the title says python this isn't strictly about python so I though it might belong in this catagory.

I've followed many tutorials on how to do this now but none seemed to have done anything.
The way I'm currently trying is having a script in /etc/init.d/test

The script in that is as follows:
Code: Select all
#! /bin/sh
# /etc/init.d/test

# Provides:          noip
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start a program at boot
# Description:       A simple script which will start / stop a program a boot /$

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
    echo "Hello!"
    sleep 10s
    sudo python /home/pi/Desktop/Projects/
    echo "Bye!"
    sleep 10s
    killall python
    exit 1

exit 0

I put in the sleep commands so that I could definitely be sure it had run.
When I run the command:
sudo /etc/init.d/test start
Everything runs as expected with the 10 second pause and then it runs the python script.
When I reboot it just runs though all the normal lines of code(or what ever all the writing is) and goes to the desktop. Why might the script not be running?
Posts: 2
Joined: Tue Jun 19, 2012 7:11 pm
by azeam » Fri Jan 04, 2013 12:32 am
Have you done this:
Code: Select all
sudo update-rc.d test defaults
You should also skip the sudo since that script will be run by root during boot
User avatar
Posts: 192
Joined: Fri Oct 26, 2012 11:13 pm
by LetHopeItsSnowing » Fri Jan 04, 2013 8:29 am
Make sure you have run update-rc.d, its this that registers your script to run at boot and shutdown.
"am I getting slower, or is stuff more complicated; either way I now have to write it down -"
User avatar
Posts: 208
Joined: Sat May 26, 2012 6:40 am
Location: UK
by Fezziwig » Fri Jan 04, 2013 10:47 pm
I had done that, but it wasn't the problem. It turns out because in raspi-config I had set it up to go straight to desktop on boot, it skipped the script. Once I disabled that feature it worked perfect!

Thanks, for your replies.
Posts: 2
Joined: Tue Jun 19, 2012 7:11 pm
by nsweeting » Sun Jan 06, 2013 6:49 pm
Anyone know how to run a python script BEFORE the raspi-config auto login/boot? Having trouble figuring that out.
Posts: 10
Joined: Sun Dec 23, 2012 3:56 pm
by dwelch67 » Sun Jan 06, 2013 11:56 pm
Is this thread related to bare metal programming?
Posts: 406
Joined: Sat May 26, 2012 5:32 pm
by -rst- » Mon Jan 07, 2013 2:17 pm
...or any programming at all? Maybe 'Using... -> Power Users' or 'Operating System... -> <which ever OS you are on>'?? - Low-level graphics and 'Coding Gold Dust'
Posts: 898
Joined: Thu Nov 01, 2012 12:12 pm
Location: Dublin, Ireland