簡易的 systemd 服務文件創(chuàng)建腳本
#!/bin/bash
# create_haproxy_service.sh
# 創(chuàng)建 systemd 服務文件
SERVICE_FILE="/etc/systemd/system/haproxy.service"
cat > $SERVICE_FILE << 'EOF'
[Unit]
Description=HAProxy Load Balancer
Documentation=man:haproxy(1)
After=network.target
[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg"
Environment="PIDFILE=/var/run/haproxy.pid"
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q
ExecStart=/usr/sbin/haproxy -f $CONFIG -p $PIDFILE
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
RestartSec=2
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
echo "HAProxy service file created at $SERVICE_FILE"
echo "Reloading systemd..."
systemctl daemon-reload
echo "Enabling HAProxy service..."
systemctl enable haproxy
echo "Starting HAProxy..."
systemctl start haproxy

浙公網(wǎng)安備 33010602011771號