Solaris 10 SMF Facility for Hyperic Agent
Introduction
I m running the HQ Agent on solaris 10 for monitoring and I want to start hyperic agent when the system start and I want to do the best practice way. So use the SMF facility to make it possile. I did not see that implementation anywhere on the net. That is the main reason why I want to document it and I know it may be usefull to someone.
Implementation
Create the hyperic-agent.xml file
As root:
vi /var/svc/manifest/network/hyperic-agent.xml
Copy and paste this section:
<?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- SMF for hyperic Agent Author: Koffi Nogbe <knogbe@silverpop.com> Date: 08/27/2007 --> <service_bundle type='manifest' name='hyperic:hyperic-agent'> <service name='network/hyperic-agent' type='service' version='1'> <create_default_instance enabled='false' /> <single_instance /> <dependency name='paths' grouping='require_all' restart_on='error' type='path'> <service_fmri value='file://localhost/opt/hyperic' /> </dependency> <!-- It make no sense to start the agent if report cannot be sent to the server over the network but can be comment out if running server locally. --> <dependency name='network' grouping='require_any' restart_on='error' type='service'> <service_fmri value='svc:/network/service' /> </dependency> <dependent name='hyperic-multi-user' grouping='optional_all' restart_on='none'> <service_fmri value='svc:/milestone/multi-user' /> </dependent> <!-- Start up option/method (start,stop,setup,status/ping) --> <exec_method type='method' name='start' exec='/lib/svc/method/hyperic-agent start' timeout_seconds='-1' /> <exec_method type='method' name='stop' exec=':kill' timeout_seconds='-1' /> <exec_method type='method' name='status' exec='/lib/svc/method/hyperic-agent status' timeout_seconds='-1' /> <exec_method type='method' name='setup' exec='/lib/svc/method/hyperic-agent setup' timeout_seconds='-1' /> <stability value='Unstable' /> <template> <common_name> <loctext xml:lang='C'> Hyperic Monitoring Agent </loctext> </common_name> <documentation> <doc_link name='hyperic.org' uri='http://support.hyperic.com/confluence/display/DOC/HQ+Documentation' /> </documentation> </template> </service> </service_bundle>
Create the hyperic-agent script:
vi /lib/svc/method/hyperic-agent
and copy and paste the below section:
#!/usr/bin/bash
############################################
# Author: Koffi Nogbe
# 08/27/2007
# This is the script supplement for SMF
# Someone can also link the hq-agent script.
############################################
. /lib/svc/share/smf_include.sh
HQ_HOME=/opt/hyperic
HQ_SCRIPT=hq-agent.sh
start() {
# Start HQ Agent daemons
$HQ_HOME/$HQ_SCRIPT start 2> /dev/null
}
stop() {
# Stop HQ Agent daemons
$HQ_HOME/$HQ_SCRIPT stop 2> /dev/null
}
check() {
# Ping HQ Agent
$HQ_HOME/$HQ_SCRIPT ping
}
setup() {
$HQ_HOME/$HQ_SCRIPT setup
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
check
;;
setup)
setup
;;
restart)
stop
sleep 20
start
;;
*)
echo "Usage: $0 {start\|stop\|status\|setup\|restart}"
;;
esac
Set all the permissions
chmod 555 /lib/svc/method/hyperic-agent
chown root:bin /lib/svc/method/hyperic-agent
chmod 444 /var/svc/manifest/network/hyperic-agent
chown root:sys /var/svc/manifest/network/hyperic-agent
Import the service
svccfg import /var/svc/manifest/network/hyperic-agent.xml
Enable the Service
svcadm -v enable hyperic-agent
And voila!