#!/bin/bash
#
# Copyright (C) Mellanox Technologies Ltd. 2001-2020. ALL RIGHTS RESERVED.
# See file LICENSE for terms.
#
# vma: Start the VMA Daemon
#
# chkconfig: 345 80 20
# description: This is a daemon which handles the task of \
# monitoring processes launched under VMA.
#
### BEGIN INIT INFO
# Provides: vma
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the VMA Daemon
# Description: This is a daemon which handles the task of
# monitoring processes launched under VMA.
### END INIT INFO
prefix=@prefix@
exec_prefix=@exec_prefix@
RETVAL=0
exefile=vmad
options=
pidfile=/var/run/lock/vmad.lock
# Source function library.
if [[ -s /etc/init.d/functions ]]; then
# RHEL / CentOS / SL / Fedora.
. /etc/init.d/functions
rc_status() { :; }
elif [[ -s /lib/lsb/init-functions ]]; then
# SLES / openSuSE / Debian.
. /lib/lsb/init-functions
success() { log_success_msg; }
failure() { log_failure_msg; }
elif [[ -s /etc/rc.status ]]; then
# Older SuSE systems.
. /etc/rc.status
failure() { rc_status -v; }
success() { rc_status -v; }
fi
function check_running()
{
[ -e ${pidfile} ] &&
[ "$(readlink "/proc/$(<${pidfile})/exe")" = "@sbindir@/${exefile}" ]
}
function check_permission()
{
[ "$(id -u)" = "0" ]
}
function do_start()
{
echo -n "Starting ${exefile}: "
if check_running; then
RETVAL=0
else
@sbindir@/${exefile} ${options} > /dev/null 2>&1
RETVAL=$?
fi
if [[ $RETVAL -eq 0 ]]; then
success
sleep 1
else
failure
fi
echo
}
function do_stop()
{
echo -n "Shutting down ${exefile}: "
RETVAL=0
if [ $(command -v pkill >/dev/null 2>&1 && echo $?) ]; then
pkill -INT "${exefile}"
RETVAL=$?
fi
if [[ $RETVAL -ne 0 ]]; then
killproc "${exefile}" -INT
RETVAL=$?
fi
if [[ $RETVAL -eq 0 ]]; then
success
sleep 1
else
failure
fi
echo
}
function do_status ()
{
pid="`pidof ${exefile}`"
ret=$?
if [ $ret -eq 0 ] ; then
echo "${exefile} is running... pid=$pid"
else
echo "${exefile} is not running."
fi
}
function do_restart()
{
do_stop
do_start
}
function do_check()
{
if ! check_permission; then
echo "root permission is required"
exit 1
fi
}
case "$1" in
start)
do_check
do_start
;;
stop)
do_check
do_stop
;;
status)
do_status
;;
restart | force-reload)
do_check
do_restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|force-reload}"
RETVAL=1
;;
esac
exit $RETVAL