File: ctdb.init

package info (click to toggle)
samba 2:4.5.16+dfsg-1+deb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 119,272 kB
  • sloc: ansic: 1,353,805; xml: 120,204; python: 119,437; sh: 36,510; perl: 29,946; asm: 3,281; yacc: 2,332; cpp: 2,225; ada: 1,681; exp: 1,582; makefile: 1,365; pascal: 1,089; cs: 879; lex: 603; awk: 118; csh: 58; sed: 45
file content (175 lines) | stat: -rwxr-xr-x 3,809 bytes parent folder | download
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/sh

# Start and stop CTDB (Clustered TDB daemon)
#
# chkconfig: - 90 01
#
# description: Starts and stops CTDB
# pidfile: /var/run/ctdb/ctdbd.pid
# config: /etc/sysconfig/ctdb

### BEGIN INIT INFO
# Provides:            ctdb
# Required-Start:      $local_fs $syslog $network $remote_fs
# Required-Stop:       $local_fs $syslog $network $remote_fs
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   start and stop ctdb service
# Description:         Start and stop CTDB (Clustered TDB daemon)
### END INIT INFO

# Source function library.
if [ -f /etc/init.d/functions ] ; then
    # Red Hat
    . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
    # Red Hat
    . /etc/rc.d/init.d/functions
elif [ -f /etc/rc.status ] ; then
    # SUSE
    . /etc/rc.status
    rc_reset
    LC_ALL=en_US.UTF-8
elif [ -f /lib/lsb/init-functions ] ; then
    # Debian
    . /lib/lsb/init-functions
fi

# Avoid using root's TMPDIR
unset TMPDIR

[ -n "$CTDB_BASE" ] || export CTDB_BASE="/etc/ctdb"

. "${CTDB_BASE}/functions"
loadconfig "network"
loadconfig "ctdb"

# check networking is up (for redhat)
if [ "$NETWORKING" = "no" ] ; then
    exit 0
fi

detect_init_style
export CTDB_INIT_STYLE

ctdbd="${CTDBD:-/usr/sbin/ctdbd}"
ctdbd_wrapper="${CTDBD_WRAPPER:-/usr/sbin/ctdbd_wrapper}"
pidfile="${CTDB_PIDFILE:-/var/run/ctdb/ctdbd.pid}"

############################################################

start()
{
    printf "Starting ctdbd service: "

    case "$CTDB_INIT_STYLE" in
	suse)
	    startproc \
		"$ctdbd_wrapper" "$pidfile" "start"
	    rc_status -v
	    ;;
	redhat)
	    daemon --pidfile "$pidfile" \
		"$ctdbd_wrapper" "$pidfile" "start"
	    RETVAL=$?
	    echo
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/ctdb || RETVAL=1
	    return $RETVAL
	    ;;
	debian)
	    eval start-stop-daemon --start --quiet --background --exec \
		"$ctdbd_wrapper" "$pidfile" "start"
	    ;;
    esac
}

stop()
{
    printf "Shutting down ctdbd service: "

    case "$CTDB_INIT_STYLE" in
	suse)
	    "$ctdbd_wrapper" "$pidfile" "stop"
	    rc_status -v
	    ;;
	redhat)
	    "$ctdbd_wrapper" "$pidfile" "stop"
	    RETVAL=$?
	    # Common idiom in Red Hat init scripts - success() always
	    # succeeds so this does behave like if-then-else
	    # shellcheck disable=SC2015
            [ $RETVAL -eq 0 ] && success || failure
	    echo ""
	    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ctdb
	    return $RETVAL
	    ;;
	debian)
	    "$ctdbd_wrapper" "$pidfile" "stop"
	    log_end_msg $?
	    ;;
    esac
}

restart()
{
    stop
    start
}

check_status ()
{
    # Backward compatibility.  When we arrange to pass --pidfile to
    # ctdbd we also create the directory that will contain it.  If
    # that directory is missing then we don't use the pidfile to check
    # status.  Note that this probably won't work if
    # $CTDB_VALGRIND="yes" but this doesn't need full backward
    # compatibility because it is a debug option.
    _d=$(dirname "$pidfile")
    if [ -d "$_d" ] ; then
	_pf_opt="-p $pidfile"
    else
	_pf_opt=""
    fi

    case "$CTDB_INIT_STYLE" in
	suse)
	    checkproc $_pf_opt "$ctdbd"
	    rc_status -v
	    ;;
	redhat)
	    status $_pf_opt -l "ctdb" "$ctdbd"
	    ;;
	debian)
	    status_of_proc $_pf_opt "$ctdbd" "ctdb"
	    ;;
    esac
}

############################################################

case "$1" in
    start)
  	start
	;;
    stop)
  	stop
	;;
    restart|reload|force-reload)
  	restart
	;;
    status)
  	check_status
	;;
    condrestart|try-restart)
  	if check_status >/dev/null ; then
	    restart
	fi
	;;
    cron)
	# used from cron to auto-restart ctdb
  	check_status >/dev/null 2>&1 || restart
	;;
    *)
	echo "Usage: $0 {start|stop|restart|reload|force-reload|status|cron|condrestart|try-restart}"
	exit 1
esac