Skip to content

Commit dbbc779

Browse files
Refactor setup.sh and cronjob.sh scripts
1 parent c36d885 commit dbbc779

1 file changed

Lines changed: 58 additions & 7 deletions

File tree

setup.sh

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,54 @@ load_test() {
281281
# locust -f "$LOCUST_FILE" --host="$HOST_URL" --headless -u 10 -r 1 --run-time 1m
282282
}
283283

284+
# Check if SystemGuard is installed
285+
check_status() {
286+
log "Checking SystemGuard status..."
287+
288+
if [ -d "$EXTRACT_DIR" ]; then
289+
log "SystemGuard is installed at $EXTRACT_DIR."
290+
else
291+
log "SystemGuard is not installed."
292+
fi
293+
294+
CRON_PATTERN=".systemguard/SystemGuard-.*/src/scripts/dashboard.sh"
295+
if crontab -l | grep -q "$CRON_PATTERN"; then
296+
log "Cron job for SystemGuard is set."
297+
else
298+
log "No cron job found for SystemGuard."
299+
fi
300+
301+
# Check if any of SystemGuard's services are running (example check for a specific service)
302+
if pgrep -f "dashboard.sh" > /dev/null; then
303+
log "SystemGuard services are running."
304+
else
305+
log "SystemGuard services are not running."
306+
fi
307+
}
308+
309+
# Health check by pinging localhost:5005
310+
health_check() {
311+
log "Performing health check on localhost:5005..."
312+
if curl -s --head $HOST_URL | grep "200 OK" > /dev/null; then
313+
log "Health check successful: $HOST_URL is up and running."
314+
else
315+
log "Health check failed: $HOST_URL is not responding."
316+
fi
317+
}
318+
319+
284320
# Display help
285321
show_help() {
286322
echo "SystemGuard Installer"
287323
echo "Usage: ./installer.sh [options]"
288324
echo "Options:"
289-
echo " --install Install SystemGuard"
290-
echo " --uninstall Uninstall SystemGuard"
291-
echo " --restore Restore SystemGuard from a backup"
292-
echo " --load-test Start Locust load testing"
293-
echo " --help Display this help message"
325+
echo " --install Install SystemGuard"
326+
echo " --uninstall Uninstall SystemGuard"
327+
echo " --restore Restore SystemGuard from a backup"
328+
echo " --load-test Start Locust load testing"
329+
echo " --status Check the status of SystemGuard installation"
330+
echo " --health-check Perform a health check on localhost:5005"
331+
echo " --help Display this help message"
294332
}
295333

296334
# Parse command-line options
@@ -300,6 +338,8 @@ for arg in "$@"; do
300338
--uninstall) ACTION="uninstall" ;;
301339
--restore) ACTION="restore" ;;
302340
--load-test) ACTION="load_test" ;;
341+
--status) ACTION="check_status" ;;
342+
--health-check) ACTION="health_check" ;;
303343
--help) show_help; exit 0 ;;
304344
*) echo "Unknown option: $arg"; show_help; exit 1 ;;
305345
esac
@@ -311,10 +351,21 @@ case $ACTION in
311351
uninstall) uninstall ;;
312352
restore) restore ;;
313353
load_test) load_test ;;
354+
install_latest) install_latest ;;
355+
check_status) check_status ;;
356+
health_check) health_check ;;
314357
*) echo "No action specified. Use --help for usage information." ;;
315358
esac
316359

317-
318360
# this script ran with sudo command so all the files have root permission
319361
# remove the root permission from the files to the user
320-
chown -R $USER_NAME:$USER_NAME $EXTRACT_DIR
362+
# Function to change ownership of a directory to the user
363+
change_ownership() {
364+
local directory="$1"
365+
if [ -d "$directory" ]; then
366+
chown -R "$USER_NAME:$USER_NAME" "$directory"
367+
fi
368+
}
369+
370+
# Call the change_ownership function
371+
change_ownership "$EXTRACT_DIR"

0 commit comments

Comments
 (0)