slackbuilds_ponce/network/haproxy/rc.haproxy
Badchay 61d912f9e6
network/haproxy: Updated for version 2.5.5.
Signed-off-by: Dave Woodfall <dave@slackbuilds.org>

Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
2022-04-16 12:12:45 +07:00

99 lines
2 KiB
Bash

#!/bin/bash
#
# Slackware initialization script for HAProxy.
#
# This script was made by T3slider.
# Slight modifications by Badchay.
#
HAPROXY=/usr/sbin/haproxy
CONFIG=/etc/haproxy/haproxy.cfg
PIDFILE=/var/run/haproxy.pid
if [[ ! -f $CONFIG && "$1" == "start" ]]; then
echo "No configuration file found. Cannot continue."
echo "The script looks for the configuration file placed in $CONFIG"
exit 1
fi
start() {
if [ -r $PIDFILE ]; then
echo 'HAProxy is already running!'
return
else
echo "Starting HAProxy..."
$HAPROXY -f $CONFIG -D -p $PIDFILE
fi
}
stop() {
if [ ! -r $PIDFILE ]; then
echo 'HAProxy is not running!'
return
fi
echo "Soft-stopping HAProxy..."
kill -USR1 `cat $PIDFILE`
# Even with the right permissions the PID file will not be removed...
rm -f $PIDFILE
}
force_stop() {
if [ ! -r $PIDFILE ]; then
echo 'HAProxy is not running!'
return
fi
echo "Hard-stopping HAProxy..."
kill `cat $PIDFILE`
# Even with the right permissions the PID file will not be removed...
rm -f $PIDFILE
}
status() {
if [ ! -r $PIDFILE ]; then
echo "HAProxy is not running."
return
fi
PID=`cat $PIDFILE`
if [ -z "$PID" ]; then
echo 'PID file is empty! HAProxy does not appear to be running, but there is a stale PID file.'
elif kill -0 $PID; then
echo "HAProxy is running."
else
echo "HAProxy is not running, but there is a stale PID file."
fi
}
checkconfig() {
$HAPROXY -c -q -V -f $CONFIG
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'force_stop')
force_stop
;;
'restart')
stop
start
;;
'force_restart')
force_stop
start
;;
'status')
status
;;
'checkconfig')
checkconfig
;;
*)
echo "Usage: $0 {start|stop|force_stop|restart|force_restart|status|checkconfig}"
exit 1
;;
esac