#! /bin/sh # # Script to start the MX server and MX autosave processes at boot time. # # This version of the script runs as root, but starts up mxserver and # mxautosave under a non-root user account which is 'mx' by default. # #------------------------------------------------------------------------- # The following makes the script LSB (Linux Standard Base) compatible. # ### BEGIN INIT INFO # Provides: mxdaq # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start mxserver and mxautosave at boot time. # Description: Enables the MX data acquisition system servers. ### END INIT INFO # #------------------------------------------------------------------------- # The following is for the use of the old Red Hat Linux chkconfig command: # # chkconfig: 2345 99 01 # description: Server control script for the MX data acquisition \ # and control system. # processname: mxserver # 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_MXSERVER=${MXSBIN}/startmxserver START_MXAUTOSAVE=${MXSBIN}/startmxautosave #--- # 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:/sbin" export PATH # Find out which user is running this script. SCRIPTUSER=`whoami` # Which user are the MX server and autosave processes 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. UNAME_OS=`uname` if [ $SCRIPTUSER = $MXUSER ]; then COMMAND_PREFIX= elif [ $SCRIPTUSER = "root" ]; then if [ $UNAME_OS = "Darwin" ]; then COMMAND_PREFIX="/usr/bin/su $MXUSER -c" elif [ $UNAME_OS = "FreeBSD" ]; then COMMAND_PREFIX="/usr/bin/su $MXUSER -c" elif [ $UNAME_OS = "NetBSD" ]; then COMMAND_PREFIX="/usr/bin/su $MXUSER -c" elif [ $UNAME_OS = "OpenBSD" ]; then COMMAND_PREFIX="/usr/bin/su $MXUSER -c" else COMMAND_PREFIX="/bin/su $MXUSER -c" fi 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 #--- MXSERVER_OPTIONS_FILE=${MXDIR}/etc/mxserver.opt if [ -f ${MXSERVER_OPTIONS_FILE} ]; then MXSERVER_OPTIONS=`cat ${MXSERVER_OPTIONS_FILE}` fi START_MXSERVER_CMD="${START_MXSERVER} ${MXSERVER_OPTIONS}" #--- MXAUTOSAVE_OPTIONS_FILE=${MXDIR}/etc/mxautosave.opt if [ -f ${MXAUTOSAVE_OPTIONS_FILE} ]; then MXAUTOSAVE_OPTIONS=`cat ${MXAUTOSAVE_OPTIONS_FILE}` fi START_MXAUTOSAVE_CMD="$START_MXAUTOSAVE ${MXAUTOSAVE_OPTIONS}" #--- #echo "SCRIPTUSER=$SCRIPTUSER" #echo "MXUSER=$MXUSER" #echo "COMMAND_PREFIX=$COMMAND_PREFIX" #echo "START_MXSERVER_CMD=$START_MXSERVER_CMD" #echo "START_MXAUTOSAVE_CMD=$START_MXAUTOSAVE_CMD" case $1 in 'start' ) echo "Starting the MX servers." # 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_MXSERVER ]; then if [ $SCRIPTUSER = "root" ]; then $COMMAND_PREFIX "touch ${MXLOG}/mxserver.log" $COMMAND_PREFIX "$START_MXSERVER_CMD" else touch ${MXLOG}/mxserver.log $START_MXSERVER_CMD fi if [ -x $START_MXAUTOSAVE ]; then if [ $SCRIPTUSER = "root" ]; then $COMMAND_PREFIX "touch ${MXLOG}/mxautosave.log" $COMMAND_PREFIX "$START_MXAUTOSAVE_CMD" else touch ${MXLOG}/mxautosave.log $START_MXAUTOSAVE_CMD fi fi fi ;; 'stop' ) echo "Stopping the MX servers." if [ -f ${MXRUN}/mxserver.pid ]; then MXSERVER_PID=`cat ${MXRUN}/mxserver.pid` kill $MXSERVER_PID rm ${MXRUN}/mxserver.pid fi if [ -f ${MXRUN}/mxautosave.pid ]; then MXAUTOSAVE_PID=`cat ${MXRUN}/mxautosave.pid` kill $MXAUTOSAVE_PID rm ${MXRUN}/mxautosave.pid fi ;; 'restart' ) $0 stop echo "Waiting 2 seconds for the servers to shut down." sleep 2 $0 start ;; 'force-reload' ) $0 stop echo "Waiting 2 seconds for the servers to shut down." sleep 2 $0 start ;; 'status' ) echo "Status not implemented." ;; *) echo "Usage: ${MXDIR}/sbin/mx {start|stop|restart}" ;; esac exit 0