...
Set and Revert Log Levels: Temporarily change the log level and revert after a specified duration.
Flexible JSON Parsing: Uses
jq
for JSON parsing if available; defaults togrep
jq
otherwise.Detachable Session Execution: Runs in a detachable session using
screen
ortmux
, allowing the script to continue running independently of the terminal session.Supports Cluster and Node Log Levels: Allows setting log level at both the cluster and individual node levels.
Log File Auto-Detection: Automatically detects and adjust the
castor.log
file path forCSN
andSCS
environments.Log Size Monitoring: Reports the log size generated during the temporary log level change.
Countdown Display: Shows a countdown for the specified duration.
Requirements
jq (optional): Used for parsing JSON responses; falls back to
grep
if unavailable.screen or tmux (optional): Required for background execution.
Permissions: Ensure sufficient permissions to execute on the DataCore Swarm server and access required files.
...
Code Block |
---|
./castor-change-log-level.sh -d <node_ip> -p <admin:password> [-i <new new_log_level | -L new_node_log_level>level] [-t <duration_in_seconds>] [-D --detach] [-v] |
Parameter | Description |
---|---|
| IP address of the Swarm API endpoint (or set |
| Admin credentials in the format |
| New log level to set (values: |
| New node log level to set (values: |
| Duration in seconds to keep the new log level (optional). |
| Runs the script in a detachable session using |
...
Code Block |
---|
./castor-change-log-level.sh -d 192.168.8.84 -p admin:datacore -i 20 -t 30 --detachD |
Running the Script at a Specific Time
The at
command can used to schedule the script to run at a later time. This is useful when you need to start collecting debug logs at a specific hour.Example 4useful when you need to start collecting debug logs at a specific hour.
Example 4: Secure password prompt if password are not provided
Code Block |
---|
./castor-change-log-level.sh -p admin -d 192.168.8.84 -i 10 -t 300 |
(You will be prompted to enter the password securely.)
Example 5: Schedule the script to run at 3:00 AM on 03/02/2025 and collect debug logs for 1 hour
Ensure the at service is installed, enabled and running
Code Block dnf -y install at atd systemctl enable --now at
Schedule the script execution using
at
:Code Block echo "/root/dist/castor-change-log-level.sh -i 10 -t 3600" | at 03:00 AM 203/1602/2025
This schedules the script to run at 3:00 AM on Feb 16 2025 and collects log at debug level for 1 hour.
To verify scheduled job:
Code Block atq 7 Sun FebMar 1602 03:00:00 2025 a root
To remove a scheduled job (replace
JOB_ID
with the actual job number fromatq
output):Code Block atrm 7
...
Message | Description | ||
---|---|---|---|
| Displays the specified Swarm IP address. |
| Credentials are masked for security. |
| Displays the cluster name retrieved from the Swarm API. | ||
| Shows the new log level requested. | ||
| Displays the current log level. | ||
| Indicates the beginning of the log level update process. | ||
| Confirms that the log level was successfully updated. | ||
| Shows the temporary period for which the new log level is retained, with a countdown. | ||
| Indicates that the temporary period has ended and the script is reverting the log level. | ||
| Provides information on the amount of logging activity generated during the temporary log level. |
...
Code Block |
---|
[root@scs dist]# ./castor-change-log-level.sh -p admin:datacore -i 10 -t 300 Swarm IP: 192.168.1.84 Credentials: [hidden for security] Cluster Name: gatewayadmindomainmsuen-scs1.suen.work New log level: 10debug Current log level is 30. Updating log level to 10...default. 2025-03-02T05:15:49.901Z Log level changed successfully from 30 → 10. Keeping log level at 10debug for 300 second (s00:05:00) ... Countdown: 00:00:01 remaining... Time's up! Reverting log level back to 30... Approximate 6988.4MB9MB new logs were generated at log level 10. Current castor.log size is 371.3MB after 300 seconds (00:05:00). 2025-03-02T05:20:50.483Z Log level reverted successfully back to 30. [root@scs dist]# |
...
Missing Parameters: Missing parameters prompt a usage message.
Invalid Log Levels: If an unsupported log level is specified, the script will prompt the user to enter a valid value.
Invalid Duration: If a non-numeric duration is provided, you’re prompted to enter a valid duration in seconds.
Connection Issues: If unable to connect to the Swarm API, check the IP, credentials, and network access.
...