Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 1.91 KB

File metadata and controls

55 lines (45 loc) · 1.91 KB

Nginx Monitor Script

Description:

This batch script monitors the status of the Nginx process on a Windows machine. It periodically checks whether the Nginx server is running or stopped. If Nginx is stopped, the script automatically attempts to restart it. The script logs status changes with timestamps into daily log files.

Features:

  • Checks if "nginx.exe" process is running.
  • Logs status changes only (running or stopped).
  • Automatically restarts Nginx if it is not running.
  • Creates daily log files stored in a LOG folder inside the script directory.
  • Maintains a temporary status file to detect changes.
  • Runs in an infinite loop with a 60-second delay between checks.

Folder Structure:

Assuming your script is located inside a folder named "Checker" under the main Nginx folder:

D:\Your_Path\nginx-1.28.0
├── nginx.exe └── Checker
├── monitor.bat (this script) ├── nginx_status.tmp (status file created automatically) └── LOG
└── monitor_YYYY-MM-DD.log (daily log files created automatically)

How to Use:

  1. Place this script in the "Checker" folder inside your Nginx installation directory.
  2. Run the batch file (monitor.bat).
  3. The script will continuously monitor Nginx status every 60 seconds.
  4. Check the LOG folder for daily log files with status changes.

Requirements:

  • Windows OS
  • Nginx installed and located one folder above this script's folder
  • PowerShell available (used to get date format for log file naming)

Notes:

  • The script uses delayed variable expansion, so "setlocal enabledelayedexpansion" is enabled.
  • Adjust the timeout duration by changing the "timeout /t 60" value in seconds.

This script is developed for my personal project and is not intended for commercial use. Created by: Toey Pathomkon Date: 2025-05-26