User Scripts & Dragons - shutdown script

ragupo - 02.01.2011, 14:40
Post subject: shutdown script
I need to run a command at shutdown, a few days ago i got instructions on irc from x-un-i, but i'm obvious to noob in making scripts to follow simple instructions, as the resulting modifications had to be undone with the live cd to make the system start again. The instructions was:
you can create a skript that u save in /etc/init.d ( read the README file there for the corresponding header there u only need to set the Default stop . and then using insserv to enable it
i wrote this in the script called graph-on
# Default-Stop:      0 1 6
echo ON > /sys/kernel/debug/vgaswitcheroo/switch

made it executable andplaced it in /etc/init.d, and then issued
insserv graph-on

that didn't work. can anyone point out the mistake, please?
x-un-i - 02.01.2011, 17:28
Post subject: RE: shutdown script
why do you strip the other header Information that is in the README?

All init.d scripts are expected to have a LSB style header documenting dependencies and default runlevel settings.

The header look like this (not all fields are required):
### BEGIN INIT INFO                                                                                                                   
# Provides:          skeleton                                                                                                         
# Required-Start:    $remote_fs $syslog                                                                                               
# Required-Stop:     $remote_fs $syslog                                                                                               
# Should-Start:      $portmap                                                                                                         
# Should-Stop:       $portmap                                                                                                         
# X-Start-Before:    nis                                                                                                             
# X-Stop-After:      nis                                                                                                             
# Default-Start:     2 3 4 5                                                                                                         
# Default-Stop:      0 1 6                                                                                                           
# X-Interactive:     true                                                                                                             
# Short-Description: Example initscript                                                                                               
# Description:       This file should be used to construct scripts to be                                                             
#                    placed in /etc/init.d.                                                                                           
### END INIT INFO                               

u need it at least
### BEGIN INIT INFO                                                                                                                   
# Provides:          Gg                                                                                                               
# Required-Start:                                                                                                                     
# Required-Stop:                                                                                                                     
# Default-Start:                                                                                                                     
# Default-Stop:      .. 6                                                                                                             
# Short-Description: Blah                                                                                                                                                                                                                                 

sx9 - 02.01.2011, 18:33
Post subject: RE: shutdown script
And after copying it to /etc/init.d/ you should execute

update-rc.d [scriptname] start

and for testing it you can use

invoke-rc.d [scriptname] start

ragupo - 02.01.2011, 21:08
Post subject:
As said I have level -5 in all of this so I just misunderstood this part
there u only need to set the Default stop .
wrongly figuring that this meant to just leave the others out.
Thanks for the swift reply both, i cannot test now, but i feel confident that its gonna be pretty hard to mess it up again with these instructions by my side
dieres - 04.01.2011, 09:18
Post subject:
as i understood graph_on with standard headers will be executed
with parameter stop in 0 1 6 with parameter start in 2 3 4 5.

you should make a case selection for parameter stop in the script, or it will be executed in every runlevel, i think.

simply use the skeleton example and adjust it for your needs.
ragupo - 04.01.2011, 09:59
Post subject:
Ill just give a total description of what i try to do, might be that theres even some other smart way around it.
My laptop has 2 graphics cards and they are both on at boot time. For switcheroo to switch off the unused card after booting i need to execute
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

Furthermore i find it useful for user to be able to switch the cards, not having to become root. This i accomplish by editing /etc/rc.local and inserting these two lines (but it might be more correct make this work through init.d)
chown "ragupo" /sys/kernel/debug/vgaswitcheroo/switch
echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

If the unused card is not turned on again before shutdown, horrible errors will occur, therefore i need to issue
<code>echo ON > /sys/kernel/debug/vgaswitcheroo/switch</code>
before shutting down.
these entries in the header
# Default-Start:     2 3 4 5                                                                                                         
# Default-Stop:      0 1 6   

confuse me, theres no "stopping" these commands.
So for my simple script containing one command to be run at shutdown is that
# Default-Start: 0 6
# Default-Stop: 0 6
dieres - 05.01.2011, 07:07
Post subject:
should be default stop.

but once more again, you have to do a selection in your script,
please have a look at the examplefile /etc/init.d/skeleton.
sx9 - 07.01.2011, 00:39
Post subject:
Try to use


case $1 in
# do nothing important
# Enter here your Script that has to Be executed
# during shutting down Example:
        echo "Hi, I'm stupid"
        echo "Unknown Option"
        echo "Usage: [name] (start|stop)

All times are GMT - 12 Hours
Powered by PNphpBB2 © 2003-2010 The Zafenio Group