Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-02-11
10
Medium Priority
?
626 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 2000 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

772 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