-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathnginxctl.sh
More file actions
104 lines (92 loc) · 3.01 KB
/
Copy pathnginxctl.sh
File metadata and controls
104 lines (92 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# ==============================================================================
# NGINX Portable Instance Control Script
#
# Description: A simple script to manage a self-contained NGINX instance.
# Author: Generated for user
# ==============================================================================
# --- Configuration ---
# Set the absolute path to your NGINX installation directory.
# IMPORTANT: Do not use trailing slashes.
NGINX_HOME="/data/nginx_acme"
# --- Script Body (Do not edit below this line) ---
set -e # Exit immediately if a command exits with a non-zero status.
# Check if the NGINX home directory exists
if [ ! -d "$NGINX_HOME" ]; then
echo "Error: NGINX home directory not found at '$NGINX_HOME'"
exit 1
fi
# Change to the NGINX directory
cd "$NGINX_HOME" || exit 1
# Define the NGINX executable path
NGINX_BIN="./sbin/nginx"
NGINX_CONF="nginx.conf"
# Check if the NGINX binary exists and is executable
if [ ! -x "$NGINX_BIN" ]; then
echo "Error: NGINX binary not found or not executable at '$NGINX_BIN'"
exit 1
fi
# Function to display usage information
usage() {
echo "Usage: $0 {start|stop|quit|reload|test|status}"
echo "Commands:"
echo " start - Start NGINX (tests config first)"
echo " stop - Stop NGINX immediately (fast shutdown)"
echo " quit - Stop NGINX gracefully"
echo " reload - Reload configuration (tests config first)"
echo " test - Test NGINX configuration"
echo " status - Show NGINX process status"
exit 1
}
# Ensure an argument is provided
if [ -z "$1" ]; then
usage
fi
# Main control logic
case "$1" in
start)
echo "Testing NGINX configuration..."
if "$NGINX_BIN" -p "$(pwd)" -t -c "$NGINX_CONF"; then
echo "Configuration is OK. Starting NGINX..."
"$NGINX_BIN" -p "$(pwd)" -c "$NGINX_CONF"
echo "NGINX started."
else
echo "Error: Configuration test failed. NGINX not started."
exit 1
fi
;;
stop)
echo "Stopping NGINX (fast shutdown)..."
"$NGINX_BIN" -p "$(pwd)" -s stop
echo "NGINX stopped."
;;
quit)
echo "Stopping NGINX gracefully..."
"$NGINX_BIN" -p "$(pwd)" -s quit
echo "NGINX stopped gracefully."
;;
reload)
echo "Testing NGINX configuration..."
if "$NGINX_BIN" -p "$(pwd)" -t -c "$NGINX_CONF"; then
echo "Configuration is OK. Reloading NGINX..."
"$NGINX_BIN" -p "$(pwd)" -s reload
echo "NGINX reloaded."
else
echo "Error: Configuration test failed. NGINX not reloaded."
exit 1
fi
;;
test)
echo "Testing NGINX configuration..."
"$NGINX_BIN" -p "$(pwd)" -t -c "$NGINX_CONF"
;;
status)
echo "Checking NGINX process status..."
# The `|| true` prevents the script from exiting if grep finds nothing
ps -ef | grep nginx | grep -v grep || true
;;
*)
usage
;;
esac
exit 0