Skip to content

Commit 1194034

Browse files
chore: loggin and help function improved
1 parent 524fbaf commit 1194034

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

setup.sh

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ GIT_INSTALL_DIR="$EXTRACT_DIR/${APP_NAME}-git"
100100
LOG_DIR="$USER_HOME/logs"
101101
LOG_FILE="$LOG_DIR/systemguard-installer.log"
102102
BACKUP_DIR="$USER_HOME/.systemguard_backup"
103-
EXECUTABLE="/usr/local/bin/systemguard-installer"
103+
EXECUTABLE_APP_NAME="systemguard-installer"
104+
EXECUTABLE="/usr/local/bin/$EXECUTABLE_APP_NAME"
104105

105106
# File paths related to the application
106107
LOCUST_FILE="$EXTRACT_DIR/${APP_NAME}-*/src/scripts/locustfile.py"
107108
HOST_URL="http://localhost:5050"
108109
INSTALLER_SCRIPT='setup.sh'
110+
FLASK_LOG_FILE="$USER_HOME/logs/systemguard_flask.log"
109111

110112
# Number of backups to keep
111113
NUM_OF_BACKUP=5
@@ -203,7 +205,7 @@ add_cron_job() {
203205

204206
rm "$temp_cron"
205207
log "INFO" "Cron job added successfully"
206-
log $cron_job
208+
# log $cron_job
207209
}
208210

209211
# Function to clean up all backups
@@ -511,7 +513,7 @@ load_test() {
511513
# Check if Locust is installed
512514
if ! command -v locust &> /dev/null
513515
then
514-
log "Locust is not installed. Please install it first."
516+
log "WARNING" "Locust is not installed. Please install it first."
515517
exit 1
516518
fi
517519

@@ -557,22 +559,58 @@ health_check() {
557559
fi
558560
}
559561

562+
# app logs
563+
show_server_logs() {
564+
log "Checking server logs at $FLASK_LOG_FILE..."
565+
log "INFO" "Press Ctrl+C to exit."
566+
echo ""
567+
echo "--- Server Logs ---"
568+
echo ""
569+
if [ -f "$FLASK_LOG_FILE" ]; then
570+
tail -f "$FLASK_LOG_FILE"
571+
else
572+
log "No logs found at $FLASK_LOG_FILE."
573+
fi
574+
}
575+
560576

561577
# Display help
562578
show_help() {
563579
echo "$APP_NAME Installer"
564-
echo "Usage: ./installer.sh [options]"
580+
echo ""
581+
echo "Usage: $EXECUTABLE_APP_NAME [options]"
582+
echo ""
565583
echo "Options:"
566-
echo " --install Install $APP_NAME"
567-
echo " --uninstall Uninstall $APP_NAME"
568-
echo " --restore Restore $APP_NAME from a backup"
569-
echo " --load-test Start Locust load testing"
570-
echo " --status Check the status of $APP_NAME installation"
571-
echo " --health-check Perform a health check on localhost:5005"
572-
echo " --clean-backups Clean up all backups"
573-
echo " --help Display this help message"
584+
echo " --install Install $APP_NAME and set up all necessary dependencies."
585+
echo " This will configure the environment and start the application."
586+
echo ""
587+
echo " --uninstall Uninstall $APP_NAME completely."
588+
echo " This will remove the application and all associated files."
589+
echo ""
590+
echo " --restore Restore $APP_NAME from a backup."
591+
echo " Use this option to recover data or settings from a previous backup."
592+
echo ""
593+
echo " --load-test Start Locust load testing for $APP_NAME."
594+
echo " This will initiate performance testing to simulate multiple users."
595+
echo ""
596+
echo " --status Check the status of $APP_NAME installation."
597+
echo " Displays whether $APP_NAME is installed, running, or if there are any issues."
598+
echo ""
599+
echo " --health-check Perform a health check on $HOST_URL."
600+
echo " Verifies that the application is running correctly and responding to requests."
601+
echo ""
602+
echo " --clean-backups Clean up all backups of $APP_NAME."
603+
echo " This will delete all saved backup files to free up space."
604+
echo ""
605+
echo " --server-logs Show server logs for $APP_NAME."
606+
echo " Displays the latest server logs, which can help in troubleshooting issues."
607+
echo " Press Ctrl+C to exit the log viewing session."
608+
echo ""
609+
echo " --help Display this help message."
610+
echo " Shows information about all available options and how to use them."
574611
}
575612

613+
576614
# Parse command-line options
577615
for arg in "$@"; do
578616
case $arg in
@@ -583,6 +621,7 @@ for arg in "$@"; do
583621
--status) ACTION="check_status" ;;
584622
--health-check) ACTION="health_check" ;;
585623
--clean-backups) ACTION="cleanup_backups" ;;
624+
--server-logs) show_server_logs; exit 0 ;;
586625
--help) show_help; exit 0 ;;
587626
*) echo "Unknown option: $arg"; show_help; exit 1 ;;
588627
esac

0 commit comments

Comments
 (0)