Initial commit
This commit is contained in:
commit
770833f110
10
etc/systemd/system/monitor_test.service
Normal file
10
etc/systemd/system/monitor_test.service
Normal file
@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Monitor Test Process
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/monitor_test.sh
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
9
etc/systemd/system/monitor_test.timer
Normal file
9
etc/systemd/system/monitor_test.timer
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Run Monitor Test Process every minute
|
||||
|
||||
[Timer]
|
||||
OnUnitActiveSec=1min
|
||||
Unit=monitor_test.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
22
usr/local/bin/monitor_test.sh
Executable file
22
usr/local/bin/monitor_test.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
PROCESS_NAME="test"
|
||||
LOG_FILE="/var/log/monitoring.log"
|
||||
MONITOR_URL="https://test.com/monitoring/test/api"
|
||||
|
||||
log() {
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
|
||||
}
|
||||
|
||||
if pgrep "$PROCESS_NAME" > /dev/null; then
|
||||
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$MONITOR_URL")
|
||||
if [[ "$RESPONSE" -ne 200 ]]; then
|
||||
log "Сервер мониторинга недоступен, код ответа: $RESPONSE"
|
||||
fi
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$(pgrep -c "$PROCESS_NAME")" -gt 1 ]; then
|
||||
log "Процесс '$PROCESS_NAME' был перезапущен"
|
||||
fi
|
||||
Loading…
x
Reference in New Issue
Block a user