msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

10 Aug 2007 Start/Stop script for a prosess run as another user

Posted by

#!/bin/sh

# rc.flexlm - Init.d start/stop script for the FlexLM License Manager

# Variables:
LM_DIR="/usr/local/matlab71/etc"
LM_BIN="lmgrd"
PROG_BIN="$LM_DIR/glnx86/$LM_BIN"

LICENSE_FILE="$LM_DIR/license.dat"

RUN_AS=flexlm
LOG_FILE="/var/log/flexlm.log"

PROG_ARGS="-c $LICENSE_FILE -l $LOG_FILE"

# Sleep time for restart.
SLEEP=1

start()
{
  echo -n "Starting FlexLM License Manager ($LM_BIN): "
  # already running?
  PID=$(pidof -s $PROG_BIN)
  if [ -z $PID ]; then
    # Initialize log file (only owner gets rw permission).
    touch $LOG_FILE
    chmod 600 $LOG_FILE
    chown $RUN_AS $LOG_FILE

    # Start program.
    su $RUN_AS -c "$PROG_BIN $PROG_ARGS"
    RETVAL=$?
    if [ "$RETVAL" = "0" ]; then
      echo "OK."
      # Create lock file:
      echo "$PID" >/var/run/flexlm.pid
    else
      echo "FAILED!"
    fi
  else
    echo "already running (PID $PID)"
    RETVAL=0
  fi

  return $RETVAL
}

stop()
{
  echo -n "Stopping FlexLM License Manager ($LM_BIN): "
  # running?
  PID=$(pidof -s $PROG_BIN)
  if [ -z $PID ]; then
    echo "not running!"
    RETVAL=0
  else
    kill $PID
    RETVAL=$?
    # Remove lock file.
    if [ "$RETVAL" = "0" ]; then
      echo "OK."
      # Remove lock file:
      rm -f /var/run/flexlm.pid
    else
      echo "FAILED!"
    fi
  fi

  return $RETVAL
}

Tags:

Comments are closed.