How To Start The Hyperic HQ Server And Agent Service At Startup With Linux
Before We Begin
This tutorial assumes that you already have Hyperic HQ software unpacked and installed on your system. Further, it assumes that you created a user named "hyperic" to install the software. If you used a different user, you'll need to edit the script below and change the "hyperic" user to the name of the user you used to do the install.
The tutorial is broken up into two parts. The first works with the Hyperic HQ Server, and the second works with the Hyperic agent.
Starting the Hyperic HQ Server Automatically
Create a new file: /etc/init.d/hq-server
The contents should be as follows. Replace the DAEMON path with the path Hyperic is installed on your system. However, it needs to point to the bin subdirectory, with $NAME.sh at the end as shown:
#! /bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Hyperic HQ Server"
NAME=hq-server
DAEMON=/home/hyperic/server/bin/$NAME.sh
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
case "$1" in
start)
sudo -u hyperic -H -s $DAEMON start
;;
stop)
sudo -u hyperic -H -s $DAEMON stop
;;
restart|force-reload)
sudo -u hyperic -H -s $DAEMON stop
sudo -u hyperic -H -s $DAEMON start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
Make the script executable by issuing the following command:
chmod +x /etc/init.d/hq-server
Now we'll create a second small script. This one will copy the first script into the various directories needed to start the service at boot for the different run levels in Linux. Created the links could be done manually as well, but this is faster and easier, especially if you'll be doing this for multiple computers. Create a new script.sh file containing the following:
#! /bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
#Make sure the script in init.d is executable
chmod +x /etc/init.d/hq-server
#Create links to the script for each runlevel
cd /etc/rc0.d
ln -s ../init.d/hq-agent K01hq-server
cd ../rc1.d
ln -s ../init.d/hq-agent K01hq-server
cd ../rc2.d
ln -s ../init.d/hq-agent S99hq-server
cd ../rc3.d
ln -s ../init.d/hq-agent S99hq-server
cd ../rc4.d
ln -s ../init.d/hq-agent S99hq-server
cd ../rc5.d
ln -s ../init.d/hq-agent S99hq-server
cd ../rc6.d
ln -s ../init.d/hq-agent K01hq-server
Now make this second script executable and run it. Congratulations, Your Hyperic Server will now start automatically when you power on your Linux server!
Starting the Hyperic Agent Automatically
Create a new file: /etc/init.d/hq-agent
The contents should be as follows. Replace the DAEMON path with the path Hyperic is installed on your system. However, it needs to point to the bin subdirectory, with $NAME.sh at the end as shown:
#! /bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Hyperic HQ Agent"
NAME=hq-agent
DAEMON=/home/hyperic/agent/bin/$NAME.sh
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
case "$1" in
start)
sudo -u hyperic -H -s $DAEMON start
;;
stop)
sudo -u hyperic -H -s $DAEMON stop
;;
restart|force-reload)
sudo -u hyperic -H -s $DAEMON stop
sudo -u hyperic -H -s $DAEMON start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
Make the script executable by issuing the following command:
chmod +x /etc/init.d/hq-server
Now we'll create a second small script. This one will copy the first script into the various directories needed to start the service at boot for the different run levels in Linux. Created the links could be done manually as well, but this is faster and easier, especially if you'll be doing this for multiple computers. Create a new script.sh file containing the following:
#! /bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
#Make sure the script in init.d is executable
chmod +x /etc/init.d/hq-agent
#Create links to the script for each runlevel
cd /etc/rc0.d
ln -s ../init.d/hq-agent K01hq-agent
cd ../rc1.d
ln -s ../init.d/hq-agent K01hq-agent
cd ../rc2.d
ln -s ../init.d/hq-agent S99hq-agent
cd ../rc3.d
ln -s ../init.d/hq-agent S99hq-agent
cd ../rc4.d
ln -s ../init.d/hq-agent S99hq-agent
cd ../rc5.d
ln -s ../init.d/hq-agent S99hq-agent
cd ../rc6.d
ln -s ../init.d/hq-agent K01hq-agent
Now make this second script executable and run it. Congratulations, Your Hyperic Agent will now start automatically when you power on your Linux server! As you can see, the process really is the same for both the server and agent components. Likewise, this same method can be used to start many other services automatically in Linux.