Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti.initd.in @ 47834a4f

History | View | Annotate | Download (2.8 kB)

1
#!/bin/sh
2
# ganeti daemons init script
3
#
4
# chkconfig: 2345 99 01
5
# description: Ganeti Cluster Manager
6
### BEGIN INIT INFO
7
# Provides:          ganeti
8
# Required-Start:    $syslog $remote_fs
9
# Required-Stop:     $syslog $remote_fs
10
# Default-Start:     2 3 4 5
11
# Default-Stop:      0 1 6
12
# Short-Description: Ganeti Cluster Manager
13
# Description:       Ganeti Cluster Manager
14
### END INIT INFO
15

    
16
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
17
DESC="Ganeti cluster"
18

    
19
DAEMON_UTIL=@PKGLIBDIR@/daemon-util
20

    
21
SCRIPTNAME="@SYSCONFDIR@/init.d/ganeti"
22

    
23
test -f "$DAEMON_UTIL" || exit 0
24

    
25
if [ -r /lib/lsb/init-functions ]; then
26
  . /lib/lsb/init-functions
27
elif [ -r /etc/rc.d/init.d/functions ]; then
28
  . /etc/rc.d/init.d/functions
29
else
30
  echo "Unable to find init functions"
31
  exit 1
32
fi
33

    
34
check_exitcode() {
35
    RC=$1
36

    
37
    if errmsg=$($DAEMON_UTIL check-exitcode $RC)
38
    then
39
        log_action_end_msg 0 "$errmsg"
40
    else
41
        log_action_end_msg 1 "$errmsg"
42
    fi
43
}
44

    
45
start_action() {
46
    # called as start_action daemon-name
47
    local daemon="$1"
48
    log_action_begin_msg "$daemon"
49
    $DAEMON_UTIL start "$@"
50
    check_exitcode $?
51
}
52

    
53
stop_action() {
54
    # called as stop_action daemon-name
55
    local daemon="$1"
56
    log_action_begin_msg "$daemon"
57
    $DAEMON_UTIL stop "$@"
58
    check_exitcode $?
59
}
60

    
61
maybe_do() {
62
    requested="$1"; shift
63
    action="$1"; shift
64
    target="$1"
65
    if [ -z "$requested" -o "$requested" = "$target" ]; then
66
        $action "$@"
67
    fi
68
}
69

    
70
start_all() {
71
    if ! $DAEMON_UTIL check-config; then
72
        log_warning_msg "Incomplete configuration, will not run."
73
        exit 0
74
    fi
75

    
76
    for i in $($DAEMON_UTIL list-start-daemons); do
77
        maybe_do "$1" start_action $i
78
    done
79
}
80

    
81
stop_all() {
82
    for i in $($DAEMON_UTIL list-stop-daemons); do
83
        maybe_do "$1" stop_action $i
84
    done
85
}
86

    
87
status_all() {
88
    local daemons="$1" status ret
89

    
90
    if [ -z "$daemons" ]; then
91
      daemons=$($DAEMON_UTIL list-start-daemons)
92
    fi
93

    
94
    status=0
95

    
96
    for i in $daemons; do
97
      if status_of_proc $($DAEMON_UTIL daemon-executable $i) $i; then
98
          ret=0
99
      else
100
          ret=$?
101
          # Use exit code from first failed call
102
          if [ "$status" -eq 0 ]; then
103
              status=$ret
104
          fi
105
      fi
106
    done
107

    
108
    exit $status
109
}
110

    
111
if [ -n "$2" ] && ! errmsg=$($DAEMON_UTIL is-daemon-name "$2" 2>&1); then
112
    log_failure_msg "$errmsg"
113
    exit 1
114
fi
115

    
116
case "$1" in
117
    start)
118
        log_daemon_msg "Starting $DESC" "$2"
119
        start_all "$2"
120
        ;;
121
    stop)
122
        log_daemon_msg "Stopping $DESC" "$2"
123
        stop_all "$2"
124
        ;;
125
    restart|force-reload)
126
        log_daemon_msg "Restarting $DESC" "$2"
127
        stop_all "$2"
128
        start_all "$2"
129
        ;;
130
    status)
131
        status_all "$2"
132
        ;;
133
    *)
134
        log_success_msg "Usage: $SCRIPTNAME {start|stop|force-reload|restart}"
135
        exit 1
136
        ;;
137
esac
138

    
139
exit 0