Saturday, April 28, 2012

Running Script on Startup - rc.local

By default there is a script that gets executed on startup. On a clean installation this is empty so it doesn't do anything. But you can add some nice function it, e.g. make your favourite programs load when you boot your system.

The file is

Edit it with any application (I use nano or gedit these days)
sudo gedit /etc/ec.local

And just add any commands that you would normally run from a terminal window, these will be run every time you start your system.

Problems encountered

However, rc.local should be executed on startup, at the moment it isn't working for me. I was playing around with it a little, including changing permissions, but then finally changed:
sudo chmod -x /etc/ec.local

Don't know if this worked, its for sure that
sudo chmod 0755 /etc/rc.local

worked and I keft it like that.

sudo update-rc.d rc.local defaults
returned that the simlink already exists. Once again a little diging around (, wikipedia)

I discovered that the problem was that only the first line of rc.local was executed. This happens if there are mistakes in the commands, the script just terminates at that step. So I actually removed a bit from it, which wasn't necessary as it has tuned out.
sudo killall tor

(tor was removed from the runlevel, so it isn't started in the first place)

After this, the script was OK, runs on startup as expected.

Own startup script

Make a script and put it into /etc/init.d

Make it executable:
sudo chmod -x script_name
Add symbolic links with:
update-rc.d script_name defaults

And this should be it. Later on if you happen to want your script removed, run this command
update-rc.d -f script_name remove

No comments:

Post a Comment