Thursday, September 13, 2012

Starting and stopping WebLogic automatically using Upstart

I've been using Unix and Linux a while. Like a while while. So long ago that the first time I installed Linux it was by floppy disk. I'm not telling you that to brag, or imply that I'm old. I say that to give you a sense of how exciting this change is for and old hat.

In the olden days when you wanted to start a program when the machine booted there were a bunch of options. You could put it in /etc/inittab and let init handle it for you; but there were a bunch of problems with that. In recent vintages of Linux we have Sys-V (pronounced System Five) style init scripts where you'd write a shell script that took a command line option "start" or "stop" and started or stopped the service, then put that script in /etc/rc3.d with a name like S99myservice. Or better yet you'd tuck it into /etc/init.d and then symlink it to the right name in /etc/rc3.d (for example). If you were reasonably smart you'd put a "chkconfig" stanza at the top and let chkconfig do the symlinking for you. You still needed to write that script which basically meant a bunch of copy/pasting the same thing over and over. And you needed to make sure the process ran "in the background" which lead to lots of people using the "&" in really awful ways that made me feel dirty to see.

But I'm here to tell you that while that's all well and good, and you can still do that if you want under Oracle or RedHat Linux 6 you no longer have to.

In Ubuntu, RedHat and Oracle Linux there's a new flavor of init called Upstart that all the kids are using and it's the new hotness when it comes to making programs into daemons and wiring them to start and stop at appropriate times.

After using it for a little bit I think I might be in love. It is a pleasure to use compared to the (now) old way.

Say you want to start Node Manager every time the machine boots. To do that you just create a file named /etc/init/nodemanager.conf and put this in it the /etc/init directory.

start on runlevel [345]
exec /bin/su - oracle -- /home/oracle/Oracle/Middleware/wlserver_10.3/server/bin/startNodeManager.sh
Substitute oracle for whichever user you run the stuff as and adjust the path as needed for your particular environment.

Want to start the OAM Admin and Managed servers on boot?



Create a file named /etc/init/oamadminserver.conf:

start on runlevel [345]
exec /bin/su - oracle -- /home/oracle/Oracle/Middleware/user_projects/domains/OAMDomain/bin/startWebLogic.sh
And /etc/init/oamserver1.conf:
start on runlevel [345]
exec /bin/su - oracle -- /home/oracle/Oracle/Middleware/user_projects/domains/OAMDomain/bin/startManagedWebLogic.sh oam_server1

Reboot the machine and the OAM AdminServer and the Managed Server will come up automatically.


If you want to start, check the status of, or stop the service? It's super simple:

[root@r2d2 init]# start oamserver1
oamserver1 start/running, process 5573
[root@r2d2 init]# status oamserver1
oamserver1 start/running, process 5573
[root@r2d2 init]# stop oamserver1
oamserver1 stop/waiting
And this is just scratching the surface of what you can do with Upstart.

You've got to try it out!

2 comments:

  1. Thanks. This exec statement didn't quite work for me. In Ubuntu 12.10, I had to use:

    env MW_HOME=/usr/Oracle/Middleware

    exec start-stop-daemon --start -u oracle -c oracle:oracle --exec $MW_HOME/user_projects/domains/base_domain/bin/startWebLogic.sh

    where the MW_HOME, the domain, and the user:group may vary for others.

    ReplyDelete
  2. I don't know if Ubuntu is technically supported but thanks for the suggestion!

    ReplyDelete

Note: Only a member of this blog may post a comment.