Skip to content

Commit 1b212fe

Browse files
rootactions-user
authored andcommitted
feat(install): Enhance systemd service setup guidance
- Improve post-service setup output with clear sections and details. - Display service name, file paths (service unit, config), and working directory. - Provide a list of common systemd service management commands. - Add validation to ensure the config file exists before creating the service. - Improve service start logic: check for successful start and report current running status. - Include the service's current running status and a command to edit the config file in the final installation summary. - Refine the manual test instructions in the summary for clarity. [auto-enhanced]
1 parent c677cc2 commit 1b212fe

1 file changed

Lines changed: 70 additions & 7 deletions

File tree

install.sh

100644100755
Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,13 @@ setup_autostart() {
711711
echo
712712

713713
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
714+
# Verify config file exists
715+
if [ ! -f "$CONFIG_FILE" ]; then
716+
print_color "$RED" "✗ Config file not found at: $CONFIG_FILE"
717+
print_color "$RED" " Cannot create service without configuration"
718+
return
719+
fi
720+
714721
# Create systemd service
715722
sudo tee /etc/systemd/system/$SERVICE_NAME.service > /dev/null << EOF
716723
[Unit]
@@ -736,18 +743,49 @@ EOF
736743
sudo systemctl daemon-reload
737744
sudo systemctl enable $SERVICE_NAME.service
738745

739-
print_color "$GREEN" "✓ Auto-start service created"
746+
print_color "$GREEN" "✓ Auto-start service created and enabled"
747+
748+
# Print service information
749+
echo
750+
print_color "$BLUE" "=== Service Information ==="
751+
print_color "$YELLOW" "Service name: $SERVICE_NAME"
752+
print_color "$YELLOW" "Service file: /etc/systemd/system/$SERVICE_NAME.service"
753+
print_color "$YELLOW" "Config file: $CONFIG_FILE"
754+
print_color "$YELLOW" "Working directory: $SCRIPT_DIR"
755+
echo
740756

741757
safe_read "Start the service now? (Y/n): " "-n 1 -r" "Y"
742758
echo
743759
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
744-
sudo systemctl start $SERVICE_NAME.service
745-
print_color "$GREEN" "✓ Service started"
760+
if sudo systemctl start $SERVICE_NAME.service; then
761+
print_color "$GREEN" "✓ Service started successfully"
762+
763+
# Wait a moment for service to initialize
764+
sleep 2
765+
766+
# Check if service is running
767+
if systemctl is-active --quiet $SERVICE_NAME.service; then
768+
print_color "$GREEN" "✓ Service is running"
769+
else
770+
print_color "$RED" "⚠ Service may have failed to start"
771+
print_color "$YELLOW" "Check logs with: sudo journalctl -u $SERVICE_NAME -n 50"
772+
fi
773+
else
774+
print_color "$RED" "✗ Failed to start service"
775+
fi
746776
echo
747-
print_color "$YELLOW" "Check service status with: sudo systemctl status $SERVICE_NAME"
748-
print_color "$YELLOW" "View logs with: sudo journalctl -u $SERVICE_NAME -f"
749777
fi
750778

779+
# Print management commands
780+
print_color "$BLUE" "=== Service Management Commands ==="
781+
print_color "$YELLOW" "View status: sudo systemctl status $SERVICE_NAME"
782+
print_color "$YELLOW" "Stop service: sudo systemctl stop $SERVICE_NAME"
783+
print_color "$YELLOW" "Start service: sudo systemctl start $SERVICE_NAME"
784+
print_color "$YELLOW" "Restart: sudo systemctl restart $SERVICE_NAME"
785+
print_color "$YELLOW" "View logs: sudo journalctl -u $SERVICE_NAME -f"
786+
print_color "$YELLOW" "Disable boot: sudo systemctl disable $SERVICE_NAME"
787+
print_color "$YELLOW" "Enable boot: sudo systemctl enable $SERVICE_NAME"
788+
751789
# Update config to reflect auto-start
752790
if command -v jq &> /dev/null; then
753791
jq '.auto_start = true' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
@@ -819,11 +857,36 @@ print_summary() {
819857

820858
if systemctl is-enabled $SERVICE_NAME &> /dev/null; then
821859
print_color "$GREEN" "✓ Auto-start: Enabled"
860+
861+
# Check if service is currently running
862+
if systemctl is-active --quiet $SERVICE_NAME.service; then
863+
print_color "$GREEN" "✓ Service Status: Running"
864+
else
865+
print_color "$YELLOW" "⚠ Service Status: Not running"
866+
fi
867+
fi
868+
869+
echo
870+
print_color "$YELLOW" "Configuration & Service Details:"
871+
echo "• Config file: $CONFIG_FILE"
872+
echo "• Working directory: $SCRIPT_DIR"
873+
echo "• Edit config: nano $CONFIG_FILE"
874+
875+
if systemctl is-enabled $SERVICE_NAME &> /dev/null; then
876+
echo "• Service name: $SERVICE_NAME"
877+
echo "• Service file: /etc/systemd/system/$SERVICE_NAME.service"
878+
echo
879+
print_color "$YELLOW" "Service Commands:"
880+
echo "• Check status: sudo systemctl status $SERVICE_NAME"
881+
echo "• View logs: sudo journalctl -u $SERVICE_NAME -f"
882+
echo "• Restart: sudo systemctl restart $SERVICE_NAME"
883+
echo "• Stop: sudo systemctl stop $SERVICE_NAME"
822884
fi
823885

824886
echo
825-
print_color "$YELLOW" "Next steps:"
826-
echo "1. Test your setup:"
887+
print_color "$YELLOW" "Test your setup:"
888+
echo "1. Manual test:"
889+
echo " cd $SCRIPT_DIR"
827890
echo " python3 publish.py --config $CONFIG_FILE"
828891
echo
829892
echo "2. View all options:"

0 commit comments

Comments
 (0)