Revision 4b42c3d6

b/daemons/daemon-util.in
45 45
  . $defaults_file
46 46
fi
47 47

  
48
# Meant to facilitate use utilities in /etc/rc.d/init.d/functions in case
49
# start-stop-daemon is not available.
50
_ignore_error() {
51
  eval "$@" || :
52
}
53

  
48 54
_daemon_pidfile() {
49 55
  echo "@LOCALSTATEDIR@/run/ganeti/$1.pid"
50 56
}
......
176 182
  fi
177 183

  
178 184
  local name="$1"; shift
179

  
180
  start-stop-daemon --stop --signal 0 --quiet \
181
    --pidfile $(_daemon_pidfile $name)
185
  local pidfile=$(_daemon_pidfile $name)
186
  local daemonexec=$(_daemon_executable $name)
187

  
188
  if type -p start-stop-daemon >/dev/null; then
189
    start-stop-daemon --stop --signal 0 --quiet \
190
      --pidfile $pidfile
191
  else
192
    _ignore_error status \
193
      -p $pidfile \
194
      $daemonexec
195
  fi
182 196
}
183 197

  
184 198
# Starts a daemon
......
189 203
  fi
190 204

  
191 205
  local name="$1"; shift
206
  local pidfile=$(_daemon_pidfile $name)
207
  local usergroup=$(_daemon_usergroup $plain_name)
208
  local daemonexec=$(_daemon_executable $name)
192 209

  
193 210
  if [[ "$name" == ganeti-confd &&
194 211
        "@CUSTOM_ENABLE_CONFD@" == False ]]; then
......
205 222

  
206 223
  @PKGLIBDIR@/ensure-dirs
207 224

  
208
  start-stop-daemon --start --quiet --oknodo \
209
    --pidfile $(_daemon_pidfile $name) \
210
    --startas $(_daemon_executable $name) \
211
    --chuid $(_daemon_usergroup $plain_name) \
212
    -- $args "$@"
225
  if type -p start-stop-daemon >/dev/null; then
226
    start-stop-daemon --start --quiet --oknodo \
227
      --pidfile $pidfile \
228
      --startas $daemonexec \
229
      --chuid $usergroup \
230
      -- $args "$@"
231
  else
232
    # TODO: Find a way to start daemon with a group, until then the group must
233
    # be removed
234
    _ignore_error daemon \
235
      --pidfile $pidfile \
236
      --user ${usergroup%:*} \
237
      $daemonexec $args "$@"
238
  fi
213 239
}
214 240

  
215 241
# Stops a daemon
......
220 246
  fi
221 247

  
222 248
  local name="$1"; shift
249
  local pidfile=$(_daemon_pidfile $name)
223 250

  
224
  start-stop-daemon --stop --quiet --oknodo --retry 30 \
225
    --pidfile $(_daemon_pidfile $name)
251
  if type -p start-stop-daemon >/dev/null; then
252
    start-stop-daemon --stop --quiet --oknodo --retry 30 \
253
      --pidfile $pidfile
254
  else
255
    _ignore_error killproc -p $pidfile $name
256
  fi
226 257
}
227 258

  
228 259
# Starts a daemon if it's not yet running
......
275 306
  @RPL_SSH_INITD_SCRIPT@ restart
276 307
}
277 308

  
309
# Read @SYSCONFDIR@/rc.d/init.d/functions if start-stop-daemon not available
310
if ! type -p start-stop-daemon >/dev/null && \
311
   [[ -f @SYSCONFDIR@/rc.d/init.d/functions ]]; then
312
  _ignore_error . @SYSCONFDIR@/rc.d/init.d/functions
313
fi
314

  
278 315
if [[ "$#" -lt 1 ]]; then
279 316
  echo "Usage: $0 <action>" >&2
280 317
  exit 1

Also available in: Unified diff