diff --git a/CHANGELOG b/CHANGELOG index c4bebca..67b81f9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,5 @@ +tag-1.4-20201113 JP + - Improve conf/ *bin/ file names and contents to better support production and (mac) development environments + tag-1.4-20201109 JP - Send status to info-serv-alert diff --git a/sbin/route_glue2.rc b/sbin/route_glue2.rc deleted file mode 100755 index 5c5579a..0000000 --- a/sbin/route_glue2.rc +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/sh - -### BEGIN INIT INFO -# Provides: route_glue2 -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Route glue2 messages from a source to a destination -# Description: Route glue2 messages from a {file, directory, amqp} to a {directory, api} -### END INIT INFO - -# Change these lines to suit where you install your script and what you want to call it -DAEMON_NAME=route_glue2 -APP_BASE=/soft/warehouse-apps-1.0/Manage-Glue2 -APP_SOURCE=${APP_BASE}/PROD -WAREHOUSE_SOURCE=/soft/warehouse-1.0/PROD -DAEMON_BIN=${APP_SOURCE}/bin/$DAEMON_NAME.py -DAEMON_LOG=${APP_BASE}/var/${DAEMON_NAME}.daemon.log -if [[ "$2" != --pdb && "$3" != --pdb && "$4" != --pdb ]]; then - exec >${DAEMON_LOG} 2>&1 -fi - -# Add any command line options for your daemon here -DAEMON_OPTS="-l info -c ${APP_BASE}/conf/${DAEMON_NAME}.conf" - -# This next line determines what user the script runs as -DAEMON_USER=software - -. /etc/init.d/functions - -PYTHON_BASE=${APP_BASE}/`cat python/lib/python*/orig-prefix.txt` -export LD_LIBRARY_PATH=${PYTHON_BASE}/lib - -PIPENV_BASE=${APP_BASE}/python -source ${PIPENV_BASE}/bin/activate - -PYTHON_BIN=python3 - -export PYTHONPATH=${APP_SOURCE}/lib:${WAREHOUSE_SOURCE}/django_xsede_warehouse -export DJANGO_CONF=${APP_BASE}/conf/django_xsede_warehouse.conf -export DJANGO_SETTINGS_MODULE=xsede_warehouse.settings - -do_start () { - echo -n "Starting ${DAEMON_NAME}:" - if [ `id -u` = 0 ] ; then - su ${DAEMON_USER} -s /bin/sh -c "${PYTHON_BIN} ${DAEMON_BIN} start ${DAEMON_OPTS}" - RETVAL=$? - elif [ `id -u` = `id -u ${DAEMON_USER}` ] ; then - ${PYTHON_BIN} ${DAEMON_BIN} start ${DAEMON_OPTS} - RETVAL=$? - else - echo "Only root or ${DAEMON_USER} should run ${DAEMON_BIN}" - RETVAL=99 - fi -} -do_stop () { - echo -n "Stopping ${DAEMON_NAME}:" - if [ `id -u` = 0 ] ; then - su ${DAEMON_USER} -s /bin/sh -c "${PYTHON_BIN} ${DAEMON_BIN} stop ${DAEMON_OPTS}" - RETVAL=$? - elif [ `id -u` = `id -u ${DAEMON_USER}` ] ; then - ${PYTHON_BIN} ${DAEMON_BIN} stop ${DAEMON_OPTS} - RETVAL=$? - else - echo "Only root or ${DAEMON_USER} should run ${DAEMON_BIN}" - RETVAL=99 - fi -} -do_debug () { - echo -n "Debugging: ${PYTHON_BIN} ${DAEMON_BIN} $@ ${DAEMON_OPTS}" - ${PYTHON_BIN} ${DAEMON_BIN} $@ ${DAEMON_OPTS} - RETVAL=$? -} - -case "$1" in - - start|stop) - do_${1} - ;; - - debug) - do_debug ${@:2} - ;; - - restart|reload|force-reload) - do_stop - do_start - ;; - - status) - echo "Haven't implemented status" - ;; - - *) - echo "Usage: /etc/init.d/${DAEMON_NAME} {start|stop|restart|status}" - exit 1 - ;; - -esac -echo rc=$RETVAL -exit $RETVAL diff --git a/sbin/route_glue2.service b/sbin/route_glue2.service index 7129950..a8ce9a4 100644 --- a/sbin/route_glue2.service +++ b/sbin/route_glue2.service @@ -5,11 +5,10 @@ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking EnvironmentFile=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.sysconfig -ExecStart=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.sh start -ExecReload=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.sh restart -ExecStop=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.sh stop +ExecStart=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.service.sh start +ExecReload=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.service.sh restart +ExecStop=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/sbin/route_glue2.service.sh stop PIDFile=/soft/warehouse-apps-1.0/Manage-Glue2/var/route_glue2.pid -#PrivateTmp=true User=software Group=admin Restart=always diff --git a/sbin/route_glue2.service.sh b/sbin/route_glue2.service.sh new file mode 100755 index 0000000..76564ba --- /dev/null +++ b/sbin/route_glue2.service.sh @@ -0,0 +1,49 @@ +#!/bin/sh +do_start () { + echo -n "Starting ${APP_NAME}:" + export LD_LIBRARY_PATH=${PYTHON_BASE}/lib + source ${PIPENV_BASE}/bin/activate + exec ${PYTHON_BIN} ${APP_BIN} start ${APP_OPTS} + RETVAL=$? +} +do_stop () { + echo -n "Stopping ${APP_NAME}:" + export LD_LIBRARY_PATH=${PYTHON_BASE}/lib + source ${PIPENV_BASE}/bin/activate + exec ${PYTHON_BIN} ${APP_BIN} stop ${APP_OPTS} + RETVAL=$? +} +do_debug () { + echo -n "Debugging: ${PIPENV_BASE}/bin/python ${APP_BIN} -l debug $@ ${APP_OPTS}" + export LD_LIBRARY_PATH=${PYTHON_BASE}/lib + source ${PIPENV_BASE}/bin/activate + exec ${PYTHON_BIN} ${APP_BIN} -l debug $@ ${APP_OPTS} + RETVAL=$? +} + +case "$1" in + start|stop) + do_${1} ${@:2} + ;; + + debug) + do_debug ${@:2} + ;; + + restart|reload|force-reload) + do_stop + do_start + ;; + + status) + echo "Haven't implemented status" + ;; + + *) + echo "Usage: ${APP_NAME} {start|stop|debug|restart}" + exit 1 + ;; + +esac +echo rc=$RETVAL +exit $RETVAL diff --git a/sbin/route_glue2.sh b/sbin/route_glue2.sh index b3612da..2a217db 100755 --- a/sbin/route_glue2.sh +++ b/sbin/route_glue2.sh @@ -1,29 +1,81 @@ #!/bin/sh + +### BEGIN INIT INFO +# Provides: route_glue2 +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Route glue2 messages from a source to a destination +# Description: Route glue2 messages from a {file, directory, amqp} to a {directory, api} +### END INIT INFO + +####### Customizations START ####### +APP_NAME=route_glue2 +APP_BASE=/soft/warehouse-apps-1.0/Manage-Glue2 +WAREHOUSE_BASE=/soft/warehouse-1.0 +# Override in shell environment +if [ -z "$PYTHON_BASE" ]; then + PYTHON_BASE=/soft/python/python-3.7.6-base +fi +DAEMON_USER=software +####### Customizations END ####### + +####### Everything else should be standard ####### +APP_SOURCE=${APP_BASE}/PROD +WAREHOUSE_SOURCE=${WAREHOUSE_BASE}/PROD + +APP_LOG=${APP_BASE}/var/${APP_NAME}.daemon.log +if [[ "$1" != --pdb && "$2" != --pdb && "$3" != --pdb && "$4" != --pdb ]]; then + exec >${APP_LOG} 2>&1 +fi + +APP_BIN=${APP_SOURCE}/bin/${APP_NAME}.py +APP_OPTS="-l info -c ${APP_BASE}/conf/${APP_NAME}.conf" + +PYTHON_BIN=python3 +export LD_LIBRARY_PATH=${PYTHON_BASE}/lib +source ${APP_BASE}/python/bin/activate + +export PYTHONPATH=${APP_SOURCE}/lib:${WAREHOUSE_SOURCE}/django_xsede_warehouse +export DJANGO_CONF=${APP_BASE}/conf/django_xsede_warehouse.conf +export DJANGO_SETTINGS_MODULE=xsede_warehouse.settings + do_start () { - echo -n "Starting ${DAEMON_NAME}:" - export LD_LIBRARY_PATH=${PYTHON_BASE}/lib - source ${PIPENV_BASE}/bin/activate - ${PYTHON_BIN} ${DAEMON_BIN} start ${DAEMON_OPTS} - RETVAL=$? + echo -n "Starting ${APP_NAME}:" + if [ `id -u` = 0 ] ; then + su ${DAEMON_USER} -s /bin/sh -c "${PYTHON_BIN} ${APP_BIN} start ${APP_OPTS}" + RETVAL=$? + elif [ `id -u` = `id -u ${DAEMON_USER}` ] ; then + ${PYTHON_BIN} ${APP_BIN} start ${APP_OPTS} + RETVAL=$? + else + echo "Only root or ${DAEMON_USER} should run ${APP_BIN}" + RETVAL=99 + fi } do_stop () { - echo -n "Stopping ${DAEMON_NAME}:" - export LD_LIBRARY_PATH=${PYTHON_BASE}/lib - source ${PIPENV_BASE}/bin/activate - ${PYTHON_BIN} ${DAEMON_BIN} stop ${DAEMON_OPTS} - RETVAL=$? + echo -n "Stopping ${APP_NAME}:" + if [ `id -u` = 0 ] ; then + su ${DAEMON_USER} -s /bin/sh -c "${PYTHON_BIN} ${APP_BIN} stop ${APP_OPTS}" + RETVAL=$? + elif [ `id -u` = `id -u ${DAEMON_USER}` ] ; then + ${PYTHON_BIN} ${APP_BIN} stop ${APP_OPTS} + RETVAL=$? + else + echo "Only root or ${DAEMON_USER} should run ${APP_BIN}" + RETVAL=99 + fi } do_debug () { - echo -n "Debugging: ${PIPENV_BASE}/bin/python ${DAEMON_BIN} $@ ${DAEMON_OPTS}" - export LD_LIBRARY_PATH=${PYTHON_BASE}/lib - source ${PIPENV_BASE}/bin/activate - ${PYTHON_BIN} ${DAEMON_BIN} $@ ${DAEMON_OPTS} + echo -n "Debugging: ${PYTHON_BIN} ${APP_BIN} $@ ${APP_OPTS}" + ${PYTHON_BIN} ${APP_BIN} $@ ${APP_OPTS} RETVAL=$? } case "$1" in start|stop) - do_${1} + do_${1} ${@:2} ;; debug) @@ -40,7 +92,7 @@ case "$1" in ;; *) - echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}" + echo "Usage: ${APP_NAME} {start|stop|debug|restart} []" exit 1 ;; diff --git a/sbin/route_glue2.sysconfig b/sbin/route_glue2.sysconfig index 35a0952..df1c112 100644 --- a/sbin/route_glue2.sysconfig +++ b/sbin/route_glue2.sysconfig @@ -1,12 +1,13 @@ -DAEMON_NAME=route_glue2 -DAEMON_BIN=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/bin/route_glue2.py +APP_NAME=route_glue2 +APP_BASE=/soft/warehouse-apps-1.0/Manage-Glue2 +APP_BIN=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/bin/route_glue2.py # Add any command line options for your daemon here -DAEMON_OPTS="-l info -c /soft/warehouse-apps-1.0/Manage-Glue2/conf/route_glue2.conf" +APP_OPTS="-l info -c /soft/warehouse-apps-1.0/Manage-Glue2/conf/route_glue2.conf" -APP_BASE=/soft/warehouse-apps-1.0/Manage-Glue2 PYTHON_BASE=/soft/python/python-3.7.5-base PIPENV_BASE=/soft/warehouse-apps-1.0/Manage-Glue2/python PYTHON_BIN=python3 PYTHONPATH=/soft/warehouse-apps-1.0/Manage-Glue2/PROD/lib:/soft/warehouse-1.0/PROD/django_xsede_warehouse + DJANGO_CONF=/soft/warehouse-apps-1.0/Manage-Glue2/conf/django_xsede_warehouse.conf DJANGO_SETTINGS_MODULE=xsede_warehouse.settings