Skip to content

Commit

Permalink
chore: Update SystemGuard app setup script and dependencies in crontab
Browse files Browse the repository at this point in the history
  • Loading branch information
codeperfectplus committed Aug 31, 2024
1 parent daadb3f commit d10b299
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# SystemGuard
# SystemGuard 💂

System Guard is a Flask app designed to monitor server stats such as CPU, Memory, Disk, and Network. It also provides real-time monitoring capabilities which can be useful for system administrators, developers, and DevOps engineers to keep track of their server's performance and troubleshoot issues. The app uses the `psutil` library to retrieve system stats and the `speedtest-cli` library to perform a network speed test.

## Installation
## Installation 🛠️

```bash
wget https://raw.githubusercontent.com/codeperfectplus/SystemGuard/main/setup.sh
Expand Down Expand Up @@ -40,7 +40,7 @@ It will install the SystemGuard app and its dependencies in the crontab and it w

- Anaconda3/Miniconda3

## Features
## Features 🚀

- Monitor server stats like CPU, Memory, Disk, and Network.
- Check the network speed of the server using a speed test.
Expand All @@ -52,7 +52,7 @@ It will install the SystemGuard app and its dependencies in the crontab and it w
- Easy download and installation using a bash script.


## Product Screenshots
## Product Screenshots 📸

### HomePage

Expand Down
9 changes: 4 additions & 5 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ get_user_home() {
# Set paths relative to the correct user's home directory
USER_HOME=$(get_user_home)
DOWNLOAD_DIR="/tmp"
EXTRACT_DIR="$USER_HOME/.systemguard"
EXTRACT_DIR="$USER_HOME/.systemguard/"
LOG_DIR="$HOME/logs"
LOG_FILE="$LOG_DIR/systemguard-installer.log"
BACKUP_DIR="$USER_HOME/.systemguard_backup"
Expand Down Expand Up @@ -99,7 +99,6 @@ install_executable() {
# CURRENT_SCRIPT=$(realpath "$0")
cd $EXTRACT_DIR/SystemGuard-*/
CURRENT_SCRIPT=$(pwd)/$INSTALLER_SCRIPT
echo "Current script: $CURRENT_SCRIPT"
# Verify that the script exists before attempting to copy
if [ -f "$CURRENT_SCRIPT" ]; then
log "Installing executable to /usr/local/bin/systemguard-installer..."
Expand Down Expand Up @@ -139,12 +138,12 @@ install() {
log "Installing SystemGuard version $VERSION..."

# Download the SystemGuard zip file
wget -q $ZIP_URL -O $DOWNLOAD_DIR/systemguard.zip
if [ $? -ne 0 ]; then
log "Downloading SystemGuard version $VERSION from $ZIP_URL..."
if ! wget -q "$ZIP_URL" -O "$DOWNLOAD_DIR/systemguard.zip"; then
log "Error: Failed to download SystemGuard version $VERSION. Please check the version number and try again."
exit 1
fi
log "Download completed."
log "Download completed successfully."

# Backup existing configurations
backup_configs
Expand Down
51 changes: 32 additions & 19 deletions src/scripts/cronjob.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
#!/bin/bash

# Define the cron job command
username=$(whoami)
log_dir="/home/$username/logs"
mkdir -p "$log_dir"
CRON_JOB="* * * * * /bin/bash $(pwd)/dashboard.sh >> $log_dir/systemguard_cron.log 2>&1"

echo "Total cron jobs before: $(crontab -l | grep -v '^#' | wc -l)"

# Add the cron job to the crontab
(crontab -l 2>/dev/null; echo "$CRON_JOB") | crontab -

echo "Cron job added: $CRON_JOB"

# show all cron jobs ignoring comments and empty lines

echo "Total cron jobs after: $(crontab -l | grep -v '^#' | wc -l)"



# Function to add a cron job with error handling
add_cron_job() {
# Define log directory and cron job command
local username=$(whoami)
local log_dir="/home/$username/logs"
local cron_job="* * * * * /bin/bash $(pwd)/dashboard.sh >> $log_dir/systemguard_cron.log 2>&1"

# Create log directory with error handling
mkdir -p "$log_dir"
if [ $? -ne 0 ]; then
echo "Error: Failed to create log directory: $log_dir"
exit 1
fi

# Verify user retrieval
if [ -z "$username" ]; then
echo "Error: Unable to retrieve current username."
exit 1
fi

# Add cron job to crontab with error handling
(crontab -l 2>/dev/null; echo "$cron_job") | crontab -
if [ $? -ne 0 ]; then
echo "Error: Failed to add the cron job to the crontab."
exit 1
fi

echo "Cron job added: $cron_job"
}

# Call the function to add the cron job
add_cron_job

0 comments on commit d10b299

Please sign in to comment.