Solved

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

Posted on 2014-02-11
10
591 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.

770 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