Boot scripts

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Bill Jonas
Date:  
Subject: Boot scripts
--oocIzbZBDVZKHAzi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Feb 20, 2003 at 12:48:16PM +0000, Aaron Cordova wrote:
> was explained. Does anyone konw of a site that has a dummies guide to=20
> bootscripts? I would really appreciate any links anyone could send me.=20
> Thank you.


I don't know whether or not this is what you're looking for, but there's
a HOWTO on the Linux Documentation Project site that provides a
high-level overview of what happens from the time you hit the power
button to the time you can log in and get a Bash prompt. It's called
"From PowerUp To Bash Prompt" and is at
<http://www.tldp.org/HOWTO/From-PowerUp-To-Bash-Prompt-HOWTO.html>.
Incidentally, the Linux From Scratch project (at
<http://www.linuxfromscratch.org/>) evolved from this.

Or were you looking for information about how to write your own?
Basically, you just need to find out if the command line says "start",
"stop", "restart", "reload", etc., and perform the correct actions based
on that. For example, here's one way to do it (this is a firewall
script that's been edited to show just the basics and commented to help
show what's going on):

----------------------
#!/bin/sh

start ()
{
# All the commands that load modules, set up the firewall rules, and
# do all other necessary actions go here.
}

stop ()
{
# Reset all rules to the default, unload modules, etc.
}

case "$1" in  # $1 is the first argument, as "start" would
              # be in "initscript start"
  start|reload|restart|force-reload) # Multiple possibilities are
                                     # separated by the "|" character.
    stop # It's a good idea to make sure everything's in a known state
         # before applying the firewall rules.  This isn't necessary
         # for regular init scripts.
    start # "stop" and "start" are just the names of the functions
          # defined above, like "functionname () { ... }".
    ;; # End this section of the case statement
  stop) # It's perfectly all right just to have a single possibility
    stop
    ;;
  *) # Catch-all.  In this case, it's anything we didn't understand.
     # Let's print a usage statement...
    echo "Usage: $0 {start|stop|reload|restart}" # $0 is the command name
    exit 1 # ...and exit with an error status.
    ;;
esac  # This ends the block opened above with "case".  Note that this is
      # "case" spelled backwards.  A case statement takes the argument
      # ($1 in this instance) and compares it to as many different
      # things as you want, executing the corresponding commands when it
      # finds a match.
----------------------


I don't know if this helps or not, or if it was at all what you were
looking for. On a Debian system, there's /etc/init.d/skeleton, which is
a barebones init script that demonstrates The Debian Way of Doing Init
Scripts. I don't know whether or not other distributions have anything
similar.

Note that the "start ()" and "stop ()" function names have nothing
sacred about them; I wrote it this way for convenience. I could have
put all the commands in the case statement. You don't even have to use
this format; it could be something like the following:

----------------------
#!/bin/sh

if [ "$1" =3D "start" ]; then
# Do start stuff here
exit 0
fi

if [ "$1" =3D "stop" ]; then
# Do shutting-down stuff here
exit 0
fi

if [ "$1" =3D "reload" ]; then
# Reload the configuration here
exit 0
fi

if [ "$1" =3D "restart" ]; then
# Restart it here
exit 0
fi

# We didn't recognize anything
echo "Usage: $0 {start|stop|reload|restart}"
exit 1
----------------------

=2E..but that's kind of ugly and non-standard. It'll work, though.
Basically, an init script needs to respond to arguments of "start",
"stop", "reload", and "restart". How you decide to do that is,
ultimately, up to you.

HTH.

--=20
Bill Jonas    *        *    http://www.billjonas.com/
"It's a dangerous business, Frodo, going out your front door.  You step
into the Road,  and if you don't keep your feet,  there  is  no knowing
where you might be swept off to."  --  Bilbo Baggins


--oocIzbZBDVZKHAzi
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+VPzRdmHcUxFvDL0RAmsmAKCGoDGM/gdP7zTpxuvp2P2bhyxqCwCfZ1wp
McvKWH21cIeuSP1NknhxOh0=
=ilpW
-----END PGP SIGNATURE-----

--oocIzbZBDVZKHAzi--