summaryrefslogtreecommitdiff
path: root/net/ucarp/files/ucarp.in
blob: 8dc2f7a8cb5b8c69cc2030cbcd38b3acaccca7f8 (plain) (blame)
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
#!/bin/sh
#
# Init script : ucarp for FreeBSD
# By Nico <nico@rottenbytes.info>
#
# PROVIDE: ucarp
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable & configure ucarp:
#
# ucarp_enable (bool):		Set it to "YES" to enable ucarp
#				Default is "NO".
# ucarp_if:			Set interface to use for ucarp checks
#				Default is "eth0"
# ucarp_src:			Set source (real) IP address of that host
# ucarp_vhid:			Set virtual IP identifier (1-255)
#				Default is "1"
# ucarp_pass:			Set password
#				Default is "dumbp4ss"
# ucarp_preempt (bool):		Set it to "YES" to become a master as soon as possible
#				Default is "NO"
# ucarp_addr:			Set virtual shared IP address
# ucarp_advbase:		Set advertisement frequency (seconds)
# ucarp_advskew:		Set advertisement skew (0-255)
# ucarp_upscript:		Run <file> to become a master
# ucarp_downscript:		Run <file> to become a backup
# ucarp_deadratio:		Set ratio to consider a host as dead
# ucarp_shutdown (bool):	Set it to "YES"  to call shutdown script at exit
#				Default is "YES"
# ucarp_facility:		Set syslog facility
#				Default is "daemon"

. %%RC_SUBR%%

name="ucarp"
rcvar=`set_rcvar`

load_rc_config $name

: ${ucarp_enable="NO"}
: ${ucarp_if="eth0"}
: ${ucarp_vhid="1"}
: ${ucarp_pass="dumbp4ss"}
: ${ucarp_preempt="NO"}
: ${ucarp_shutdown="YES"}
: ${ucarp_facility="daemon"}

command=%%PREFIX%%/sbin/ucarp
command_args="-i ${ucarp_if} -v ${ucarp_vhid} -p ${ucarp_pass} -f ${ucarp_facility} -B "
start_precmd="build_command_args"

build_command_args()
{
	if [ ${ucarp_preempt} = "YES" ]
	then
		command_args=${command_args}"-P "
	fi

	if [ ${ucarp_shutdown} = "YES" ]
	then
		command_args=${command_args}"-z "
	fi

	# Mandatory arguments
	if [ -z ${ucarp_src} ]
	then
		echo "source address is not set ! please set it"
		exit 1
	fi

	if [ -z ${ucarp_addr} ]
	then
		echo "virtual address is not set ! please set it"
		exit 1
	fi

	command_args=${command_args}"-s ${ucarp_src} -a ${ucarp_addr} "

	# Optional args
	if ! [ -z ${ucarp_upscript} ]
	then
		command_args=${command_args}"-u ${ucarp_upscript} "
	fi
	if ! [ -z ${ucarp_downscript} ]
	then
		command_args=${command_args}"-d ${ucarp_downscript} "
	fi
	if ! [ -z ${ucarp_deadratio} ]
	then
		command_args=${command_args}"-r ${ucarp_deadratio} "
	fi
	if ! [ -z ${ucarp_advbase} ]
	then
		command_args=${command_args}"-b ${ucarp_advbase} "
	fi
	if ! [ -z ${ucarp_advskew} ]
	then
		command_args=${command_args}"-k ${ucarp_advskew} "
	fi
}

run_rc_command "$1"