Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
ragupoOffline
Post subject: shutdown script  PostPosted: 02.01.2011, 14:40



Joined: 2010-09-11
Posts: 29
Location: Copenhagen
Status: Offline
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
      Code:
#!/bin/sh
### BEGIN INIT INFO
# Default-Stop:      0 1 6
### END INIT INFO
echo ON > /sys/kernel/debug/vgaswitcheroo/switch

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

that didn't work. can anyone point out the mistake, please?
 
 View user's profile Send private message  
Reply with quote Back to top
x-un-i
Post subject: RE: shutdown script  PostPosted: 02.01.2011, 17:28
Team Member


Joined: 2010-08-26
Posts: 170

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):
      Code:
                                                                                                                               
### 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
      Code:
### BEGIN INIT INFO                                                                                                                   
# Provides:          Gg                                                                                                               
# Required-Start:                                                                                                                     
# Required-Stop:                                                                                                                     
# Default-Start:                                                                                                                     
# Default-Stop:      .. 6                                                                                                             
# Short-Description: Blah                                                                                                                                                                                                                                 
### END INIT INFO   

_________________
Why do strong arms fatigue themselves with frivolous dumbbells?
To dig a vineyard is worthier exercise for men.
Marcus Valerius Martialis, römischer Satiriker und Epigrammdichter

Será que o diabo perdeu a virgindade?
 
 View user's profile Send private message  
Reply with quote Back to top
sx9Offline
Post subject: RE: shutdown script  PostPosted: 02.01.2011, 18:33



Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
And after copying it to /etc/init.d/ you should execute

      Code:
update-rc.d [scriptname] start


and for testing it you can use

      Code:
invoke-rc.d [scriptname] start

_________________
My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
 
 View user's profile Send private message Send e-mail Yahoo Messenger  
Reply with quote Back to top
ragupoOffline
Post subject:   PostPosted: 02.01.2011, 21:08



Joined: 2010-09-11
Posts: 29
Location: Copenhagen
Status: Offline
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
 
 View user's profile Send private message  
Reply with quote Back to top
dieresOffline
Post subject:   PostPosted: 04.01.2011, 09:18



Joined: 2010-09-12
Posts: 30

Status: Offline
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.
 
 View user's profile Send private message  
Reply with quote Back to top
ragupoOffline
Post subject:   PostPosted: 04.01.2011, 09:59



Joined: 2010-09-11
Posts: 29
Location: Copenhagen
Status: Offline
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
      Code:
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)
      Code:
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
      Code:
# 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
or
# Default-Stop: 0 6
 
 View user's profile Send private message  
Reply with quote Back to top
dieresOffline
Post subject:   PostPosted: 05.01.2011, 07:07



Joined: 2010-09-12
Posts: 30

Status: Offline
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.
 
 View user's profile Send private message  
Reply with quote Back to top
sx9Offline
Post subject:   PostPosted: 07.01.2011, 00:39



Joined: 2010-09-12
Posts: 219
Location: Wiesbaden,Germany
Status: Offline
Try to use

      Code:

case $1 in
    start)
# do nothing important
    ;;
    stop)
# 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)
    ;;
esac

_________________
My new self-made computer:
Intel Core i7-2600k
ASUS Maximus IV Gene-Z (Mainboard)
2x4GB DDR3 RAM
ATI Radeon HD 6770
OCZ Vertex 3 60GB (SSD)
Western Digital Caviar Green WD20EARX 2TB (HDD)
...
aptosid x86_64
 
 View user's profile Send private message Send e-mail Yahoo Messenger  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 12 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by Zafenio