Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions diskwatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,9 @@ def main():
)
args = parser.parse_args()

# Control room launcher env override (between YAML and CLI in priority)
if os.environ.get("CRS_PORT_HTTP"): WEB_PORT = int(os.environ["CRS_PORT_HTTP"])

Comment on lines +1300 to +1302
# CLI flags override YAML (only when actually supplied)
if args.host is not None: WEB_HOST = args.host
if args.port is not None: WEB_PORT = args.port
Expand Down Expand Up @@ -1334,6 +1337,14 @@ def main():
t = threading.Thread(target=poll_loop, daemon=True)
t.start()

# Announce via mu2edaq-discovery (optional dependency).
try:
from mu2edaq_discovery import Responder
Responder(name="Disk Watcher", app="diskwatcher",
port=WEB_PORT, scheme="http").start()
except ImportError:
print("[Discovery] mu2edaq-discovery not installed; discovery disabled")

# Start Flask (werkzeug development server)
app.run(host=WEB_HOST, port=WEB_PORT, use_reloader=False,
threaded=True)
Comment on lines +1340 to 1350
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flask>=3.0
pyyaml>=6.0
mu2edaq-discovery @ git+https://github.com/Mu2e/mu2edaq-discovery.git
20 changes: 20 additions & 0 deletions start-mu2edaq-diskwatcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

source ./venv/bin/activate
export PYTHONPATH=./src:$PYTHONPATH

# Use a configuration file for the Diskwatcher, defaulting to diskwatcher.yaml if not provided
CONFIG_FILE="${1:-./config/mu2edaq-diskwatcher.yaml}"
echo "Starting DAQ Diskwatcher with configuration: $CONFIG_FILE"

# Start the Diskwatcher
#python diskwatcher.py --config $CONFIG_FILE --daemon
python diskwatcher.py --config $CONFIG_FILE
if [ $? -eq 0 ]; then
echo "Diskwatcher started successfully"
echo "Diskwatcher PID: $(cat ${CONFIG_FILE%.yaml}.pid)"
else
echo "Failed to start Diskwatcher"
fi


20 changes: 0 additions & 20 deletions start_diskwatcher.sh

This file was deleted.

1 change: 1 addition & 0 deletions start_diskwatcher.sh
30 changes: 30 additions & 0 deletions stop-mu2edaq-diskwatcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
#
# This script is used to stop the Diskwatcher. It sends a shutdown signal to the server,
# which will then cleanly shut down.
#
# We start with a simple curl command to send a shutdown request to the server's API endpoint.
# If this fails then we resort to killing the process directly.
#
# We start with a kill and then do a kill -9 if the process does not terminate within a reasonable time frame.
Comment on lines +3 to +9

# Take the name of the PID file as an argument, defaulting to the diskwatcher.pid if not provided
PID_FILE="${1:-./config/mu2edaq-diskwatcher.pid}"

if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
echo "Using Diskwatcher PID from file: $PID"
echo "Attempting to stop Diskwatcher with PID: $PID"
kill $PID 2>/dev/null || true
sleep 5
if kill -0 $PID 2>/dev/null; then
echo "Diskwatcher did not shut down cleanly, killing forcefully."
kill -9 $PID 2>/dev/null || true
else
echo "Diskwatcher stopped successfully."
fi
rm -f "$PID_FILE"
Comment on lines +14 to +26
else
echo "Diskwatcher PID file not found: $PID_FILE."
echo "Is the server running?"
fi
30 changes: 0 additions & 30 deletions stop_diskwatcher.sh

This file was deleted.

1 change: 1 addition & 0 deletions stop_diskwatcher.sh