summaryrefslogtreecommitdiff
path: root/files/solaris-svc-fail2ban
blob: 96415323c68a539ee476d5ed63a4728ced3e6f86 (plain)
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
#!/usr/bin/bash -e
#
# fail2ban		This init.d script is used to start fail2ban.
# (C) by Hanno Wagner <wagner@rince.de>, License is GPL

#set -x

. /lib/svc/share/smf_include.sh

set -e


F2B_CONF="/etc/fail2ban/fail2ban.conf"
if [ -n "$2" ] && [ -f "$F2B_CONF" ]; then
  F2B_CONF="$2"
fi

ENV="/usr/bin/env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin:/opt/sfw/bin:/usr/sfw/bin"

# get socket/pid conf and check dir exists
# sock and pid default dirs are currently the same
# mkdir if it doesn't exist
SOCK_FILE=$(sed "/^\#/d" "$F2B_CONF" | grep "socket"  | tail -1 | cut -d "=" -f2-)
SOCK_DIR=$(dirname $SOCK_FILE)
if [ -n "$SOCK_DIR" ]; then
	if [ ! -d "$SOCK_DIR" ]; then
		mkdir "$SOCK_DIR" || exit 1
	fi
fi

case $1 in
	start)
		# remove any lingering sockets
		# don't quote the var for the -e test
		if [ -n "$SOCK_FILE" ]; then
			if [ -e $SOCK_FILE ]; then
				rm -f $SOCK_FILE || exit 1
			fi
		fi
		[ -f /etc/fail2ban.conf ] || touch /etc/fail2ban.conf
		echo "Starting fail2ban-server with $F2B_CONF"
		eval $ENV /usr/local/bin/fail2ban-client start &
	;;
	stop)
		echo "Stopping fail2ban-server with $F2B_CONF"
		eval $ENV /usr/local/bin/fail2ban-client stop &
	;;
	reload | refresh )
		echo "Reloading fail2ban-server with $F2B_CONF"
		eval $ENV /usr/local/bin/fail2ban-client reload &
	;;
	restart | force-reload)
		echo "Forcing reload of fail2ban-server with $F2B_CONF"
		eval $ENV /usr/local/bin/fail2ban-client stop &
		sleep 2
		eval $ENV /usr/local/bin/fail2ban-client start &
	;;
	status)
		/usr/local/bin/fail2ban-client status &
	;;
	*)
		echo "Usage: /lib/svc/method/svc-fail2ban start|stop|status|refresh|restart|reload|force-reload" >&2
		exit 2
	;;
esac