Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Jun 2007 11:42:23 -0400
From:      Jerry McAllister <jerrymc@msu.edu>
To:        gmoniey <gmoniey@gmail.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: startup / shutdown script (rc.d)
Message-ID:  <20070601154223.GC43330@gizmo.acns.msu.edu>
In-Reply-To: <10906324.post@talk.nabble.com>
References:  <10902043.post@talk.nabble.com> <20070601131230.380039e8@localhost> <10906324.post@talk.nabble.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, May 31, 2007 at 09:05:17PM -0700, gmoniey wrote:

> 
> Hi Noberto,
> 
> I actually looked at the apache one, and it seemed so complicated, there
> were 2 files for it, one of which was relatively short and the other was
> significantly long.
> 
> Now dont get me wrong, they aren't beyond comprehension, but i simply dont
> have the time right now to figure them out.
> 
> I dont quite see how something as simple as "apachectl start" is expanded
> into so many lines.

It is because those scripts take in to consideration so many
possible different conditions.   In addition, lines like:

  # PROVIDE: apache22
  # REQUIRE: NETWORKING SERVERS
  # BEFORE: DAEMON
  # KEYWORD: shutdown

Deal with ordering of execution and integrating with other things.
They could be meaningful, but are probably not needed in a simple
routine like you seem to want.

The basic scheme is that the system calls the scripts in rc.d
one at a time.   During startup it calls them with an argument
of 'start'  and when it is shutting down, it calls them with
an argument of 'stop'.   So, all you script has to do is look
for a first argument (past the script name) and check for start
or stop and possibly error if it is anything else.

Presuming you have one routine to run at startup
called  /usr/local/bin/mystartuproutine
and one routine to run at shutdown
called /usr/local/bin/myshutdownroutine
and these two files have execute permission,
then something as simple as this would work.

Put this little script in /usr/local/etc/rc.d/  with
a name something like mystuff.sh and give it execute permission.


#!/bin/sh
case "$1" in
start)
	/usr/local/bin/mystartuproutine
        ;;
stop)
	/usr/local/bin/myshutdownroutine
        ;;
*)
        echo "Usage: `basename $0` {start|stop}" >&2
        exit 64
        ;;
esac


You might want to add some other checks and conditions such
as checking if those files exist and some niceties such as 
making variables of your routine names later.

////jerry

> 
> maybe i will get some time in the near future to understand it...
> 
> 
> Norberto Meijome-2 wrote:
> > 
> > On Thu, 31 May 2007 14:06:45 -0700 (PDT)
> > gmoniey <gmoniey@gmail.com> wrote:
> > 
> >> I was wondering if there is a simple way to create 1 script that will be
> >> called during startup and shutdown. Basically, I am looking for something
> >> like this:
> > 
> > the easiest way (for me) is to grab the rc script of anything that you
> > know
> > well (for example, apache) and modify it for your needs. anyway, at least
> > you
> > can learn from the one that is already made, without having to start from
> > scratch.
> > 
> > B 
> > 
> > _________________________
> > {Beto|Norberto|Numard} Meijome
> > 
> > "People demand freedom of speech to make up for the freedom of thought
> > which
> > they avoid. " Soren Aabye Kierkegaard
> > 
> > I speak for myself, not my employer. Contents may be hot. Slippery when
> > wet.
> > Reading disclaimers makes you go blind. Writing them is worse. You have
> > been
> > Warned.
> > _______________________________________________
> > freebsd-questions@freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> > To unsubscribe, send any mail to
> > "freebsd-questions-unsubscribe@freebsd.org"
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/startup---shutdown-script-%28rc.d%29-tf3848895.html#a10906324
> Sent from the freebsd-questions mailing list archive at Nabble.com.
> 
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070601154223.GC43330>