Slackware init script for cfengine3

#!/bin/sh
# Start/stop/restart cfengine3.

# Set cfengine3 working directory
CFDIR="/usr/local/var/cfengine"

# Start cfengine3 daemons:
cfengine_start() {
  CFMONITORD="$CFDIR/bin/cf-monitord"
  CFEXECD="$CFDIR/bin/cf-execd"
  CFSERVERD="$CFDIR/bin/cf-serverd"

pgrep cf-monitord | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-monitord is running."
  else
    echo "Starting cf-monitord:  $CFMONITORD"
    $CFMONITORD
  fi

pgrep cf-execd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-execd is running."
  else
    echo "Starting cf-execd:  $CFEXECD"
    $CFEXECD
  fi

pgrep cf-serverd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-serverd is running."
  else
    echo "Starting cf-serverd:  $CFSERVERD"
    $CFSERVERD
  fi
}

# Stop cfengine3 daemons:
cfengine_stop() {
echo "Stopping cf-execd..."
  if [ -r $CFDIR/cf-execd.pid ]; then
    kill -9 $(cat $CFDIR/cf-execd.pid)
    rm -f $CFDIR/cf-execd.pid
  else
    killall cf-execd
  fi
echo "Stopping cf-monitord..."
  if [ -r $CFDIR/cf-monitord.pid ]; then
    kill -9 $(cat $CFDIR/cf-monitord.pid)
    rm -f $CFDIR/cf-monitord.pid
  else
    killall cf-monitord
  fi
echo "Stopping cf-serverd..."
  if [ -r $CFDIR/cf-serverd.pid ]; then
    kill -9 $(cat $CFDIR/cf-serverd.pid)
    rm -f $CFDIR/cf-serverd.pid
  else
    killall cf-serverd
  fi
}

# Restart cfengine3 daemons:
cfengine_restart() {
  cfengine_stop
  sleep 1
  cfengine_start
}

# Check if cfengine3 daemons are running
cfengine_status() {
pgrep cf-serverd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-serverd is running."
  else
    echo "cf-serverd is stopped."
  fi

pgrep cf-monitord | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-monitord is running."
  else
    echo "cf-monitord is stopped."
  fi

pgrep cf-execd | grep -v $$ | grep -q -v $PPID
if [ $? -eq 0 ]; then
    echo "cf-execd is running."
  else
    echo "cf-execd is stopped."
  fi
exit 1
}

case "$1" in
'start')
  cfengine_start
  ;;
'stop')
  cfengine_stop
  ;;
'restart')
  cfengine_restart
  ;;
'status')
  cfengine_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac

Leave a Reply

Your email address will not be published.