From 770833f110fb81645dcc3072b8b2aa2209be90b9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 23 Oct 2025 12:50:20 +0700 Subject: [PATCH] Initial commit --- README.md | 3 +++ etc/systemd/system/monitor_test.service | 10 ++++++++++ etc/systemd/system/monitor_test.timer | 9 +++++++++ usr/local/bin/monitor_test.sh | 22 ++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 README.md create mode 100644 etc/systemd/system/monitor_test.service create mode 100644 etc/systemd/system/monitor_test.timer create mode 100755 usr/local/bin/monitor_test.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..9ef7448 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# test_example + +Effective Mobile \ No newline at end of file diff --git a/etc/systemd/system/monitor_test.service b/etc/systemd/system/monitor_test.service new file mode 100644 index 0000000..8aa62aa --- /dev/null +++ b/etc/systemd/system/monitor_test.service @@ -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 diff --git a/etc/systemd/system/monitor_test.timer b/etc/systemd/system/monitor_test.timer new file mode 100644 index 0000000..3d125e6 --- /dev/null +++ b/etc/systemd/system/monitor_test.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run Monitor Test Process every minute + +[Timer] +OnUnitActiveSec=1min +Unit=monitor_test.service + +[Install] +WantedBy=timers.target diff --git a/usr/local/bin/monitor_test.sh b/usr/local/bin/monitor_test.sh new file mode 100755 index 0000000..69839ca --- /dev/null +++ b/usr/local/bin/monitor_test.sh @@ -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