I received several replies to my message to the list regarding
automatic start and stop programs when boot and shutdown the system
(D.U.3.2C). I wish to thank to all the people for responding.
Here are some of the responses:
jean.schuller" <schuller_at_sbgal4.in2p3.fr>:
1) - In /sbin/init.d/ I wrote a script called http :
PATH=/usr/local/etc/httpd:/usr/bin:/sbin
export PATH
case "$1" in
'start')
httpd&
;;
'stop')
pid=`/bin/ps -e | grep httpd | \
sed -e 's/^ *//' -e 's/ .*//' | head -1`
if [ "X$pid" != "X" ]
then
/bin/kill $pid
fi
;;
*)
echo "usage: $0 {start|stop}"
;;
esac
2) - in /sbin/rc2.d, make a link starting with Kxx
K like KILL and xx a free sequence :
ln -s ../init.d/http K85http
3) - in /sbin/rc3.d, make a link starting with Sxx
S like START and xx a free sequence :
ln -s ../init.d/http S85http
PS : - Use the same sequence number : K85 must have a S85.
- Make the right path in /sbin/init.d/http
Lucio Chiappetti <lucio_at_ifctr.mi.cnr.it>:
(a) the script itself shall be placed in /sbin/init.d, and can have
any mnemonic name. For instance mine for httpd is called "httpd"
(b) the script shall accept only a single argument, and this argument
shall either be "start" or "stop"
(c) the script shall be a case statement, which in the two cases of
start and stop executes the commands necessary to do the job
(d) links for the script shall be placed in /sbin/rcx.d, where x can be
2 or 3. Consult Sys Adm manuals. rc2.d is for multiuser
non-networked
daemons, rc3.d for network daemons (at least under DU)
(e) the links shall be two, and have names like
Snnaaaaa
Kmmaaaaa
and point to ../init.d/aaaaa
(the convention of name aaaa is arbitary, the Snn and Knn is not)
(f) at boot there are SCRIPTS called rc2 rc3 etc. Essentially the rcn
script does a "foreach" on directory rcn.d and runs in turn any of
the Snnaaaaa scripts, in the alphanumeric order.
It invokes them as "Snnaaaaa start"
Thus the nn is used to establish the order in which daemon are
started. S99pinco is started after S93pallino. If nn is the same
alphabetic order rules, thus S99panco comes before S99pinco.
(g) at shutdown I believe the script is rc0. It does a foreach for
the Knnaaaa scripts as above, and invokes them as
"Knnaaaaa stop"
(i) for maintenance, you can do it manually, go to /sbin/init.d and
run the ./aaaaa start or ./aaaaa stop command manually.
I'll enclose two examples. One is the precanned httpd script coming with
NCSA
httpd (this is at level 93). The other one is used to start SAMBA (a
daemon
which allows Microsoft machines to see Unix disks), at level 99. In this
case
I did not even put the script in init.d, I left it with SAMBA outside the
system disks and just made the links.
Bernd Scherer <bernd.scherer_at_vt.siemens.de>:
All scripts for boot or shutdown you have to put in the directory
init.d.
In rc3.d you make an softlink to your script in init.d. The name of the
link
indicate the sequence in which the scripts will be started at boot time.
In the directory rc0.d you create the link which will be executed at
shutdown
time.
For example
# cd /sbin/init.d
# => Here is your script to start an stop the httpd
...
case $1 in
'start') httpd
;;
'stop') kill httpd
;;
'*') usage
;;
esac
# cd /sbin/rc3.d
# ln -s ../init.d/httpd S85httpd
# cd /sbin/rc0.d
# ln -s ../init.d/httpd K02httpd
The system starts all scripts in rc3.d beginning with S01xxx and ending
at S99xxx.
It will stop all scripts in rc0.d starting with K01xxx and ending at
K99xx.
The system will handle your script with the right parameter for start
and stop, so you are done with all after you made the tasks shown in the
example.
Ian Mortimer <mortimer_at_physics.uq.edu.au>:
pids=`/bin/ps -e | grep /usr/local1/sbin/sshd | grep -v grep | sed -e 's/^
*//' -e 's/ .*//'`
case $1 in
'start')
echo "Starting Secure Shell Daemon"
[ -n "$pids" ] && kill -9 $pids
/usr/local1/sbin/sshd
/usr/local1/sbin/sshd -p 2022
;;
'stop')
echo "Stopping Secure Shell Daemon"
[ -n "$pids" ] && kill -9 $pids
;;
*)
echo "usage: $0 {start|stop}"
;;
esac
Example for httpd:
PRE Site Manager <star_at_uclan.ac.uk>:
...
PATH=/sbin:/usr/sbin:/usr/bin
export PATH
case "$1" in
'start')
set `who -r`
if [ $9 = "S" ]; then
echo " Starting http Daemon on port 80"
<directory>httpd -d <directory> -f <conf file>
echo " Waiting 10 seconds..."
sleep 10
fi
;;
'stop')
echo " Stopping http daemon..."
kill -9 `cat /home/scratch/httpd/logs/httpd.pid`
;;
*)
echo "usage: $0 {start|stop}"
;;
esac
------------------------------------
...and a link in /sbin/rc3.d:
S97httpd -> ../init.d/httpd
nb you also need a Knnhttpd link in (say) level 1 to kill it off (the
'stop' target).
Example for sshd:
Landkammer Ji" <LandkammerJ_at_Radiomobil.cz>:
...
PATH=$PATH:/usr/local/sbin
export PATH
Pid=`/sbin/init.d/bin/getpid /usr/local/sbin/sshd -uroot`
case "$1" in
'start')
set `who -r`
if [ "X$Pid" = "X" ]
then
if /usr/local/sbin/sshd; then
echo "Sshd server was up .............."
else
echo "Sshd server wasn't up ............."
fi
fi
;;
'stop')
if [ "X$Pid" != "X" ]
then
if /bin/kill $Pid; then
echo "Sshd server was down .............."
else
echo "Sshd server wasn't down .............."
fi
fi
;;
*)
echo "usage: $0 {start|stop}"
;;
esac
\\\___///
\\ - - //
( _at_ _at_ )
-----------------------------oOOo-(_)-oOOo--------------------------------
*Bubulac Angela Tatiana - National Institute for R&D of Materials Physics*
* Bucuresti - Magurele P.O.B. MG-7 *
* Romania *
*e-mail: tatia_at_alpha1.infim.ro | phone :401-7805385 int.1380 *
* root_at_alpha1.infim.ro | 401-7806925 *
* | 401-7804573 *
--------------------------------------Oooo--------------------------------
oooO ( )
( ) ) /
\ ( (_/
\_)
Received on Wed May 27 1998 - 08:18:09 NZST