Skip to content
Snippets Groups Projects
Unverified Commit 7c3ba7f9 authored by kpetersn's avatar kpetersn Committed by GitHub
Browse files

Merge pull request #14 from epics-modules/bash_source_12

BASH scripting changes
parents 1caff2ed ebe56302
No related branches found
No related tags found
No related merge requests found
......@@ -40,27 +40,33 @@ PS=ps
#####################################################################
SNAME=$0
SNAME=${BASH_SOURCE:-$0}
SELECTION=$1
if [ -z "$IOC_STARTUP_DIR" ]
then
# uncomment for your OS here (comment out all the others)
#IOC_STARTUP_FILE="st.cmd.Cygwin"
IOC_STARTUP_FILE="st.cmd.Linux"
#IOC_STARTUP_FILE="st.cmd.vxWorks"
#IOC_STARTUP_FILE="st.cmd.Win32"
#IOC_STARTUP_FILE="st.cmd.Win64"
if [ -z "$IOC_STARTUP_DIR" ] ; then
# If no startup dir is specified, use the directory above the script's directory
IOC_STARTUP_DIR=`dirname $BASH_SOURCE`/..
IOC_CMD="../../bin/${EPICS_HOST_ARCH}/${IOC_BINARY} st.cmd.Linux"
IOC_STARTUP_DIR=`dirname ${SNAME}`/..
IOC_CMD="../../bin/${EPICS_HOST_ARCH}/${IOC_BINARY} ${IOC_STARTUP_FILE}"
else
IOC_CMD="${IOC_STARTUP_DIR}/../../bin/${EPICS_HOST_ARCH}/${IOC_BINARY} ${IOC_STARTUP_DIR}/st.cmd.Linux"
IOC_CMD="${IOC_STARTUP_DIR}/../../bin/${EPICS_HOST_ARCH}/${IOC_BINARY} ${IOC_STARTUP_DIR}/${IOC_STARTUP_FILE}"
fi
#!${ECHO} ${IOC_STARTUP_DIR}
#####################################################################
screenpid() {
if [ -z ${SCREEN_PID} ] ; then
${ECHO}
else
${ECHO} " in a screen session (pid=${SCREEN_PID})"
fi
if [ -z ${SCREEN_PID} ] ; then
${ECHO}
else
${ECHO} " in a screen session (pid=${SCREEN_PID})"
fi
}
checkpid() {
......@@ -71,61 +77,59 @@ checkpid() {
if [ "${IOC_PID}" != "" ] ; then
# Assume the IOC is down until proven otherwise
IOC_DOWN=1
IOC_DOWN=1
# At least one instance of the IOC binary is running;
# Find the binary that is associated with this script/IOC
# At least one instance of the IOC binary is running;
# Find the binary that is associated with this script/IOC
for pid in ${IOC_PID}; do
BIN_CWD=`${READLINK} /proc/${pid}/cwd`
IOC_CWD=`${READLINK} -f ${IOC_STARTUP_DIR}`
if [ "$BIN_CWD" == "$IOC_CWD" ] ; then
# The IOC is running; the binary with PID=$pid is the IOC that was run from $IOC_STARTUP_DIR
IOC_PID=${pid}
IOC_DOWN=0
SCREEN_PID=""
if [ "${GET_SCREEN_PID}" == "YES" ]
then
# Get the PID of the parent of the IOC (shell or screen)
P_PID=`${PS} -p ${IOC_PID} -o ppid=`
# Get the PID of the grandparent of the IOC (sshd, screen, or ???)
GP_PID=`${PS} -p ${P_PID} -o ppid=`
#!${ECHO} "P_PID=${P_PID}, GP_PID=${GP_PID}"
# Get the screen PIDs
S_PIDS=`${PGREP} screen`
for s_pid in ${S_PIDS}
do
#!${ECHO} ${s_pid}
if [ "${s_pid}" == "${P_PID}" ] ; then
SCREEN_PID=${s_pid}
break
fi
if [ "${s_pid}" == "${GP_PID}" ] ; then
SCREEN_PID=${s_pid}
break
fi
done
fi
break
#else
# ${ECHO} "PATHS are different"
# ${ECHO} ${BIN_CWD}
# ${ECHO} ${IOC_CWD}
fi
done
BIN_CWD=`${READLINK} /proc/${pid}/cwd`
IOC_CWD=`${READLINK} -f ${IOC_STARTUP_DIR}`
if [ "$BIN_CWD" = "$IOC_CWD" ] ; then
# The IOC is running; the binary with PID=$pid is the IOC that was run from $IOC_STARTUP_DIR
IOC_PID=${pid}
IOC_DOWN=0
SCREEN_PID=""
if [ "${GET_SCREEN_PID}" = "YES" ] ; then
# Get the PID of the parent of the IOC (shell or screen)
P_PID=`${PS} -p ${IOC_PID} -o ppid=`
# Get the PID of the grandparent of the IOC (sshd, screen, or ???)
GP_PID=`${PS} -p ${P_PID} -o ppid=`
#!${ECHO} "P_PID=${P_PID}, GP_PID=${GP_PID}"
# Get the screen PIDs
S_PIDS=`${PGREP} screen`
for s_pid in ${S_PIDS} ; do
#!${ECHO} ${s_pid}
if [ "${s_pid}" = "${P_PID}" ] ; then
SCREEN_PID=${s_pid}
break
fi
if [ "${s_pid}" = "${GP_PID}" ] ; then
SCREEN_PID=${s_pid}
break
fi
done
fi
break
#else
# ${ECHO} "PATHS are different"
# ${ECHO} ${BIN_CWD}
# ${ECHO} ${IOC_CWD}
fi
done
else
# IOC is not running
IOC_DOWN=1
IOC_DOWN=1
fi
return ${IOC_DOWN}
......@@ -134,19 +138,19 @@ checkpid() {
start() {
if checkpid; then
${ECHO} -n "${IOC_NAME} is already running (pid=${IOC_PID})"
screenpid
screenpid
else
${ECHO} "Starting ${IOC_NAME}"
cd ${IOC_STARTUP_DIR}
# Run xxx inside a screen session
${SCREEN} -dm -S ${IOC_NAME} -h 5000 ${IOC_CMD}
# Run xxx inside a screen session
${SCREEN} -dm -S ${IOC_NAME} -h 5000 ${IOC_CMD}
fi
}
stop() {
if checkpid; then
${ECHO} "Stopping ${IOC_NAME} (pid=${IOC_PID})"
${KILL} ${IOC_PID}
${KILL} ${IOC_PID}
else
${ECHO} "${IOC_NAME} is not running"
fi
......@@ -169,10 +173,10 @@ status() {
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}
# 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
......@@ -181,21 +185,21 @@ console() {
run() {
if checkpid; then
${ECHO} -n "${IOC_NAME} is already running (pid=${IOC_PID})"
screenpid
screenpid
else
${ECHO} "Starting ${IOC_NAME}"
cd ${IOC_STARTUP_DIR}
# Run xxx outside of a screen session, which is helpful for debugging
${IOC_CMD}
# Run xxx outside of a screen session, which is helpful for debugging
${IOC_CMD}
fi
}
start_medm() {
${IOC_STARTUP_DIR}/../../start_MEDM_xxx
${IOC_STARTUP_DIR}/../../start_MEDM_xxx
}
start_caqtdm() {
${IOC_STARTUP_DIR}/../../start_caQtDM_xxx
${IOC_STARTUP_DIR}/../../start_caQtDM_xxx
}
usage() {
......@@ -204,46 +208,45 @@ usage() {
#####################################################################
if [ ! -d ${IOC_STARTUP_DIR} ]
then
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
;;
start
;;
stop | kill)
stop
;;
stop
;;
restart)
restart
;;
restart
;;
status)
status
;;
status
;;
console)
console
;;
;;
run)
run
;;
medm)
start_medm
;;
caqtdm)
start_caqtdm
;;
;;
medm)
start_medm
;;
caqtdm)
start_caqtdm
;;
*)
usage
;;
usage
;;
esac
fi
#!/bin/bash
export EPICS_APP=`dirname $BASH_SOURCE`
export EPICS_APP=`dirname ${BASH_SOURCE:-$0}`
export EPICS_APP_ADL_DIR=${EPICS_APP}/xxxApp/op/adl
export DEFAULT_UI_FILE=${DEFAULT_UI_FILE:-xxx.adl}
......
#!/bin/bash
export EPICS_APP=`dirname $BASH_SOURCE`
export EPICS_APP=`dirname ${BASH_SOURCE:-$0}`
export EPICS_APP_UI_DIR=${EPICS_APP}/xxxApp/op/ui
export DEFAULT_UI_FILE=${DEFAULT_UI_FILE:-xxx.ui}
......
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