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 :once)

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

1 Like

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):

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.

/etc/rc.d/rc2.d

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:

#! /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

1 Like

Thanks you ! This resolve my issue. Thanks again !