Start script or service with boot on AIX 7.2

Tags
aix, script, service, solved, start

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
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; 1 Week Ago at 10:34 AM..
# 2  
Old 1 Week Ago
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:
Neo (5 Days Ago)
# 3  
Old 1 Week Ago
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  
Old 1 Week Ago
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:
Neo (6 Days Ago)
# 5  
Old 6 Days Ago
Thanks you ! This resolve my issue. Thanks again !

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

More UNIX and Linux Forum Topics You Might Find Helpful
Cannot get sma (net-snmp) service to start. Zeus18 Solaris 4 02-07-2017 03:05 PM
How to make SMF service start last? JWH Solaris 6 04-17-2013 04:16 AM
not able to start xvfb service via rc script chidori Shell Programming and Scripting 2 09-30-2012 05:12 PM
start service when get login prompt paragnehete Ubuntu 0 12-15-2011 05:08 AM
Can't start NTOP service/daemon getrue Red Hat 9 06-28-2011 10:01 AM
named service will not start, connection refused wbdevilliers Linux 1 06-09-2010 11:23 AM
VSFTPD Service Failed to Start PaulComins Red Hat 4 05-26-2010 11:11 AM
vsftpd service failed to start u.n.i.x Red Hat 2 02-01-2010 12:19 AM
could not able to start the ssh service plz suggest girish.batra Solaris 1 05-28-2009 04:45 AM
Q: how to start a service when system start acerlinux AIX 4 04-03-2009 10:37 PM
StartUP file to start a service bmathiasf Solaris 2 01-29-2009 12:03 PM
MySQL service start error saravanakumar Programming 4 09-11-2008 02:41 PM
Start a service as user potro Shell Programming and Scripting 5 04-17-2008 03:19 AM
Making a Script to Start as a Service S.Vishwanath UNIX for Dummies Questions & Answers 3 02-08-2007 01:37 AM
AIX 5.3: Start Service on System startup dennis.kuehl UNIX for Advanced & Expert Users 1 07-25-2006 04:32 AM