Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start/Stop Scripts in /etc/...? 1

Status
Not open for further replies.

vut

Technical User
Nov 18, 2004
26
0
0
GB
Dear Experts,

I do have a series of scripts that I would like to Start/Stop automaticaly, I need some orientation on where to put them. The start/stop comands are as simples as:

./usr/local/apache/sbin/apache start
./usr/local/apache/sbin/apache stop

Thank you,
vut
 
Solaris stores the start and stop scripts in /etc/init.d (the pool) and hard or softlinks the files to the apropriet runlevel /etc/rc2.d or /etc/rc3.d
I suggest to create a softlink in /etc/init.d
ln -s /usr/local/apache/sbin/apache /etc/init.d/apache
and create a startlink in /etc/rc3.d
ln -s /etc/init.d/apache /etc/rc3.d/S50apache
and a stoplink in rc0.d
ln -s /etc/init.d/apache /etc/rc0.d/K50apache

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years in the domain of the OS, Backup and Storage
 
Hi,

Why soft links? If the start script is deleted, you now have a dead link! I would recommend using hard links. This is also what is taught in sun's admin courses ;-)

-Joe
 
Dear Franz,

Is there another method as my client does not like to use links?
Rgd,
vut
 
Make sure [tt]root[/tt] owns, and is the only one who can edit the startup scripts. Other wise you have a huge security hole. The startup scripts are run by [tt]root[/tt] when the system is entering that run level, so any command in the script gets run as root. If a non-privileged user can add to the script, they can own the machine on the next reboot.

That's why a lot of the scripts in [tt]/etc/init.d[/tt] should use [tt]su - user command[/tt] to run the user supported script at startup.

For example, here's one I use for Oracle...
Code:
# Set ORA_HOME to be equivalent to the ORACLE_HOME from
# which you wish to execute dbstart and dbshut
# Set ORA_OWNER to the user id of the owner of the Oracle
# database in ORA_HOME

ORA_HOME=/oracle/8.1.6/
ORA_OWNER=oracle

if [ ! -f ${ORA_HOME}/bin/dbstart -o ! -d ${ORA_HOME} ]
then
        echo "Oracle startup: cannot $1"
        exit
fi

case "$1" in
'start')
        # Start the Oracle databases:
        echo "Starting Oracle Database"
        /usr/bin/su - ${ORA_OWNER} -c "export ORACLE_HOME=/oracle/8.1.6; ${ORA_HOME}/bin/dbstart ; /usr/bin/sleep 20 ; ${ORA_HOME}/bin/lsnrctl start"
        ;;
'stop')
        # Stop the Oracle databases:
        echo "Shutting Down Oracle Database"
        /usr/bin/su - ${ORA_OWNER} -c "export ORACLE_HOME=/oracle/8.1.6; ${ORA_HOME}/bin/lsnrctl stop ; ${ORA_HOME}/bin/dbshut"
        ;;
*)
        # Invalid parameter
        echo "ERROR: Oracle startup/shutdown error."
        echo "       Unknown parameter given to /etc/init.d/dbora \"$1\""
        ;;
esac

This goes into [tt]/etc/init.d[/tt] and the soft links to start it go into [tt]/etc/rc3.d[/tt]. Also, stop links in the other run levels will make it shut down cleanly when needed.
Code:
ln -s /etc/init.d/oracle /etc/rc0.d/K99oracle
ln -s /etc/init.d/oracle /etc/rc1.d/K99oracle
ln -s /etc/init.d/oracle /etc/rc2.d/K99oracle
ln -s /etc/init.d/oracle /etc/rcS.d/K99oracle
ln -s /etc/init.d/oracle /etc/rc3.d/S99oracle
That way the DBA can edit the actualy Oracle startup script because it runs as the user [tt]oracle[/tt] on startup.

Hope this helps.
 
dear vut,

as the others pointed out: ether copy the script to /etc/rc?.d Directories or use a wrapper linke Sam point's out.

@Joe

well softlinks work on the whole machine, hardlinks just work in the same filesystem and you can't hardlink a softlink but softlink a softlink. It's a matter of taste and I like softlinks... ;)


Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years in the domain of the OS, Backup and Storage
 
@franz

You most certainly can hardlink a softlink, you could also softlink to a hardlinked soft link but, why would you want to do that. Although it is true that you can only hardlink in the same FS, we're talking about linking from /etc/init.d to the rc.* directories, these directories are, or should be, in the same FS.

-Joe :)
 
@Joe

yes, you can hardlink a softlink, but the result is not, what you expected! ;-)

Code:
root@pepe:~/linktest: echo Hello world\! > file
root@pepe:~/linktest: ls -al
total 6
drwxr-xr-x   2 root     other        512 Aug 10 13:13 .
drwxr-xr-x  12 root     other        512 Aug 10 13:08 ..
-rw-r--r--   1 root     other         13 Aug 10 13:13 file
root@pepe:~/linktest: ln -s file softlink
root@pepe:~/linktest: ln file hardlink
root@pepe:~/linktest: ln -s softlink softlinkthesoftlink
root@pepe:~/linktest: ln -s hardlink softlinkthehardlink
root@pepe:~/linktest: ln hardlink hardlinkthehardlink
root@pepe:~/linktest: ln softlink hardlinkthesoftlink
root@pepe:~/linktest: ls -al
total 18
drwxr-xr-x   2 root     other        512 Aug 10 13:14 .
drwxr-xr-x  12 root     other        512 Aug 10 13:08 ..
-rw-r--r--   3 root     other         13 Aug 10 13:13 file
-rw-r--r--   3 root     other         13 Aug 10 13:13 hardlink
-rw-r--r--   3 root     other         13 Aug 10 13:13 hardlinkthehardlink
[b]lrwxrwxrwx   2 root     other          4 Aug 10 13:13 hardlinkthesoftlink -> file[/b]
lrwxrwxrwx   2 root     other          4 Aug 10 13:13 softlink -> file
lrwxrwxrwx   1 root     other          8 Aug 10 13:14 softlinkthehardlink -> hardlink
lrwxrwxrwx   1 root     other          8 Aug 10 13:14 softlinkthesoftlink -> softlink
root@pepe:~/linktest:

anyway, it's more or less a matter of taste; I prefere the softlink since you can see where it point's to. With a hardlink you have to use "find . -inum" to show you where the other copies are. They both have their pros and conts.

Best Regards, Franz
--
Solaris System Manager from Munich, Germany
I used to work for Sun Microsystems Support (EMEA) for 5 years in the domain of the OS, Backup and Storage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top