Statistics
| Branch: | Tag: | Revision:

root / daemons / ensure-dirs.in @ 46a8da3b

History | View | Annotate | Download (1.2 kB)

1
#!/bin/bash
2

    
3
set -e
4

    
5
LIBDIR="@LOCALSTATEDIR@/lib"
6
DATADIR="${LIBDIR}/ganeti"
7
RUNDIR="@LOCALSTATEDIR@/run"
8
GNTRUNDIR="${RUNDIR}/ganeti"
9
LOGDIR="@LOCALSTATEDIR@/log"
10
GNTLOGDIR="${LOGDIR}/ganeti"
11

    
12
_fileset_owner() {
13
  case "$1" in
14
    masterd)
15
      echo "@GNTMASTERUSER@:@GNTMASTERDGROUP@"
16
      ;;
17
    confd)
18
      echo "@GNTCONFDUSER@:@GNTCONFDGROUP@"
19
      ;;
20
    rapi)
21
      echo "@GNTRAPIUSER@:@GNTRAPIGROUP@"
22
      ;;
23
    daemons)
24
      echo "@GNTMASTERUSER@:@GNTDAEMONSGROUP@"
25
      ;;
26
    *)
27
      echo "root:root"
28
      ;;
29
  esac
30
}
31

    
32
_ensure_dir() {
33
  local dir="$1"
34
  local perm="$2"
35
  local owner="$3"
36

    
37
  [ -d "${dir}" ] || mkdir "${dir}"
38
  chmod ${perm} "${dir}"
39
  chown ${owner} "${dir}"
40
}
41

    
42
_ensure_rundir() {
43
  _ensure_dir "${GNTRUNDIR}" 0775 "$(_fileset_owner "daemons")"
44
  _ensure_dir "${GNTRUNDIR}/socket" 0750 "$(_fileset_owner "daemons")"
45
}
46

    
47
_ensure_logdir() {
48
  _ensure_dir "${GNTLOGDIR}" 0770 "$(_fileset_owner "daemons")"
49

    
50
  chown $(_fileset_owner "rapi") "${GNTLOGDIR}/rapi-daemon.log"
51
}
52

    
53
_operate_while_hold() {
54
  local fn=$1
55
  local path=$2
56
  shift 2
57

    
58
  (cd "${path}";
59
   ${fn} "$@")
60
}
61

    
62
main() {
63
  _operate_while_hold "_ensure_rundir" "${RUNDIR}"
64
  _operate_while_hold "_ensure_logdir" "${LOGDIR}"
65
}
66

    
67
main "$@"