Sponsored Content
Operating Systems AIX Start script or service with boot on AIX 7.2 Post 303028568 by bakunin on Thursday 10th of January 2019 12:54:53 PM
Old 01-10-2019
Quote:
Originally Posted by penchev
Yes that will be possible alternative. Please explain me or example me... file from /etc/rc.d/ how will looked one startup file /etc/rc.d/apache2.sh ?
OK, a little general UNIX knowledge: UNIX systems work in "runlevels". A runlevel is a set of certain started (or, respectively, running) services. For instance, there might be a runlevel with the system up in general but no network services started. Here are some commands to manage runlevels (be EXTREMELY CAREFUL and test only on "play" machines which nobody really needs):

Code:
telinit <runlevel>       # switch to a certain runlevel
init <runlevel>          # same as telinit
cat /etc/.init.state     # display the runlevel currently active
fwtmp | grep run-level   # display the history of run-levels active

When a switches from one runlevel to another it kills all processes assigned to the old runlevel, then starts all processes assigned to the new runlevel. This is done by executing "Start-Stop-Scripts" which are generally in the /etc/rc.d hierarchy. There is a directory associated with each runlevel, i.e. [icode]/etc/rc.d/rc2.d[/code] is for runlevel 2 (the one you are most likely in right now, it is the default runlevel).

There is a program /etc/rc.d/rc that will run these start/stop-scripts for the respective runlevel and in the following way:

All the scripts starting with "S" (for start) are executed when the runlevel is entered. Since the scripts are executed sorted in alphabetic order they are usually named "SNNname" "where NN is a two-digit number, i.e. "S22sshd" might start the ssh-daemon. First S00* is started, then S01* and so on, until S99*. This way you have control when processes depend on each other.

In the same way all the scripts named "K" (for kill) are executed to stop the processes when leaving the runlevel but in reverse alphabetic order. Hence, K99*. is executed first, then K98* and so on until K00* is reached. It makes sense to name the respective scripts with the same numner, so if you have "S22shd" you should also have "K22shd".

There is a (informally adhered to) quasi-standard about which runlevel does (or, rather, should do) what:

0 (sometimes S): single-user mode/maintenance mode
2: normal operation without graphical login and no X11-server running
3: normal operation with graphical log-in (i.e. a started X11 with CDE or something such)
6: reboot - kills all processes, then restarts the machine

So far, this is true for all UNIX- and Linux-systems. Now for the specific AIX-part:

Runlevels in AIX can be "0"-"9", "a", "b" and "c". 0 and 1 are reserved for future use, 2 is the default run level, 3-9 are user-definable. a,b and c can also be defined but init will not kill the processes of the previous runlevel but instead only start the assigned processes.

How to write Start- or Kill-scripts: there is a (also informally adhered to) standard for such scripts. Usually, as they could well be used in several runlevels, it pays to write a script (a so-called "rc-script") that does the work and in the S- and K-scripts you only call this. An rc-script should know 3(4) parameters:

"start"
"stop"
"restart"|"reload"

Where "start" starts the process, "stop" stops the process and "restart" or "reload" stops the running process, then starts it again (you need that for some programs to re-read their configuration when it changes). A general rc-script looks like this:

Code:
#! /bin/ksh

start ()
{
<all commands to start the software>
}

stop ()
{
<all commands to stop the software>
}


case "$1" in
     "start")
          start
          ;;

     "stop")
          stop
          ;;

     "reload"|"restart")
          stop
          sleep 1
          start
          ;;

esac
exit 0

Notice, however (this might have been a reason why your mkitab command failed in first place, but i had that idea just yet), that you might have to switch users somewhere because Apache is not to be started as root and all this runlevel-switching and inittab-processing is done as root.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

AIX 5.3: Start Service on System startup

Hi, I'm new to AIX, and have to make some services start at system startup. The IBM-Redbook says I have to edit /etc/inittab. As a long time (Debian)-Linux Admin I'm a bit confused. Is there something like /etc/init.d/$SERVICE in AIX? Greetings, Dennis (1 Reply)
Discussion started by: dennis.kuehl
1 Replies

2. UNIX for Dummies Questions & Answers

Making a Script to Start as a Service

Hi, I have a shell script t1.sh. on my solaris box. So, what are the steps required to make this script run as a Service, when the system re-starts. (for ex:- at run level 3). I know that I should use the rc.d folders. But I don't know the exact steps. Kindly explain, Thanks in... (3 Replies)
Discussion started by: S.Vishwanath
3 Replies

3. Shell Programming and Scripting

Start a service as user

Hi I need a service to be start as user after a reboot. My script in /etc/init.d contain the following: start() { su - $USER cd ${INSTALL_PATH}/bin ./MyApp -X exit return 0 } This function stops after su - $USER, I get user shell, and only if I manualy... (5 Replies)
Discussion started by: potro
5 Replies

4. Solaris

StartUP file to start a service

Hi guys: i have a Solaris 10 development server and a Solaris 9 production server. The entire task must be done in the dev. server. When it's done and all the testing is OK, the script or files are transfer to prod. Server. All right. Now I have to figure out a way to put a script to initiate... (2 Replies)
Discussion started by: bmathiasf
2 Replies

5. AIX

Q: how to start a service when system start

As topic, assume we have a service called "blahservice" and we can start it by: startsrc -s blahservice what is the best practice to run such command when system start? - directly use mkitab to add it into /etc/inittab or - drop startup scripts in /etc/rc.d/rcX.d I know they... (4 Replies)
Discussion started by: acerlinux
4 Replies

6. Red Hat

vsftpd service failed to start

hi, i am using RHEL 5 and i am not able to on the vsftp i have tried to on the vsftp service using command service vsftpd start Starting vsftpd for vsftpd: i am posting the content of my /etc/xinetd.d/vsftpd file # description: The vsftpd FTP... (2 Replies)
Discussion started by: u.n.i.x
2 Replies

7. Red Hat

Can't start NTOP service/daemon

I have installed version of ntop 4.0.3 by guide. But I can't start ntop daemon/service. I didn't find a service file for starting. During the installation there was no problem only want to RRDTool so I installed that. Now there is no necessary package required. I didn't find in /etc/init.d/... (9 Replies)
Discussion started by: getrue
9 Replies

8. Ubuntu

start service when get login prompt

Hi Team, I am using DRBL environment on Ubuntu. When my machine starts some times it's not starting lxdm & nslcd service. Because of that i didn't get graphic mode & also not able to authenticate user as nslcd is also stops. I have to login as root and restart these two services, then i am able... (0 Replies)
Discussion started by: paragnehete
0 Replies

9. Shell Programming and Scripting

not able to start xvfb service via rc script

Hi , I am having this start script to start xvfb under rc3.d but it fails during system startup saying unable to open display. also manually if i try to execute the script , it does not work. But if i execute what ever is there in the script line by line on my SHELL , it starts well. ... (2 Replies)
Discussion started by: chidori
2 Replies

10. Solaris

Not able to start cron service in Solaris 10

Hi, This is Solaris-10 x86. I am not able to start cron service, configured in FMRI. It is in maintenance and when I clear it, it seems like calling and failing on /etc/init.d/tcs-rtm script. I am not able to figure out, why cron is calling that script, if this failure is because of that. Cron... (5 Replies)
Discussion started by: ron323232
5 Replies
All times are GMT -4. The time now is 02:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy