-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_service.sh
More file actions
executable file
·123 lines (105 loc) · 2.85 KB
/
install_service.sh
File metadata and controls
executable file
·123 lines (105 loc) · 2.85 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# WolfProxy Service Installation Script
# (C) 2025 Wolf Software Systems Ltd
#
# This script installs wolfproxy as a systemd service
set -e
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo"
exit 1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="/opt/wolfproxy"
BINARY_PATH="$INSTALL_DIR/wolfproxy"
CONFIG_PATH="$INSTALL_DIR/wolfproxy.toml"
SERVICE_NAME="wolfproxy"
echo "Installing WolfProxy..."
# Create installation directory
mkdir -p "$INSTALL_DIR"
# Check if binary exists
if [ -f "$SCRIPT_DIR/target/release/wolfproxy" ]; then
cp "$SCRIPT_DIR/target/release/wolfproxy" "$BINARY_PATH"
elif [ -f "$SCRIPT_DIR/wolfproxy" ]; then
cp "$SCRIPT_DIR/wolfproxy" "$BINARY_PATH"
else
echo "Binary not found. Please build first with: cargo build --release"
exit 1
fi
chmod +x "$BINARY_PATH"
# Copy configuration if not exists
if [ ! -f "$CONFIG_PATH" ]; then
if [ -f "$SCRIPT_DIR/wolfproxy.toml" ]; then
cp "$SCRIPT_DIR/wolfproxy.toml" "$CONFIG_PATH"
else
cat > "$CONFIG_PATH" << 'EOF'
[server]
host = "0.0.0.0"
http_port = 80
https_port = 443
[nginx]
config_dir = "/etc/nginx"
auto_reload = false
EOF
fi
fi
# Create systemd service file
cat > /etc/systemd/system/${SERVICE_NAME}.service << EOF
[Unit]
Description=WolfProxy - Nginx Proxy Replacement
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=${INSTALL_DIR}
ExecStart=${BINARY_PATH}
Restart=always
RestartSec=5
Environment=RUST_LOG=info
# Security hardening
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/var/log
ReadOnlyPaths=/etc/nginx /etc/letsencrypt
# Capability for binding to privileged ports
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd
systemctl daemon-reload
echo ""
echo "Installation complete!"
echo ""
echo "Configuration file: $CONFIG_PATH"
echo ""
echo "Commands:"
echo " Start: systemctl start $SERVICE_NAME"
echo " Stop: systemctl stop $SERVICE_NAME"
echo " Status: systemctl status $SERVICE_NAME"
echo " Enable: systemctl enable $SERVICE_NAME"
echo " Logs: journalctl -u $SERVICE_NAME -f"
echo ""
echo "IMPORTANT: Before starting, make sure nginx is stopped:"
echo " systemctl stop nginx"
echo " systemctl disable nginx"
echo ""
# Ask if user wants to enable and start
read -p "Would you like to enable and start WolfProxy now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Stop nginx if running
if systemctl is-active --quiet nginx; then
echo "Stopping nginx..."
systemctl stop nginx
fi
systemctl enable $SERVICE_NAME
systemctl start $SERVICE_NAME
echo ""
echo "WolfProxy is now running!"
systemctl status $SERVICE_NAME --no-pager
fi