Skip to content

Instantly share code, notes, and snippets.

@unode
Last active August 29, 2015 14:14
Show Gist options
  • Save unode/25f47f232b68177f8b46 to your computer and use it in GitHub Desktop.
Save unode/25f47f232b68177f8b46 to your computer and use it in GitHub Desktop.
galaxy init scripts
#!/bin/bash
# Author: Renato Alves, 2013
function usage {
echo "WARNING: $0 should not be used directly"
echo " Create a symlink to $0 with a name in the format 'galaxy-NAME'"
echo " NAME should be 'toolshed' or anything matching [server:NAME] in your config/galaxy.ini"
echo "E.g. galaxy-web0 , galaxy-job0 or galaxy-toolshed"
exit 1
}
# Will hold the final part of current script name "galaxy-(SERVER)"
if [[ "${0}" == *galaxy-* ]]; then
SERVER=${0##*-}
if [ $SERVER == "base" ]; then
usage
fi
else
usage
fi
### BEGIN INIT INFO
# Provides: galaxy-$SERVER
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Galaxy $SERVER
### END INIT INFO
HOME=/home/Users/galaxy/galaxy_files
VENV="$HOME/galaxy_env"
DIR="$HOME/galaxy_dist"
PATH=$VENV/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
USER=galaxy
GROUP=galaxy
DAEMON=/bin/sh
NAME=galaxy-$SERVER
LOGFILE=/var/log/$USER/$NAME.log
PIDFILE=/var/run/$USER/$NAME.pid
if [ "$NAME" == "galaxy-toolshed" ]; then
DAEMON_OPTS="$DIR/run_tool_shed.sh --log-file=$LOGFILE --pid-file=$PIDFILE"
else
DAEMON_OPTS="$DIR/run.sh --log-file=$LOGFILE --server-name=$SERVER --pid-file=$PIDFILE"
fi
# Removed exit on error as this causes premature aborts and makes it impossible
# to use commands that are expected to fail
#set -e
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting Galaxy" "$SERVER"
LOGFOLDER="$(dirname $LOGFILE)"
PIDFOLDER="$(dirname $PIDFILE)"
# Make sure log and run folders exist and are owned by $USER before launch
# but only if LOGFOLDER and PIDFOLDER end with $USER
if [[ "$(basename $LOGFOLDER)" == "$USER" && "$(basename $PIDFOLDER)" == "$USER" ]]; then
if ! [ -d "$LOGFOLDER" ]; then
mkdir "$LOGFOLDER"
fi
chown $USER.$GROUP $LOGFOLDER
if ! [ -d "$PIDFOLDER" ]; then
mkdir "$PIDFOLDER"
fi
chown $USER.$GROUP $PIDFOLDER
fi
start-stop-daemon --chuid $USER --group $GROUP --start \
--pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPTS --daemon > /dev/null
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping Galaxy" "$SERVER"
start-stop-daemon --stop --pidfile $PIDFILE -- --stop-daemon
log_end_msg $?
;;
restart|force-reload)
# restart commands here
$0 stop
sleep 1
$0 start
;;
status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;
*)
echo "Usage: $0 start|stop|restart|force-reload|status"
exit 1
;;
esac
#!/bin/bash
# Author: Renato Alves, 2014
### BEGIN INIT INFO
# Provides: galaxy-init
# Required-Start: $network $local_fs
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Initialize all galaxy components
### END INIT INFO
PATH=$VENV/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#set -e
function get_components {
for g in ${DIR}/galaxy-*; do
# Do nothing for galaxy-init and galaxy-base
case "$g" in
${DIR}/galaxy-init|${DIR}/galaxy-base)
continue
;;
*)
echo $g
esac
done
}
function check_status {
# Check the status of the current galaxy component in a subshell
if [ "$2" == "verbose" ]; then
($1 status)
else
($1 status) > /dev/null
echo $?
fi
}
function check_status_verbose {
check_status $1 "verbose"
}
. /lib/lsb/init-functions
case "$1" in
start)
for g in $(get_components); do
# Check the status of the current galaxy component in a subshell
STATUS=$(check_status $g)
if [ "$STATUS" != "0" ]; then
$g start
else
SERVER="galaxy-${g##*-}"
echo "Not starting $SERVER - already running"
fi
done
;;
stop)
for g in $(get_components); do
# Check the status of the current galaxy component in a subshell
STATUS=$(check_status $g)
if [ "$STATUS" == "0" ]; then
$g stop
else
SERVER="galaxy-${g##*-}"
echo "Not stopping $SERVER - already stopped with status $STATUS"
fi
done
;;
restart|force-reload)
# restart commands here
$0 stop
sleep 1
$0 start
;;
status)
for g in $(get_components); do
check_status_verbose $g
done
;;
*)
echo "Usage: $0 start|stop|restart|force-reload|status"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment