SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2011-08-07 13:19:50

xaos52
The Good Doctor
From: Planet of the @s
Registered: 2011-06-24
Posts: 4,595

Howto run local scripts on systemstartup and/or shutdown.

1. Replace /etc/init.d/rc.local with this script:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          rc.local
# Required-Start:    $local_fs $bootlog
# Required-Stop:     
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Run /etc/rc.local if it exist
# Description:       This script executes commands in /etc/rc.local 
#                    at startup, if /etc/rc.local exists and 
#                    executes /etc/rc.local.shutdown when the
#                    system goes down for shutdown or reboot.
### END INIT INFO


PATH=/sbin:/usr/sbin:/bin:/usr/bin

. /lib/init/vars.sh
. /lib/lsb/init-functions

do_start() {
    if [ -x /etc/rc.local.startup ]; then
            [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
        /etc/rc.local.startup
        ES=$?
        [ "$VERBOSE" != no ] && log_end_msg $ES
        return $ES
    fi
}
do_stop() {
    if [ -x /etc/rc.local.shutdown ]; then
            [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
        /etc/rc.local.shutdown
        ES=$?
        [ "$VERBOSE" != no ] && log_end_msg $ES
        return $ES
    fi
}

case "$1" in
    start)
    do_start
        ;;
    restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
    stop)
    do_stop
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

2. Install this script in /etc/rc.local.startup:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

3. Install this script in /etc/rc.local.shutdown:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at shutdown (rc0) and reboot (rc6) with argument "stop".
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

4. Make both scripts executable:

sudo chmod +x /etc/rc.local.startup
sudo chmod +x /etc/rc.local.shutdown

5. Remove existing links to /etc/init.d/rc.local for all runlevels:

sudo /usr/sbin/update-rc.d -f rc.local remove

6. add new links to /etc/init.d/rc.local for the necessary runlevels:

sudo /usr/sbin/update-rc.d rc.local defaults

7. Check your runlevels:

sudo find /etc/rc?.d -iname '*local'

The output should give you something like this:

/etc/rc0.d/K01rc.local
/etc/rc6.d/K01rc.local
/etc/rcS.d/S15rc.local

There should be 3 entries. The third entry may be different for you. It depends on the services you want at startup. S15 might give you another number, but thats OK.

Now if you want commands executed at startup, add them to /etc/rc.local.startup, before the line 'exit 0'.
If you want commands executed at shutdown, add then to /etc/rc.local.shutdown, before the 'exit 0' line.
Thats it!
Enjoy

Last edited by xaos52 (2011-08-07 13:31:26)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo