48 lines
1.1 KiB
Bash
Executable file
48 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
CMD=${1:-help}
|
|
PIDFILE="/tmp/merlin-daemon.pid"
|
|
LOGFILE="/tmp/merlin-daemon.log"
|
|
|
|
case "$CMD" in
|
|
start)
|
|
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
|
|
echo "Merlin already running (pid $(cat "$PIDFILE"))"
|
|
exit 0
|
|
fi
|
|
conda run -n cf python -m merlin.daemon >> "$LOGFILE" 2>&1 &
|
|
echo $! > "$PIDFILE"
|
|
echo "Merlin started (pid $!). Logs: $LOGFILE"
|
|
;;
|
|
stop)
|
|
if [ -f "$PIDFILE" ]; then
|
|
kill "$(cat "$PIDFILE")" 2>/dev/null && echo "Merlin stopped"
|
|
rm -f "$PIDFILE"
|
|
else
|
|
echo "Merlin not running"
|
|
fi
|
|
;;
|
|
restart)
|
|
bash "$0" stop
|
|
sleep 1
|
|
bash "$0" start
|
|
;;
|
|
status)
|
|
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
|
|
echo "Running (pid $(cat "$PIDFILE"))"
|
|
curl -s http://localhost:8522/status | python3 -m json.tool
|
|
else
|
|
echo "Stopped"
|
|
fi
|
|
;;
|
|
logs)
|
|
tail -f "$LOGFILE"
|
|
;;
|
|
test)
|
|
conda run -n cf pytest tests/ -v
|
|
;;
|
|
*)
|
|
echo "Usage: $0 start|stop|restart|status|logs|test"
|
|
;;
|
|
esac
|