Skip to content
Snippets Groups Projects
Commit 92c6068a authored by kpetersn's avatar kpetersn
Browse files

Added xxx.sh, a script to start/stop/restart a linux ioc in a screen session....

Added xxx.sh, a script to start/stop/restart a linux ioc in a screen session. Improved in-screen.sh and run scripts.
parent 708c3ae0
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
# $Id$
/usr/bin/screen -d -m ./run
/usr/bin/screen -dm -S xxx -h 5000 ./run
# start the IOC in a screen session
# type:
......
......@@ -3,7 +3,7 @@
# ensure that multiple, simultaneous IOCs are not started by this user ID
MY_UID=`id -u`
IOC_PID="`/usr/bin/pgrep xxx -u ${MY_UID}`"
IOC_PID="`/usr/bin/pgrep xxx\$ -u ${MY_UID}`"
if [ "" != "${IOC_PID}" ] ; then
echo "xxx IOC is already running, won't start a new one, PID=${IOC_PID}"
......
#!/bin/sh
#
# description: start/stop/restart an EPICS IOC in a screen session
#
# Make sure this path to the IOC is set correctly
IOC_STARTUP_DIR=/home/username/epics/ioc/synApps/xxx/iocBoot/iocxxx
IOC_NAME=xxx
# Commands needed by this script
ECHO=echo
ID=id
PGREP=pgrep
SCREEN=screen
KILL=kill
# Explicitly define paths to commands if commands aren't found
#!ECHO=/bin/echo
#!ID=/usr/bin/id
#!PGREP=/usr/bin/pgrep
#!SCREEN=/usr/bin/screen
#!KILL=/bin/kill
#####################################################################
SNAME=$0
SELECTION=$1
#####################################################################
checkpid() {
MY_UID=`${ID} -u`
# The '\$' is needed in the pgrep pattern to select xxx, but not xxx.sh
IOC_PID=`${PGREP} ${IOC_NAME}\$ -u ${MY_UID}`
#!echo "IOC_PID=${IOC_PID}"
if [ "$IOC_PID" != "" ] ; then
# IOC is running
IOC_DOWN=0
else
# IOC is not running
IOC_DOWN=1
fi
return ${IOC_DOWN}
}
start() {
if checkpid; then
${ECHO} "${IOC_NAME} is already running (pid=${IOC_PID})"
else
${ECHO} "Starting ${IOC_NAME}"
cd ${IOC_STARTUP_DIR}
./in-screen.sh
# Run xxx outside of a screen session, which is helpful for debugging
#!./run
fi
}
stop() {
if checkpid; then
${ECHO} "Stopping ${IOC_NAME} (pid=${IOC_PID})"
${KILL} ${IOC_PID}
else
${ECHO} "${IOC_NAME} is not running"
fi
}
restart() {
stop
start
}
status() {
if checkpid; then
${ECHO} "${IOC_NAME} is running (pid=${IOC_PID})"
else
${ECHO} "${IOC_NAME} is not running"
fi
}
console() {
if checkpid; then
${ECHO} "Connecting to ${IOC_NAME}'s screen session"
# The -r flag will only connect if no one is attached to the session
#!${SCREEN} -r ${IOC_NAME}
# The -x flag will connect even if someone is attached to the session
${SCREEN} -x ${IOC_NAME}
else
${ECHO} "${IOC_NAME} is not running"
fi
}
usage() {
${ECHO} "Usage: $(basename ${SNAME}) {start|stop|restart|status|console}"
}
#####################################################################
if [ ! -d ${IOC_STARTUP_DIR} ]
then
${ECHO} "Error: ${IOC_STARTUP_DIR} doesn't exist."
${ECHO} "IOC_STARTUP_DIR in ${SNAME} needs to be corrected."
else
case ${SELECTION} in
start)
start
;;
stop | kill)
stop
;;
restart)
restart
;;
status)
status
;;
console)
console
;;
*)
usage
;;
esac
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment