Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,29 @@ The job manager writes log information to the file `eessi_bot_job_manager.log`.

The job manager can run on a different machine than the event handler, as long as both have access to the same shared filesystem.

## <a name="step7.3"></a>Step 7.3: Managing the bot with a single command
Comment thread
smoors marked this conversation as resolved.

The `bot` script starts, stops, restarts, and checks the status of the 2 bot
components: the event handler and the job manager. It launches both component
processes in the background.

```bash
./bot start [options]
./bot stop
./bot restart [options]
./bot status
```

Available `start`/`restart` options are the same as those for
`event_handler.sh` and `job_manager.sh`.

The following example starts the bot with 10 job manager iterations, managing
only job ids 1234 and 5678, and listening for events on port 8080:

```bash
./bot start -i 10 -j 1234,5678 --port 8080
```

# Example pull request on software-layer

For information on how to make pull requests and let the bot build software, see
Expand Down
126 changes: 126 additions & 0 deletions bot
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/bin/bash
#
# This file is part of the EESSI build-and-deploy bot,
# see https://github.com/EESSI/eessi-bot-software-layer
#
# The bot helps with requests to add software installations to the
# EESSI software layer, see https://github.com/EESSI/software-layer
#
# author: Samuel Moors (@smoors)
#
# license: GPLv2
#

red="$(tput setaf 1)"
blue="$(tput setaf 4)"
green="$(tput setaf 2)"
reset="$(tput sgr0)"

export PYTHONUNBUFFERED=1

JOB_MANAGER="python3 -m eessi_bot_job_manager"
EVENT_HANDLER="python3 -m eessi_bot_event_handler"

start_bot() {
local manager_args=()
local handler_args=()

shift

while [[ $# -gt 0 ]]; do
case "$1" in
-i|--max-manager-iterations)
manager_args+=("$1" "$2")
shift 2
;;
-j|--jobs)
manager_args+=("$1" "$2")
shift 2
;;
--port)
handler_args+=("$1" "$2")
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

if pgrep -f "$JOB_MANAGER" >/dev/null; then
Comment thread
smoors marked this conversation as resolved.
Outdated
echo "$blue>>> job manager is already running$reset"
else
echo "$blue>>> starting job manager...$reset"
$JOB_MANAGER "${manager_args[@]}" \
| sed -e '1s/^/\n/' -e "s/\(.*\)/$blue\1$reset/" &
fi

if pgrep -f "$EVENT_HANDLER" >/dev/null; then
Comment thread
smoors marked this conversation as resolved.
Outdated
echo "$green>>> event handler is already running$reset"
else
echo "$green>>> starting event handler...$reset"
$EVENT_HANDLER "${handler_args[@]}" \
| sed -e '1s/^/\n/' -e "s/\(.*\)/$green\1$reset/" &
fi
}

stop_bot() {
if pgrep -f "$EVENT_HANDLER" >/dev/null; then
echo "$red>>> stopping event handler...$reset"
pkill -e -f "$EVENT_HANDLER"
else
echo "$red>>> event handler is not running$reset"
fi

if pgrep -f "$JOB_MANAGER" >/dev/null; then
echo "$red>>> stopping job manager...$reset"
pkill -e -f "$JOB_MANAGER"
else
echo "$red>>> job manager is not running$reset"
fi
}

status_bot() {
if pgrep -f "$JOB_MANAGER" >/dev/null; then
Comment thread
smoors marked this conversation as resolved.
Outdated
echo "$blue>>> job manager is running$reset"
else
echo "$red>>> job manager is not running$reset"
fi

if pgrep -f "$EVENT_HANDLER" >/dev/null; then
Comment thread
smoors marked this conversation as resolved.
Outdated
echo "$green>>> event handler is running$reset"
else
echo "$red>>> event handler is not running$reset"
fi
}

case "$1" in
start)
start_bot "$@"
;;

stop)
stop_bot
;;

restart)
stop_bot
sleep 1
start_bot "$@"
;;

status)
status_bot
;;

*)
echo "Usage: $0 {start|stop|restart|status} [options]"
Comment thread
smoors marked this conversation as resolved.
Outdated
echo
echo "Start/restart options:"
echo " -i, --max-manager-iterations N Job manager max iterations"
echo " -j, --jobs N Comma-separated list of job ids"
echo " --port PORT Event handler port"
exit 1
;;
esac
Loading