Sean's i/o Stream

Musings-as-a-Service

Making your UrbanCode services run automatically on Linux

  • June 08, 2015
  •   category: ibm
  • tags: urbancode, linux

Getting UrbanCode products installed on your Linux machines is a pretty straight forward task, one thing that is easy to forget to is to make those services run automatically. This post takes you through the steps needed to make the services automatically start as your infrastructure is restarted.

Once you have installed UrbanCode Deploy Agent/Agent Relay/Server or Build Server/Agent you can easily start the services by executing the <install>/bin/<service> start command. To make the process simpler the products come installed with a basic init.d script to start with, depending on your setup, OS, and product they vary slightly so I will just outline the basic procedure and you can fill in the blanks.

First look for the init.d scripts:

sgwilbur@ucd01:/opt/ibm-ucd$ grep '^SERVER_' server/bin/init/server
SERVER_PROG=`echo $prog | sed -s s/ˆ[SK][0-9][0-9]//`
SERVER_HOME="/opt/ibm-ucd/server"
SERVER_USER=@SERVER_USER@
SERVER_GROUP=@SERVER_GROUP@

sgwilbur@ucd01:/opt/ibm-ucd$ grep '^AGENT_' agent/bin/init/agent
AGENT_HOME="/opt/ibm-ucd/agent"
AGENT_USER=
AGENT_GROUP=

sgwilbur@ar01:/opt/ibm-ucd$ grep '^AGENT' agentrelay/bin/init/agentrelay
AGENT_RELAY_HOME="/opt/ibm-ucd/agentrelay"
AGENTRELAY_USER=
AGENTRELAY_GROUP=

We need to ensure that the *_USER and *_GROUP variables are set, here is a simple example to just run as root for testing.

sgwilbur@ucd01:/opt/ibm-ucd$ grep '^SERVER_' server/bin/init/server
SERVER_PROG=`echo $prog | sed -s s/ˆ[SK][0-9][0-9]//`
SERVER_HOME="/opt/ibm-ucd/server"
SERVER_USER=root
SERVER_GROUP=root

sgwilbur@ucd01:/opt/ibm-ucd$ grep '^AGENT_' agent/bin/init/agent
AGENT_HOME="/opt/ibm-ucd/agent"
AGENT_USER=root
AGENT_GROUP=root

sgwilbur@ar01:/opt/ibm-ucd$ grep '^AGENT' agentrelay/bin/init/agentrelay
AGENT_RELAY_HOME="/opt/ibm-ucd/agentrelay"
AGENTRELAY_USER=agentrelay
AGENTRELAY_GROUP=agentrelay

The second step is to symlink the relevant startup script to /etc/init.d, again a straight-forward process and here is when we pick the desired service_name to use below.

sgwilbur@ucd01:~$ sudo ln -sf /opt/ibm-ucd/server/bin/init/server /etc/init.d/ibm-ucd-server
[sudo] password for sgwilbur:
sgwilbur@ucd01:~$ sudo ln -sf /opt/ibm-ucd/agent/bin/init/agent /etc/init.d/ibm-ucd-agent
sgwilbur@ucd01:~$ ls -als /etc/init.d/ibm*
0 lrwxrwxrwx 1 root root 33 Jun  5 16:00 /etc/init.d/ibm-ucd-agent -> /opt/ibm-ucd/agent/bin/init/agent
0 lrwxrwxrwx 1 root root 35 Jun  5 15:59 /etc/init.d/ibm-ucd-server -> /opt/ibm-ucd/server/bin/init/server

Then add it to the default run levels so it starts up automatically.

On RHEL-like systems:

chkconfig --add <service_name>

On Debian-like systems:

update-rc.d <service_name> defaults

For example:

sgwilbur@mysql01:/opt/ibm-ucd$ sudo update-rc.d ibm-ucd-agent defaults
 Adding system startup for /etc/init.d/ibm-ucd-agent ...
   /etc/rc0.d/K20ibm-ucd-agent -> ../init.d/ibm-ucd-agent
   /etc/rc1.d/K20ibm-ucd-agent -> ../init.d/ibm-ucd-agent
   /etc/rc6.d/K20ibm-ucd-agent -> ../init.d/ibm-ucd-agent
   /etc/rc2.d/S20ibm-ucd-agent -> ../init.d/ibm-ucd-agent
   /etc/rc3.d/S20ibm-ucd-agent -> ../init.d/ibm-ucd-agent
   /etc/rc4.d/S20ibm-ucd-agent -> ../init.d/ibm-ucd-agent
   /etc/rc5.d/S20ibm-ucd-agent -> ../init.d/ibm-ucd-agent

And you can verify it is working as expected:

sgwilbur@ucd01:~$ ps aux|grep agent
sgwilbur 28946  0.0  0.0  10460   936 pts/0    S+   16:27   0:00 grep --color=auto agent
sgwilbur@ucd01:~$ sudo service ibm-ucd-agent start
Starting ibm-ucdagent:
sgwilbur@ucd01:~$ ps aux|grep agent
root     28957 14.0  1.4 2021120 29308 pts/0   Sl   16:27   0:00 /usr/lib/jvm/default-java/bin/java -Dfile.encoding=UTF-8 -jar /opt/ibm-ucd/agent/monitor/air-monitor.jar /opt/ibm-ucd/agent /opt/ibm-ucd/agent/bin/worker-args.conf 7000
root     28971 84.5  3.0 1543512 62772 pts/0   Sl   16:27   0:01 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java -Dcom.urbancode.air.mw.common.Monitor.port=35585 -Xmx256m -Dfile.encoding=UTF-8 -Dconsole.encoding=UTF-8 -Djava.io.tmpdir=/opt/ibm-ucd/agent/var/temp -Djava.security.properties=/opt/ibm-ucd/agent/conf/agent/java.security -jar /opt/ibm-ucd/agent/monitor/air-worker.jar /opt/ibm-ucd/agent/bin/classpath.conf 5000 com.urbancode.air.agent.AgentWorker
sgwilbur 28991  0.0  0.0  10460   932 pts/0    S+   16:27   0:00 grep --color=auto agent
sgwilbur@ucd01:~$ sudo service ibm-ucd-agent stop
Stopping ibm-ucdagent:
sgwilbur@ucd01:~$ ps aux|grep agent
sgwilbur 29013  0.0  0.0  10460   936 pts/0    S+   16:27   0:00 grep --color=auto agent

The only missing behavior is the lack of the status command which you can add with a very similar command to what I used above. If you don’t care, you are done :) If you need status for monitoring or some other purpose you need to get into the init.d scripts and start hacking them up.

Modifying the default scripts is less than ideal as the manual script and init scripts vary, the agent and agentrelay scripts vary, and variable use and naming vary. So in order to avoid the issue of supporting and making changes to two or three different script styles across your machines, I would just recommend creating your own generic init.d script in a consistent fashion that can that makes sense for your purposes and organization. I have some sample patch files for the defaults scripts that I’ll host on github and link here when I get them squared away with my Ansible playbooks, that are meant to specifically help streamline this type of maintenance effort.

Reference:
Back to Top