Install Hostmonitor RMA on Ubuntu 12.04
Posted: Fri Sep 20, 2013 9:23 am
Get RMA files
Copy RMA files to appropriate location
Edit Agent ini file
Create startup script
Edit startup script
Make the script executable
Add the script to the boot sequence
Start installed agent
Code: Select all
#
mkdir -p /usr/local/src/rma
cd /usr/local/src/rma
#
wget http://www.hostmonitor.biz/download/rma/rma129_lin_x64.tgz
#
tar -xzf rma129_lin_x64.tgz
#
Code: Select all
#
mkdir /usr/local/etc/rma
mkdir /usr/local/etc/rma/docs
#
#
cp rma /usr/bin
#
cp rma.ini /usr/local/etc/rma
#
cp cpu.sh /usr/local/etc/rma
cp proccnt.sh /usr/local/etc/rma
cp proclist.sh /usr/local/etc/rma
#
cp INSTALL /usr/local/etc/rma/docs
cp LICENSE /usr/local/etc/rma/docs
cp README /usr/local/etc/rma/docs
#
Code: Select all
sudo vi /usr/local/etc/rma/rma.ini
Code: Select all
RmaPath = /usr/bin/rma
Password=*******
CPUUsageScript=/usr/local/etc/rma/cpu.sh
ProcCntScript=/usr/local/etc/rma/proccnt.sh
ProcListScript=/usr/local/etc/rma/proclist.sh
Code: Select all
sudo touch /etc/init.d/rma
Code: Select all
sudo vi /etc/init.d/rma
Code: Select all
#! /bin/sh
### BEGIN INIT INFO
# Provides: Host Monitor RMA
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Host Monitor RMA
### END INIT INFO
# Author: ***** <*****@****.***>
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESCRIPTION="Host Monitor RMA"
NAME=rma
RMA_INI_FILE=/usr/local/etc/rma/rma.ini
DAEMON=/usr/bin/$NAME
DAEMON_ARGS="-d $RMA_INI_FILE"
PIDFILE=$PIDNAME.pid
PIDSPATH=/var/run
PIDFILE=$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
RUNAS=root #user to run as
SCRIPT_OK=0 #ala error codes
SCRIPT_ERROR=1 #ala error codes
TRUE=1 #boolean
FALSE=0 #boolean
#------------------------------------------------------------------------------
# Simple Tests
#------------------------------------------------------------------------------
# Test if rma is a file and executable
[ -x "$DAEMON" ] || exit 0
# Include rma defaults if available
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /lib/init/vars.sh
. /lib/lsb/init-functions
#------------------------------------------------------------------------------
# Functions
#------------------------------------------------------------------------------
setFilePerms(){
if [ -f $PIDSPATH/$PIDFILE ]; then
chmod 400 $PIDSPATH/$PIDFILE
fi
}
isRunning() {
if [ $1 ]; then
pidof_daemon $1
PID=$?
if [ $PID -gt 0 ]; then
return 1
else
return 0
fi
else
pidof_daemon
PID=$?
if [ $PID -gt 0 ]; then
return 1
else
return 0
fi
fi
}
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
status(){
isRunning
isAlive=$?
if [ "${isAlive}" -eq $TRUE ]; then
echo "$DESCRIPTION found running with processes: `pidof $NAME`"
else
echo "$DESCRIPTION is NOT running."
fi
}
removePIDFile(){
if [ $1 ]; then
if [ -f $1 ]; then
rm -f $1
fi
else
#Do default removal
if [ -f $PIDSPATH/$PIDFILE ]; then
rm -f $PIDSPATH/$PIDFILE
fi
fi
}
start() {
log_daemon_msg "Starting $DESCRIPTION"
isRunning
isAlive=$?
if [ "${isAlive}" -eq $TRUE ]; then
log_end_msg $SCRIPT_ERROR
else
start-stop-daemon --start --verbose --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON -- $DAEMON_ARGS
pidof $NAME >$PIDSPATH/$PIDFILE
setFilePerms
log_end_msg $SCRIPT_OK
fi
}
stop() {
log_daemon_msg "Stopping $DESCRIPTION"
isRunning
isAlive=$?
if [ "${isAlive}" -eq $TRUE ]; then
start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
# wait_for_pid 'removed' $PIDSPATH/$PIDFILE
# if [ -n "$try" ] ; then
# log_end_msg $SCRIPT_ERROR
# else
removePIDFile
log_end_msg $SCRIPT_OK
# fi
else
log_end_msg $SCRIPT_ERROR
fi
}
reload() {
log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
isRunning
if [ $? -eq $TRUE ]; then
kill -HUP `cat $PIDSPATH/$PIDFILE`
log_end_msg $SCRIPT_OK
else
log_end_msg $SCRIPT_ERROR
fi
}
destroy() {
log_daemon_msg "Force terminating and may include self (via KILLALL) $DESCRIPTION"
killall $NAME -q >> /dev/null 2>&1
log_end_msg $SCRIPT_OK
}
pidof_daemon() {
PIDS=`pidof $NAME`
[ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
for i in $PIDS; do
if [ "$i" = "$PIDS2" ]; then
return 1
fi
done
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
reload)
$1
;;
status)
status
;;
destroy)
$1
;;
*)
echo "Usage: service $NAME {start|stop|restart|reload|destroy}"
echo " The 'destroy' command should only be used as a last resort."
exit 1
;;
esac
exit 0
Code: Select all
sudo chmod +x /etc/init.d/rma
Code: Select all
sudo update-rc.d rma defaults
Code: Select all
sudo service rma start