tags:

views:

79

answers:

3

Shouldn't following command run myScript only at the runlevel 2. I noticed it executes at reboot too. I wanted to run it only and only at startup.

update-rc.d myScript start 01 2 . stop 01 0 1 6 .
A: 

You should recognize the different runlevels inside myScript and do something different depending on the case. In runlevel 6 you should write some file to be discovered next time you reach runlevel 2. However, you may need to revise your design as this is a very strange requirement. What do you need to achieve ?

dtmilano
Sorry dtmilano, for creating the confusion. I did not want to say 'reboot'. What I wanted to say is that the script runs when I 'shutdown' the pc. I have found what wrong was I doing i.e. to start a script only at startup I should not use the 'stop' option of update-rc.d.
baltusaj
A: 

How is startup and reboot different? If the machine is dual-boot machine you can reboot from linux but then after that boot into windows for some time, say an hour, before again rebooting and boot linux. How is that different from just shutting down the machine for an hour? There is no way you can detect or predict at shutdown time what will happen after the reboot.

What I think you actually want to check is when your machine starts up booting linux your script must check how long time it was since the machine was shut down last time. If that is within a short period of time, say 5 minutes, you count it as a reboot. Otherwise you count it as a startup.

hlovdal
Sorry hlovadal, for creating the confusion. I did not want to say 'reboot'. What I wanted to say is that the script runs when I 'shutdown' the pc. I have found what wrong was I doing i.e. to start a script only at startup I should not use the 'stop' option of update-rc.d.
baltusaj
+1  A: 

That's right. You need to check the first argument (start, stop, etc.) passed to your script to decide whats happening. It is explained in Debian Policy Manual '9.3.2 Writing the scripts' section.

Or alternatively you can run your script just by placing it in /etc/init.d/rc.local file or do not include any stop levels in your update-rc.d.

Maxwell Troy Milton King
Yeah I found the same solution i.e. not to include any Stop level. Thanks
baltusaj