update
This commit is contained in:
92
services/setup_matrix_services.sh
Normal file
92
services/setup_matrix_services.sh
Normal file
@@ -0,0 +1,92 @@
|
||||
#!/bin/bash
|
||||
# File: /var/www/moduleair_pro_4g/services/setup_matrix_services.sh
|
||||
# Purpose: Set up LED matrix boot display service (runs once at boot)
|
||||
# to install:
|
||||
# sudo chmod +x /var/www/moduleair_pro_4g/services/setup_matrix_services.sh
|
||||
# sudo /var/www/moduleair_pro_4g/services/setup_matrix_services.sh
|
||||
|
||||
echo "Setting up moduleair boot display service..."
|
||||
|
||||
# Create directory for logs if it doesn't exist
|
||||
mkdir -p /var/www/moduleair_pro_4g/logs
|
||||
|
||||
|
||||
# Create service file for LED Matrix Boot Display (one-shot at boot)
|
||||
cat > /etc/systemd/system/moduleair-matrix-boot.service << 'EOL'
|
||||
[Unit]
|
||||
Description=moduleair LED Matrix Boot Display Service (runs once)
|
||||
After=network.target
|
||||
After=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/var/www/moduleair_pro_4g/matrix/imageScreen/image_split_boot /var/www/moduleair_pro_4g/matrix/imageScreen/ModuleAir128x64.png
|
||||
User=root
|
||||
WorkingDirectory=/var/www/moduleair_pro_4g/matrix/imageScreen/
|
||||
StandardOutput=append:/var/www/moduleair_pro_4g/logs/matrix_boot_service.log
|
||||
StandardError=append:/var/www/moduleair_pro_4g/logs/matrix_boot_service_errors.log
|
||||
TimeoutStartSec=30s
|
||||
RemainAfterExit=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
# Compile the boot version of the program
|
||||
echo "Compiling boot version of image_split..."
|
||||
cd /var/www/moduleair_pro_4g/matrix/imageScreen/
|
||||
|
||||
# Make sure we have the boot version source file
|
||||
if [ ! -f "image_split_boot.cc" ]; then
|
||||
echo "Creating image_split_boot.cc from provided code..."
|
||||
# The code will be created separately as image_split_boot.cc
|
||||
echo "Please save the boot version code as image_split_boot.cc first"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Compile the boot version
|
||||
g++ -I/var/www/moduleair_pro_4g/matrix/include -L/var/www/moduleair_pro_4g/matrix/lib \
|
||||
/var/www/moduleair_pro_4g/matrix/imageScreen/image_split_boot.cc \
|
||||
-o /var/www/moduleair_pro_4g/matrix/imageScreen/image_split_boot \
|
||||
-lrgbmatrix `GraphicsMagick++-config --cppflags --libs`
|
||||
|
||||
# Check if compilation was successful
|
||||
if [ ! -f "image_split_boot" ]; then
|
||||
echo "Compilation failed! Please check dependencies and try again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make sure the matrix executable has proper permissions
|
||||
echo "Setting permissions for LED matrix boot executable..."
|
||||
chmod +x /var/www/moduleair_pro_4g/matrix/imageScreen/image_split_boot
|
||||
|
||||
# Reload systemd to recognize new service
|
||||
systemctl daemon-reload
|
||||
|
||||
# Enable the boot service
|
||||
echo "Enabling boot display service..."
|
||||
systemctl enable moduleair-matrix-boot.service
|
||||
|
||||
echo "Setup complete!"
|
||||
echo ""
|
||||
echo "LED Matrix Boot Display will:"
|
||||
echo " - Run once at boot after network and multi-user target"
|
||||
echo " - Show 3-second split reveal animation"
|
||||
echo " - Display image for 5 seconds"
|
||||
echo " - Exit automatically (total ~8 seconds)"
|
||||
echo ""
|
||||
echo "To test the service manually:"
|
||||
echo " sudo systemctl start moduleair-matrix-boot.service"
|
||||
echo ""
|
||||
echo "To check the status:"
|
||||
echo " sudo systemctl status moduleair-matrix-boot.service"
|
||||
echo ""
|
||||
echo "To view logs:"
|
||||
echo " sudo journalctl -u moduleair-matrix-boot.service"
|
||||
echo " tail -f /var/www/moduleair_pro_4g/logs/matrix_boot_service.log"
|
||||
echo ""
|
||||
echo "To disable boot display:"
|
||||
echo " sudo systemctl disable moduleair-matrix-boot.service"
|
||||
echo ""
|
||||
echo "Note: The old repeating matrix display timer has been disabled."
|
||||
echo "If you want to re-enable it, run the original setup_services.sh script."
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# File: /var/www/moduleair_pro_4g/services/setup_services.sh
|
||||
# Purpose: Set up all systemd services for moduleair data collection
|
||||
# Purpose: Set up all systemd services for moduleair data collection and LED matrix display
|
||||
# to install:
|
||||
# sudo chmod +x /var/www/moduleair_pro_4g/services/setup_services.sh
|
||||
# sudo /var/www/moduleair_pro_4g/services/setup_services.sh
|
||||
@@ -205,24 +205,76 @@ AccuracySec=1h
|
||||
WantedBy=timers.target
|
||||
EOL
|
||||
|
||||
# Create service and timer files for LED Matrix Display
|
||||
cat > /etc/systemd/system/moduleair-matrix-display.service << 'EOL'
|
||||
[Unit]
|
||||
Description=moduleair LED Matrix Display Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/var/www/moduleair_pro_4g/matrix/imageScreen/image_split /var/www/moduleair_pro_4g/matrix/imageScreen/ModuleAir128x64.png
|
||||
User=root
|
||||
WorkingDirectory=/var/www/moduleair_pro_4g/matrix/imageScreen/
|
||||
StandardOutput=append:/var/www/moduleair_pro_4g/logs/matrix_service.log
|
||||
StandardError=append:/var/www/moduleair_pro_4g/logs/matrix_service_errors.log
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOL
|
||||
|
||||
cat > /etc/systemd/system/moduleair-matrix-display.timer << 'EOL'
|
||||
[Unit]
|
||||
Description=Run moduleair LED Matrix Display every 10 seconds
|
||||
Requires=moduleair-matrix-display.service
|
||||
|
||||
[Timer]
|
||||
OnBootSec=30s
|
||||
OnUnitActiveSec=10s
|
||||
AccuracySec=1s
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
EOL
|
||||
|
||||
# Make sure the matrix executable has proper permissions
|
||||
echo "Setting permissions for LED matrix executable..."
|
||||
chmod +x /var/www/moduleair_pro_4g/matrix/imageScreen/image_split
|
||||
|
||||
# Reload systemd to recognize new services
|
||||
systemctl daemon-reload
|
||||
|
||||
# Enable and start all timers
|
||||
echo "Enabling and starting all services..."
|
||||
for service in npm envea sara bme280 co2 db-cleanup; do
|
||||
systemctl enable moduleair-$service-data.timer
|
||||
systemctl start moduleair-$service-data.timer
|
||||
echo "Started moduleair-$service-data timer"
|
||||
for service in npm envea sara bme280 co2 db-cleanup matrix-display; do
|
||||
systemctl enable moduleair-$service-data.timer 2>/dev/null || systemctl enable moduleair-$service.timer
|
||||
systemctl start moduleair-$service-data.timer 2>/dev/null || systemctl start moduleair-$service.timer
|
||||
echo "Started moduleair-$service timer"
|
||||
done
|
||||
|
||||
echo "Checking status of all timers..."
|
||||
systemctl list-timers | grep moduleair
|
||||
|
||||
echo "Setup complete. All moduleair services are now running."
|
||||
echo "To check the status of a specific service:"
|
||||
echo ""
|
||||
echo "LED Matrix Display will:"
|
||||
echo " - Start 30 seconds after boot"
|
||||
echo " - Run every 10 seconds (6s animation + 4s gap)"
|
||||
echo " - Show split reveal animation + 3s display"
|
||||
echo ""
|
||||
echo "To check the status of services:"
|
||||
echo " sudo systemctl status moduleair-npm-data.service"
|
||||
echo "To view logs for a specific service:"
|
||||
echo " sudo systemctl status moduleair-matrix-display.service"
|
||||
echo ""
|
||||
echo "To view logs for services:"
|
||||
echo " sudo journalctl -u moduleair-npm-data.service"
|
||||
echo "To restart a specific timer:"
|
||||
echo " sudo systemctl restart moduleair-npm-data.timer"
|
||||
echo " sudo journalctl -u moduleair-matrix-display.service"
|
||||
echo " tail -f /var/www/moduleair_pro_4g/logs/matrix_service.log"
|
||||
echo ""
|
||||
echo "To restart timers:"
|
||||
echo " sudo systemctl restart moduleair-npm-data.timer"
|
||||
echo " sudo systemctl restart moduleair-matrix-display.timer"
|
||||
echo ""
|
||||
echo "To disable matrix display:"
|
||||
echo " sudo systemctl stop moduleair-matrix-display.timer"
|
||||
echo " sudo systemctl disable moduleair-matrix-display.timer"
|
||||
Reference in New Issue
Block a user