]> git.pld-linux.org Git - packages/ucarp.git/blame - ucarp.init
rel 4; systemd support
[packages/ucarp.git] / ucarp.init
CommitLineData
bd9e9bfb 1#!/bin/sh
2#
3# ucarp Start/stop the UCARP daemon.
4#
5# chkconfig: 2345 11 89
6#
7# description: UCARP is Common Address Redundancy Protocol (CARP) \
8# for Unix
9#
10
11# Get service config
12[ -f /etc/sysconfig/ucarp ] && . /etc/sysconfig/ucarp
13
14CONFIG_VIRTUAL_IPS=$VIRTUAL_IPS
15
16[ -n "$2" ] && VIRTUAL_IPS="$2"
17
18# no virtual IPs. exit silently
19if [ -z "$VIRTUAL_IPS" ]; then
20 case "$1" in
21 start|stop|restart|reload|force-reload)
22 exit 0
23 ;;
24 esac
25fi
26
27# Source function library
28. /etc/rc.d/init.d/functions
29
30# Source networking configuration.
31. /etc/sysconfig/network
32
33# Check that networking is up.
34if is_yes "${NETWORKING}"; then
35 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
36 msg_network_down UCARP
37 exit 1
38 fi
39else
40 exit 0
41fi
42
43# check if the virtual ip $1 s up
44vipup() {
45 local vip="$1"
46 local pidfile=/var/run/ucarp/$vip.pid
47 local pid=$(cat $pidfile 2>/dev/null)
48 kill -0 $pid 2>/dev/null
49 return $?
50}
51
52# check if all the configured virtual IPs are up
53vipsup() {
54 ret=0
55 for vip in $CONFIG_VIRTUAL_IPS; do
56 vipup $vip && continue
57 ret=1
58 done
59 return $ret
60}
61
62# check if any of the configured interfaces is up
63anyvipsup() {
64 ret=1
65 for vip in $CONFIG_VIRTUAL_IPS; do
66 vipup $vip && return 0
67 done
68 return $ret
69}
70
71start() {
72 # Check if the service is already running?
73 if ! vipsup; then
74 msg_starting "UCARP"; started
75 for vip in $VIRTUAL_IPS; do
76 config="/etc/ucarp/$vip.conf"
77 if [ ! -f "$config" ]; then
78 nls "Invalid virtual IP \`%s': missing config: %s" $vip "$config"
79 fail
80 RET=1
81 else
82 UCARP_OPTS=""
83 . $config
84 show "Starting UCARP for virtual IP %s" "$vip"
85 if vipup $vip; then
86 started
87 continue
88 fi
89 # Needed for makepid work
90 RC_LOGGING=no
91 daemon --makepid --fork --pidfile /var/run/ucarp/$vip.pid \
92 /usr/sbin/ucarp --addr=${vip} ${UCARP_OPTS}
93 RET=$?
94 fi
95 [ $RETVAL -eq 0 ] && RETVAL=$RET
96 done
97 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ucarp
98 else
99 msg_already_running "UCARP"
100 fi
101}
102
103stop() {
104 if anyvipsup; then
105 # Stop daemons.
106 msg_stopping "UCARP"; started
107 for vip in $VIRTUAL_IPS; do
108 pidfile=/var/run/ucarp/$vip.pid
109 [ -f "$pidfile" ] || continue
110 pid=`cat "$pidfile"`
111 show "Stopping UCARP for virtual IP %s" "$vip"; busy
112 killproc --pidfile "$pidfile" || err=1
113 rm -f "$pidfile" >/dev/null 2>&1
114 done
115 anyvipsup || rm -f /var/lock/subsys/ucarp >/dev/null 2>&1
116 else
117 msg_not_running "UCARP"
118 fi
119}
120
121RETVAL=0
122# See how we were called.
123case "$1" in
124 start)
125 start
126 ;;
127 stop)
128 stop
129 ;;
130 reload|force-reload)
131 if vipsup; then
132 msg_reloading "UCARP"; started
133 for vip in $VIRTUAL_IPS; do
134 show "Reloading UCARP for virtual IP %s" "$vip"
135 killproc --pidfile ucarp/$vip.pid ucarp -HUP
136 [ $? -ne 0 -a $RETVAL -eq 0 ] && RETVAL=7
137 done
138 else
139 msg_not_running "UCARP"
140 exit 7
141 fi
142 ;;
143 restart)
144 stop
145 sleep 1
146 start
147 exit $?
148 ;;
149 status)
150 nls "Configured virtual IPs:"
151 echo " $VIRTUAL_IPS"
152 nls "Currently active virtual IPs:"
153 for pidfile in /var/run/ucarp/*.pid; do
154 [ -f "$pidfile" ] || continue
155 vip=${pidfile#/var/run/ucarp/}
156 vip=${vip%.pid}
157 vipup $vip && echo -n " $vip($(cat $pidfile))"
158 done
159 echo ""
160 vipsup
161 exit $?
162 ;;
163 *)
164 msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
165 exit 3
166 ;;
167esac
168
169exit $RETVAL
This page took 0.087752 seconds and 4 git commands to generate.