#! /bin/sh # # Script to start the MX Channel Access server at boot time. # # This version of the script runs as root, but starts up mxca_server # under a non-root user account which is 'mx' by default. # # The following is for the use of the Red Hat Linux chkconfig command: # # chkconfig: 2345 99 01 # description: EPICS Channel Access server control script for the MX data \ # acquisition and control system. # processname: mxca_server # if [ x$MXDIR = x ]; then MXDIR=/opt/mx fi MXBIN=${MXDIR}/bin MXETC=${MXDIR}/etc MXLOG=${MXDIR}/log MXRUN=${MXDIR}/run MXSBIN=${MXDIR}/sbin MX_LOCAL_CONFIG=${MXETC}/mx_local_config START_MXCA_SERVER=${MXSBIN}/start_mxca_server #--- # The following makes sure that whoami is in the path on Solaris 2 and SunOS 4 # and that libMx.dll is in the path on Cygwin. PATH="$PATH:$MXBIN:/usr/ucb" export PATH # Find out which user is running this script. SCRIPTUSER=`whoami` # Which user is the MX Channel Access server to be run as? MXUSER_FILE=${MXDIR}/etc/mxuser.dat if [ -f ${MXUSER_FILE} ]; then MXUSER=`cat ${MXUSER_FILE}` else MXUSER=mx fi # Construct a prefix for the server startup commands below. if [ $SCRIPTUSER = $MXUSER ]; then PREFIX= elif [ $SCRIPTUSER = "root" ]; then PREFIX="/bin/su $MXUSER -c" else echo "This script must be run either as the MX user '$MXUSER' or as 'root'." echo "You are '$SCRIPTUSER', so this script is aborting." exit 1 fi #--- MXCA_SERVER_OPTIONS_FILE=${MXDIR}/etc/mxca_server.opt if [ -f ${MXCA_SERVER_OPTIONS_FILE} ]; then MXCA_SERVER_OPTIONS=`cat ${MXCA_SERVER_OPTIONS_FILE}` fi START_MXCA_SERVER_CMD="$START_MXCA_SERVER ${MXCA_SERVER_OPTIONS}" #--- #echo "SCRIPTUSER=$SCRIPTUSER" #echo "MXUSER=$MXUSER" #echo "PREFIX=$PREFIX" #echo "START_MXCA_SERVER_CMD=$START_MXCA_SERVER_CMD" case $1 in 'start' ) echo "Starting the MX Channel Access server." # If possible, fix any outstanding permission problems. if [ $SCRIPTUSER = "root" ]; then chown $MXUSER ${MXDIR}/log chown $MXUSER ${MXDIR}/run chown $MXUSER ${MXDIR}/state chown $MXUSER ${MXDIR}/log/*.log fi if [ -f $MX_LOCAL_CONFIG ]; then . $MX_LOCAL_CONFIG fi if [ -x $START_MXCA_SERVER ]; then if [ $SCRIPTUSER = "root" ]; then $PREFIX "touch ${MXLOG}/mxca_server.log" ( $PREFIX "$START_MXCA_SERVER_CMD" < /dev/null >> ${MXLOG}/mxca_server.log 2>&1 & ) else touch ${MXLOG}/mxca_server.log ( $START_MXCA_SERVER_CMD < /dev/null >> ${MXLOG}/mxca_server.log 2>&1 & ) fi fi ;; 'stop' ) echo "Stopping the MX Channel Access server." if [ -f ${MXRUN}/mxca_server.pid ]; then MXCA_SERVER_PID=`cat ${MXRUN}/mxca_server.pid` kill $MXCA_SERVER_PID rm ${MXRUN}/mxca_server.pid fi ;; 'restart' ) $0 stop echo "Waiting 2 seconds for the MX Channel Access server to shut down." sleep 2 $0 start ;; *) echo "Usage: ${MXDIR}/sbin/mxca_server {start|stop|restart}" ;; esac