Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions check_gcode_monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,23 @@ print_header() {
echo "[$(timestamp)] $1"
}

send_alert() {
local title="$1"
local body="$2"
local urgency="${3:-critical}"
# Desktop notification (works if DISPLAY/DBUS available)
if command -v notify-send &>/dev/null; then
notify-send --urgency="$urgency" "$title" "$body" 2>/dev/null || true
fi
print_header "ALERT: $title - $body"
}

check_service_status() {
if systemctl is-active --quiet "${SERVICE_NAME}"; then
print_header "Service ${SERVICE_NAME} is active."
else
print_header "ERROR: Service ${SERVICE_NAME} is not active."
send_alert "GCode Monitor Down" "Service ${SERVICE_NAME} is not active"
systemctl status "${SERVICE_NAME}" --no-pager
exit 1
fi
Expand Down Expand Up @@ -52,6 +64,7 @@ check_recent_errors() {
print_header "Scanning journal for recent errors..."
if journalctl -u "${SERVICE_NAME}" --since "30 minutes ago" | grep -qi "error"; then
print_header "ERROR: Recent errors detected in journal."
send_alert "GCode Monitor Errors" "Recent errors detected in journal for ${SERVICE_NAME}"
journalctl -u "${SERVICE_NAME}" --since "30 minutes ago"
exit 1
else
Expand Down
5 changes: 4 additions & 1 deletion config.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Note: config.local is git-ignored for security

# Local machine settings
WATCH_DIR="$HOME/Desktop" # Directory to monitor for .gcode files
WATCH_DIR="$HOME/Desktop" # Directory to monitor for .gcode files (comma-separated for multiple dirs)
LOG_FILE="$HOME/.gcode_sync.log" # Log file location

# Raspberry Pi connection settings
Expand All @@ -12,6 +12,9 @@ REMOTE_HOST="192.168.1.100" # IP address or hostname of your Raspberry P
REMOTE_PORT="22" # SSH port (default: 22)
REMOTE_PATH="/mnt/usb_share" # Path to USB gadget mount point on Pi

# Optional settings
DELETE_AFTER_SYNC="false" # Delete local file after successful sync (true/false)

# Example configurations:
# Direct connection: REMOTE_HOST="192.168.1.6" REMOTE_PORT="22"
# SSH port forwarding: REMOTE_HOST="localhost" REMOTE_PORT="9702"
Expand Down
8 changes: 4 additions & 4 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ if [ "$EUID" -ne 0 ]; then
exec sudo bash "$0" "$@"
fi

# Step 1: Copy updated service file
echo -e "${YELLOW}[1/4] Copying updated service file...${NC}"
# Step 1: Install service file via install_service.sh (template substitution)
echo -e "${YELLOW}[1/5] Installing service file...${NC}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cp "${SCRIPT_DIR}/gcode-monitor.service" /etc/systemd/system/
echo -e "${GREEN}✓ Service file updated${NC}"
bash "${SCRIPT_DIR}/install_service.sh"
echo -e "${GREEN}✓ Service file installed${NC}"
echo ""

# Step 2: Reload systemd configuration
Expand Down
8 changes: 4 additions & 4 deletions gcode-monitor.service
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ ProtectClock=true
CapabilityBoundingSet=
AmbientCapabilities=

# System call filtering - relaxed for Python compatibility
# SystemCallFilter=@system-service
# SystemCallFilter=~@privileged @resources @obsolete
# SystemCallArchitectures=native
# System call filtering
SystemCallFilter=@system-service
SystemCallFilter=~@privileged @resources @obsolete
SystemCallArchitectures=native

# Logging
StandardOutput=journal
Expand Down
5 changes: 1 addition & 4 deletions install_and_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ read -p "Install as systemd service (auto-start on boot)? [Y/n]: " install_servi

if [[ ! "$install_service" =~ ^[Nn]$ ]]; then
echo "Installing systemd service..."
sudo cp "$SCRIPT_DIR/gcode-monitor.service" /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable gcode-monitor.service
sudo systemctl start gcode-monitor.service
sudo bash "$SCRIPT_DIR/install_service.sh"

echo -e "${GREEN}✓ Service installed and started${NC}"
echo
Expand Down
Loading
Loading