-
Notifications
You must be signed in to change notification settings - Fork 0
Added a new script to restart the services gressfully #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| appVersion: 1.8.0.1015 | ||
| appVersion: 1.8.1.1016 | ||
| maxCount : 7500000 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SERVICES=("spring-loaded-switch-php.service" "spring-loaded-switch-python.service") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Checking status before restart..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for SERVICE in "${SERVICES[@]}"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Status of $SERVICE:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo systemctl status "$SERVICE" --no-pager | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "-----------------------------" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Restarting services..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for SERVICE in "${SERVICES[@]}"; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ! sudo systemctl restart "$SERVICE"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "ERROR: Failed to restart $SERVICE" >&2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+18
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Restarting services..." | |
| for SERVICE in "${SERVICES[@]}"; do | |
| if ! sudo systemctl restart "$SERVICE"; then | |
| echo "ERROR: Failed to restart $SERVICE" >&2 | |
| fi | |
| done | |
| echo "Restarting services..." | |
| FAILED=0 | |
| for SERVICE in "${SERVICES[@]}"; do | |
| if ! sudo systemctl restart "$SERVICE"; then | |
| echo "ERROR: Failed to restart $SERVICE" >&2 | |
| FAILED=1 | |
| fi | |
| done | |
| if [ "$FAILED" -ne 0 ]; then | |
| echo "One or more services failed to restart." >&2 | |
| exit 1 | |
| fi |
Copilot
AI
Sep 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script continues processing remaining services even when a service fails to restart. Consider adding exit 1 after the error message to halt execution on failure, or implement a flag to track failures and exit with an error code at the end.
| echo "Restarting services..." | |
| for SERVICE in "${SERVICES[@]}"; do | |
| if ! sudo systemctl restart "$SERVICE"; then | |
| echo "ERROR: Failed to restart $SERVICE" >&2 | |
| fi | |
| done | |
| echo "Restarting services..." | |
| FAILED=0 | |
| for SERVICE in "${SERVICES[@]}"; do | |
| if ! sudo systemctl restart "$SERVICE"; then | |
| echo "ERROR: Failed to restart $SERVICE" >&2 | |
| FAILED=1 | |
| fi | |
| done | |
| if [ "$FAILED" -ne 0 ]; then | |
| echo "One or more services failed to restart. Exiting with error." >&2 | |
| exit 1 | |
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script lacks error handling options. Consider adding
set -euo pipefailafter the shebang to make the script exit on errors, undefined variables, and pipe failures for more robust execution.