summarylogtreecommitdiffstats
path: root/initscript_openrc
blob: 689884e9e9d1ceea2b3581ae9b8ada6eb86a07a4 (plain)
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
#!/usr/bin/openrc-run
# OpenRC wwwoffle script

## The controlling environment variable should be set within /etc/conf.d/wwwoffle!

_DAEMON="/usr/sbin/wwwoffled"
_DAEMON_ARGS=(
              -c "${WWWOFFLE_CONFIG_FILE}"
              ${WWWOFFLED_EXTRA_ARGS}
             )

extra_started_commands="reload status"

depend() {
  use logger dns
}

_check_conf_file_var() {
  if [ -z "${WWWOFFLE_CONFIG_FILE}" ]; then
    eerror "Variable 'WWWOFFLE_CONFIG_FILE' not set or empty in '/etc/conf.d/wwwoffle'".
    eerror "This variable needs to be set to the configuration file to use."
    return 1
  fi
}

start() {
  ebegin "Starting $(basename "${_DAEMON}"): Executing ${_DAEMON} ${_DAEMON_ARGS[@]}"
  _check_conf_file_var && start-stop-daemon --start --exec "${_DAEMON}" -- "${_DAEMON_ARGS[@]}"
  eend "$?"
}

stop() {
  ebegin "Stopping $(basename "${_DAEMON}")"
  start-stop-daemon --stop --exec "${_DAEMON}" || {
    sleep 1
    _pids="$(pidof "${_DAEMON}")"
    for _pid in ${_pids}; do
      kill -9 "${_pid}" &> /dev/null
    done
  }
  sleep 1
  _running="$(pidof "${_DAEMON}" | tr ' ' '\n' | wc -l)"
  if [ ${_running} -gt 0 ]; then
    eerror "Failed to stop or kill all ${_DAEMON} processes."
    eerror "Remaining processes: ${_running}."
  fi
  eend "${_running}"
}

reload() {
  ebegin "Re-reading configuration file for $(basename "${_DAEMON}")"
  _check_conf_file_var && wwwoffle -c "${WWWOFFLE_CONFIG_FILE}" -config
  eend "$?"
}

status() {
  ebegin "Querying status of $(basename "${_DAEMON}")"
  _check_conf_file_var && wwwoffle -c "${WWWOFFLE_CONFIG_FILE}" -status
  eend "$?"
}