Start script or service with boot on AIX 7.2


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Start script or service with boot on AIX 7.2

I have installed apache2, but not run with boot in AIX 7.2, how to make it run ?



in AIX 7.1 i used : mkitab "apache:2:once:/usr/IBMAHS/bin/apachectl start > /dev/null 2>&1" ### ---> not work in AIX 7.2 (i use 0 in once, because appear emoticon when use Smilience)

Moderator's Comments:
Mod Comment Did you know that you can use ICODE-tags (like the ones i entered for you) for short commands to let them stand out? That also takes care of the emoticons.

Last edited by bakunin; 01-10-2019 at 09:34 AM..
# 2  
I haven't used mkitab in a while. Have you looked at /etc/inittab what has really landed there? Because, ultimately, mkitab is only a frontend for editing this file anyway.

Furthermore, i would think that Apache is a high-level application which needs practically the whole system to be up already. Its start might be better placed in an rc-file in /etc/rc.d as the last thing to execute when the run-level is reached. Would that be a viable alternative?

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 3  
Quote:
Originally Posted by bakunin
I haven't used mkitab in a while. Have you looked at /etc/inittab what has really landed there? Because, ultimately, mkitab is only a frontend for editing this file anyway.

Furthermore, i would think that Apache is a high-level application which needs practically the whole system to be up already. Its start might be better placed in an rc-file in /etc/rc.d as the last thing to execute when the run-level is reached. Would that be a viable alternative?

I hope this helps.

bakunin

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 ?
# 4  
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:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
not able to start xvfb service via rc script
chidori
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. ...... Shell Programming and Scripting
2
Shell Programming and Scripting
Q: how to start a service when system start
acerlinux
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...... AIX
4
AIX
Start a service as user
potro
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...... Shell Programming and Scripting
5
Shell Programming and Scripting
Making a Script to Start as a Service
S.Vishwanath
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...... UNIX for Dummies Questions & Answers
3
UNIX for Dummies Questions & Answers
AIX 5.3: Start Service on System startup
dennis.kuehl
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... UNIX for Advanced & Expert Users
1
UNIX for Advanced & Expert Users