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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

where to put script to start application up when linux box starts up 3

Status
Not open for further replies.

hok1man

Technical User
Feb 16, 2008
102
Hi Guys,

I have a script that needs to be run once the linux box starts up, but I'm not 100% sure how to implement this.

This is what I know.
my scripts called : controlApps.ksh

but to call it.. I need to put parameter "start", because this script can be use to start and stop application.

so to trigger it: we need to call
controlApps.ksh start

my OS is
Red Hat Enterprise Linux AS release 4 (Nahant Update 4)

I used to know that all startup scripts needs to be put in directory /etc/init.d, is it correct?

how do I check what scripts that run and the sequence as well (if possible) once the box starts up?

Appreciate for your help guys...

Cheers,

 
If you want to be really neat, the best way is to make the script chkconfig aware. This makes it really easy to enable and disable services and install and remove the startup links.

If you look at an existing service startup script in /etc/init.d you should see somewhere near the top:

Code:
# chkconfig: 2345 55 25
# description: OpenSSH server daemon

As you can guess this example is from /etc/init.d/sshd. This means that the SSH service runs in runlevels 2, 3, 4 and 5, and it is started at sequence 55 (mid-way through the boot process), and stopped at sequence 25 (quite early in the shut-down process). For a user defined service you would typically use "345 99 00", i.e. it starts up right at the end, and is one of the first things shut down.

Once you have copied your script into /etc/init.d and added the above information, changing the description appropriately, you can chkconfig --add controlApps.ksh. It should now appear in chkconfig --list, and you should see some new symbolic links have been created if you run ls -l /etc/rc?.d/*controlApps.ksh.

Typically Linux systems boot into runlevel 5 by default, which means all services including X-windows. Servers are frequently configured to boot to runlevel 3, which is multi-user but without X. You can check which one yours is configured for by examining the "initdefault" line in /etc/inittab. You can check your current runlevel by using the who -r or runlevel commands. See man init for more info.

Annihilannic.
 
wow..

what an explanation..
have a star..

but I still got couple question about this Anni,

1.) Do I just need to put one level for myscript? if I checked via who -r or runlevel, I can see I am on run-level 3 (only one level) but I checked other applications/system they all multiple level

ie :
BigBrother:# chkconfig: 2345 55 25
IBtechOpenSSH:# chkconfig: 2345 55 25
acpid:# chkconfig: 345 44 56

here's my initdefault :
bash-3.00$ grep initdefault /etc/inittab
# 0 - halt (Do NOT set initdefault to this)
# 6 - reboot (Do NOT set initdefault to this)
id:3:initdefault:

so, I guess I just need to put 3 and 5 in the chkconfig, what do you suggestion?

Thanks,
 
Correct, you only *need* to put one runlevel, but I would just use 3, 4 and 5 as is most common. I have never booted to runlevel 4, nor seen anyone else use it; I can't even remember what it is, but no harm in having it there too.

The way Linux startup scripts work there is no harm or impact of having your service configured to start or stop in multiple runlevels. In other Unix-like operating systems it does matter, because they don't go directly from S (single-user) to 3 (as per your initdefault), but rather ascend through the runlevels starting services at each level. It can be pretty confusing, but of course you don't have to worry about that. :)

Annihilannic.
 
I saw so many apps running on
# chkconfig: 2345 55 25

is it some kind a default way?

I was thinking it could be make the startup process and shutdown process slower, wouldn't it?

what's the best way to put the number of the sequence?
 
Hi Anni,

just wondering once the box starts up and trigger my script, who's the unix will login as ?

I assume is root, am I right?
or is there any automated sudo/suexec something like that?

because in my script, I validate who's going to trigger this script only "appslogin"

and my script has parameter, because this script is able to stop and start.
[script] start

how do we enter the parameter?
or should I create another script calling this script by saying [script] start?

Thanks man,

never done this before..
 
All SNNxxxx startup scripts are called with one parameter, "start", so you are already covered there.

Yes, you guessed correctly, they are all run as root. So if the service is supposed to run as some other user, e.g. appuser they should contain something like:

Code:
su - appuser -c '
     # startup commands go here
'

Annihilannic.
 
All SNNxxxx startup scripts are called with one parameter, "start"

questions :
what SNNxxxx means?
 
I'm just referring to the startup scripts that you'll find in /etc/rc?.d, e.g. S90crond or S99controlApps.ksh.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top