Solved

AIX - Can you verify my assumption? Create Script for Service (daemon)

Posted on 2014-02-11
10
583 Views
Last Modified: 2014-02-12
Hi All,

This is my understanding to start glassfish4 as a service (or daemon) on AIX

$ vi /etc/rc.d/rc2.d

Enter the following:

#!bin/bash
# description: Glassfish Start Stop Restart
# processname: glassfish
# chkconfig: 234 20 80
export JAVA_HOME=/usr/java71
PATH=$JAVA_HOME/bin:$PATH
export PATH
GLASSFISH_HOME=/u01/oracle/glassfish/glassfish
GLASSFISH_USER=glassfsh

case $1 in
start)
su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
;;
stop)
su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
;;
restart)
su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
su $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
;;
esac
exit 0 

Open in new window


Thank you in advance,
Bill
0
Comment
Question by:bcarlis
  • 5
  • 5
10 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39850339
First, /etc/rc.d/rc2.d is a directory which you can't "edit".

Next, didn't we decide to use "su -" ? Well, you set the PATH in the script so it will most probably work with "su" alone.

Besides that, the script itself looks good. The initial comments which are useful in Linux for "chkconfig" have no meaning in AIX, because there's no "chkconfig" tool - but they will do no harm either.

Don't put the script into rc2.d! The standard setup is to put the script into /etc/rc.d/init.d and to create softlinks to it in /etc/rc.d/rc2.d starting with "Snn" or "Knn".
A link starting with "S" will be executed by AIX with the parameter "start", a link starting with "K" will be executed with the parameter "stop".

The two numbers "nn" after "S" or "K" indicate the priority - links with lower numbers will be started/stopped first.

Please let me know if you need instructions how to move the script to the init.d directory or how to create softlinks - I'll explain.

Note: AIX doesn't have /bin/bash by default. Did you install it? If you didn't - no problem. Change the shebang to "#!/bin/ksh" and it will still work.

N
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39850539
Hi N,

Ok, wouldn't you just
vi /etc/rc.d/init.d

#!/bin/ksh
# description: Glassfish Start Stop Restart
# processname: glassfish
# 
export JAVA_HOME=/usr/java71
PATH=$JAVA_HOME/bin:$PATH
export PATH
GLASSFISH_HOME=/u01/oracle/glassfish/glassfish
GLASSFISH_USER=glassfsh

case $1 in
start)
su - $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
;;
stop)
su - $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
;;
restart)
su - $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1"
su - $GLASSFISH_USER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1"
;;
esac
exit 0

Open in new window


paste the below script into it (i for insert), then save (:wq)

To "create softlinks" - just looked it up.. :)
ln -s S11_Glassfish /etc/rc.d/rc2.d

you may need to explain a bit more on the links?
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39850572
init.d is a directory which cannot be edited.

Run

vi /etc/rc.d/init.d/glassfish

Type "i" for "insert" then paste the script. Type <ESC>:wq!

Then

cd /etc/rc.d/rc2.d
ln -s /etc/rc.d/init.d/glassfish S11glassfish
ln -s /etc/rc.d/init.d/glassfish K11glassfish

A softlink is a directory entry which doesn't indicate a file (inode) but points to another directory entry somewhere else in the filesystem hierarchy. This second entry indicates the "real" file.

We use links here to avoid having the same script twice in rc2.d. This not only saves space but also facilitates future changes which must be made in one place only.

If AIX encounters a link (or script) in rc2.d starting with "Snn" it runs it on system startup with the parameter "start":

/etc/rc.d/rc2.d/Snnxxxxx start

Likewise, if AIX encounters a link (or script) in rc2.d starting with "Knn" it runs it on system shutdown with the parameter "stop":

/etc/rc.d/rc2.d/Knnxxxxx stop

The "2" in "rc2.d" indicates the runlevel.
We only need to put all this into rc2.d because AIX normally uses only this runlevel 2. There is by default no particular runlevel support for e.g. "graphic mode" startup or "no network" startup.
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39850838
Awesome, so to test it
So on reboot of the server it automatically executes

/etc/rc.d/init.d/glassfish K11glassfish stop

/etc/rc.d/init.d/glassfish S11glassfish start

I don't have to do anything else?

I tested it this way:

# /etc/rc.d/init.d/glassfish restart
[YOU HAVE NEW MAIL]
Waiting for the domain to stop .
Command stop-domain executed successfully.
[YOU HAVE NEW MAIL]
Waiting for domain1 to start ........................
Successfully started the domain : domain1
domain  Location: /u01/oracle/glassfish/glassfish/domains/domain1
Log File: /u01/oracle/glassfish/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

and tried to test this way:
/etc/rc.d/init.d/glassfish K11glassfish stop

then I tried the GlassFish Admin - but the admin worked, wasn't stopped
Is the only wat to test it by actually rebooting the server?

Thanks N!
Bill
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 500 total points
ID: 39850889
This is OK:

/etc/rc.d/init.d/glassfish restart

because the "glassfish" script is actually in /etc/rc.d/init.d, and the parameter "restart" is supported.

This is not OK:

/etc/rc.d/init.d/glassfish K11glassfish stop

because the "glassfish" script of course (!) doesn't accept a parameter "K11glassfish".

It should have been:

/etc/rc.d/rc2.d/K11glassfish stop

given you executed the "ln -s" commands as suggested.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 2

Author Comment

by:bcarlis
ID: 39850956
Ohhh I got it.. ya duh,

/etc/rc.d/rc2.d/K11glassfish
is like an alias (link, duh)

to
/etc/rc.d/init.d/glassfish

so
/etc/rc.d/rc2.d/K11glassfish stop
should do it!

and it did:

# /etc/rc.d/rc2.d/K11glassfish stop
[YOU HAVE NEW MAIL]
Waiting for the domain to stop .
Command stop-domain executed successfully.
# /etc/rc.d/rc2.d/S11glassfish start
[YOU HAVE NEW MAIL]
Waiting for domain1 to start ...............
Successfully started the domain : domain1
domain  Location: /u01/oracle/glassfish/glassfish/domains/domain1
Log File: /u01/oracle/glassfish/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

Open in new window

0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39851013
Whoopee! Fine!
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39851066
you are the man! I'll close this.. thx again!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39851083
Thx for the points!

A little side note:

The "K" and "S" prefixes are only for AIX to know which parameter to pass to the script.

So

/etc/rc.d/rc2.d/S11glassfish stop
/etc/rc.d/rc2.d/K11glassfish start

issued from the command line would also work, counter-intuitevely!

N
0
 
LVL 2

Author Comment

by:bcarlis
ID: 39854024
Thanks makes sense now!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now