Skip to content

Commit

Permalink
Replace paster with circusd, add basic functionality to run.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Apr 2, 2021
1 parent 201b1e5 commit 47d4e18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 56 deletions.
40 changes: 3 additions & 37 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,6 @@ fi
[ -n "$GALAXY_UWSGI" ] && APP_WEBSERVER='uwsgi'
find_server "${GALAXY_CONFIG_FILE:-none}" galaxy

if [ "$run_server" = "python" -a -n "$GALAXY_RUN_ALL" ]; then
servers=$(sed -n 's/^\[server:\(.*\)\]/\1/ p' "$GALAXY_CONFIG_FILE" | xargs echo)
if [ -z "$stop_daemon_arg_set" -a -z "$daemon_or_restart_arg_set" ]; then
echo "ERROR: \$GALAXY_RUN_ALL cannot be used without the '--daemon', '--stop-daemon', 'restart', 'start' or 'stop' arguments to run.sh"
exit 1
fi
for server in $servers; do
echo "Executing: python $server_args --server-name=\"$server\" --pid-file=\"$server.pid\" --log-file=\"$server.log\""
eval python $server_args --server-name="$server" --pid-file="$server.pid" --log-file="$server.log"
if [ -n "$wait_arg_set" -a -n "$daemon_or_restart_arg_set" ]; then
while true; do
sleep 1
# Grab the current pid from the pid file and remove any trailing space
if ! current_pid_in_file=$(sed -e 's/[[:space:]]*$//' "$server.pid"); then
echo "A Galaxy process died, interrupting" >&2
exit 1
fi
if [ -n "$current_pid_in_file" ]; then
echo "Found PID $current_pid_in_file in '$server.pid', monitoring '$server.log'"
else
echo "No PID found in '$server.pid' yet"
continue
fi
# Search for all pids in the logs and tail for the last one
latest_pid=$(grep '^Starting server in PID [0-9]\+\.$' "$server.log" | sed 's/^Starting server in PID \([0-9]\{1,\}\).$/\1/' | tail -n 1)
# If they're equivalent, then the current pid file agrees with our logs
# and we've succesfully started
[ -n "$latest_pid" ] && [ "$latest_pid" -eq "$current_pid_in_file" ] && break
done
echo
fi
done
else
echo "Executing: $run_server $server_args"
# args are properly quoted so use eval
eval $run_server $server_args
fi
echo "Executing: $run_server $server_args"
# args are properly quoted so use eval
eval $run_server $server_args
30 changes: 11 additions & 19 deletions scripts/common_startup_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ parse_common_args() {
;;
--stop-daemon|stop)
common_startup_args="$common_startup_args --stop-daemon"
paster_args="$paster_args --stop-daemon"
circusctl_args="$circusctl_args quit"
add_pid_arg=1
uwsgi_args="$uwsgi_args --stop \"$PID_FILE\""
stop_daemon_arg_set=1
shift
;;
--restart|restart)
paster_args="$paster_args restart"
circusctl_args="$circusctl_args restart"
add_pid_arg=1
add_log_arg=1
uwsgi_args="$uwsgi_args --reload \"$PID_FILE\""
Expand All @@ -41,7 +41,7 @@ parse_common_args() {
shift
;;
--daemon|start)
paster_args="$paster_args --daemon"
circusd_args="$circusd_args --daemon"
gunicorn_args="$gunicorn_args --daemon"
add_pid_arg=1
add_log_arg=1
Expand All @@ -52,7 +52,6 @@ parse_common_args() {
shift
;;
--status|status)
paster_args="$paster_args $1"
add_pid_arg=1
shift
;;
Expand All @@ -64,7 +63,7 @@ parse_common_args() {
break
;;
*)
paster_args="$paster_args $1"
circusctl_args="$circusctl_args $1"
uwsgi_args="$uwsgi_args $1"
shift
;;
Expand Down Expand Up @@ -138,14 +137,10 @@ find_server() {
server_config=$1
server_app=$2
arg_getter_args=
default_webserver="paste"
case "$server_config" in
*.y*ml|''|none)
default_webserver="uwsgi" # paste incapable of this
;;
esac
default_webserver="circusd"

APP_WEBSERVER=${APP_WEBSERVER:-$default_webserver}
CIRCUS_CONFIG_FILE=${CIRCUS_CONFIG_FILE:-config/dev.ini}
if [ "$APP_WEBSERVER" = "uwsgi" ]; then
# Look for uwsgi
if [ -z "$skip_venv" ] && [ -x $GALAXY_VIRTUAL_ENV/bin/uwsgi ]; then
Expand Down Expand Up @@ -173,15 +168,12 @@ find_server() {
if [ "$add_log_arg" -eq 1 ]; then
server_args="$server_args --log-file \"$LOG_FILE\""
fi
elif [ -n "$circusctl_args" ]; then
run_server="circusctl"
server_args="$circusctl_args"
else
run_server="python"
server_args="./scripts/paster.py serve \"$server_config\" $paster_args"
if [ "$add_pid_arg" -eq 1 ]; then
server_args="$server_args --pid-file \"$PID_FILE\""
fi
if [ "$add_log_arg" -eq 1 ]; then
server_args="$server_args --log-file \"$LOG_FILE\""
fi
run_server="circusd"
server_args="$CIRCUS_CONFIG_FILE $circusd_args"
fi
}

Expand Down

0 comments on commit 47d4e18

Please sign in to comment.