LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (http://www.linuxquestions.org/questions/debian-26/)
-   -   Modify Startup and Shutdown Scripts (http://www.linuxquestions.org/questions/debian-26/modify-startup-and-shutdown-scripts-687420/)

explosive_tom 12-01-2008 04:32 AM

Modify Startup and Shutdown Scripts
 
Hi,

I am using Debian Etch.

I have purchased a Belkin Universal UPS and have set it up using NUT, but in order to have the automatic shutdown and restart work I need to apply a fix.

http://www.mscs.dal.ca/~selinger/ups/belkin-universal-ups.html#workaround]

The fix says to add a script to both the startup and shutdown scripts:

Quote:

The intention is that one puts commands such as the following as the last part of the computer's shutdown script:

Code:

# NEAR END OF SHUTDOWN SCRIPT:
# if shutdown was caused by UPS, perform Belkin UPS workaround.
if [ -f /etc/killpower ] ; then
    echo "Waiting for AC power, or for UPS batteries to run out..."
    /usr/bin/belkinunv -x wait /dev/ttyS1

    # we get here if the power came back on. Reboot.
    echo "Power is back. Rebooting..."
    reboot
fi


Quote:

Put this before any disks are mounted read/write, and before any file system integrity checks, so that the system is in a safe state.

Code:

# NEAR BEGINNING OF STARTUP SCRIPT:
# if we are recovering from a power failure, wait for the UPS to
# charge to a comfortable level before writing anything to disk
if [ -f /etc/killpower ] ; then
    echo "Waiting for UPS battery charge to reach 60%..."
    /usr/bin/belkinunv -x wait=60 -x nohang /dev/ttyS1
fi


Would anyone be able to point me in the right direction as to the scripts (and the correct point within them) I should add these to?

Many thanks.

Tanc 12-01-2008 01:55 PM

Hi,

Never done that, but /etc/init.d is the folder where to find startup and shutdown script.
So i would create in root

1. a file in here, name could be belkin
touch belkin
chmod 755 belkin


2. vi belkin then add the following by typing i or use another editor
#!/bin/sh
# belkin

case "$1" in
'start')
# bootup sequence
;;
'stop')
# shutdown sequence
;;
*)
echo "Usage: $0 { start | stop }"
;;
esac
exit 0
3. in Console, run the following
update-rc.d belkin defaults
( put update-rc.d -f belkin remove to remove it )

As i am a novice, it should be validated by a more experienced linux user.
hope it helps.

Pierre

explosive_tom 12-01-2008 09:28 PM

Hi Tanc,

Thanks for the suggestion.
I don't think that is going to work as the startup script needs to be run before the disks go RW and the shutdown after they have been made Read-Only. I think the init.d scripts get run at the wrong time for that?

Tanc 12-02-2008 12:09 AM

Hi Tom,
I will continue to dig, but did you ever had a look at this folder /etc/initramfs-tools/scripts/ ?

Addon
I did create a script named before in /etc/initramfs-tools/scripts/init-premount containing an echo command
chmod a+x
then /usr/sbin/update-initramfs -k all -u

At boot, i can see it before disk are mounted.
Will try to confirm that with logs messages in couple of mn


All times are GMT -5. The time now is 09:33 AM.