-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstart_smartune.sh
More file actions
executable file
·77 lines (65 loc) · 1.88 KB
/
Copy pathstart_smartune.sh
File metadata and controls
executable file
·77 lines (65 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Copyright (c) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#
# Top-level entry point for the SmarTune product.
#
# -a (default) start balancer + monitor together (single process, port 9001)
# -m start the monitor only (standalone, port 9001)
set -e
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
cd "$SCRIPT_DIR"
usage() {
cat <<EOF
Usage: $(basename "$0") [-a | -m | -h]
-a Start balancer + monitor together (single process, port 9001). Default.
-m Start the monitor only (standalone telemetry, port 9001).
-h Show this help and exit.
EOF
}
MODE="all"
while getopts "amh" opt; do
case "$opt" in
a) MODE="all" ;;
m) MODE="monitor" ;;
h) usage; exit 0 ;;
*) usage >&2; exit 1 ;;
esac
done
KEY_DIR="$SCRIPT_DIR/key"
CERT_FILE="$KEY_DIR/b_server.crt"
KEY_FILE="$KEY_DIR/b_server.key"
mkdir -p "$KEY_DIR"
if [ -f "$CERT_FILE" ] && [ -f "$KEY_FILE" ]; then
echo "Certificate and key already exist. Skipping generation."
else
echo "Generating certificate..."
openssl req -x509 -newkey rsa:4096 \
-keyout "$KEY_FILE" -out "$CERT_FILE" \
-days 365 -nodes -subj "/CN=localhost" \
-addext "subjectAltName=IP:127.0.0.1"
if [ $? -eq 0 ]; then
echo "Certificate generated successfully"
chmod 644 "$CERT_FILE"
chmod 600 "$KEY_FILE"
else
echo "Certificate generation failed" >&2
exit 1
fi
fi
PYTHON_BIN="$(command -v python3)"
cleanup() {
echo "Clean up..."
sudo pkill -f "smartune.py" 2>/dev/null
wait
stty sane 2>/dev/null || true
echo "Service stopped."
}
trap cleanup INT TERM EXIT
if [ "$MODE" = "monitor" ]; then
echo "Starting monitor only..."
sudo -E "$PYTHON_BIN" "$SCRIPT_DIR/smartune.py" -m
else
echo "Starting balancer + monitor..."
sudo -E "$PYTHON_BIN" "$SCRIPT_DIR/smartune.py" -a
fi