Revision 5224330e daemons/ensure-dirs.in

b/daemons/ensure-dirs.in
8 8
GNTRUNDIR="${RUNDIR}/ganeti"
9 9
LOGDIR="@LOCALSTATEDIR@/log"
10 10
GNTLOGDIR="${LOGDIR}/ganeti"
11
LOCKDIR="@LOCALSTATEDIR@/lock"
11 12

  
12 13
_fileset_owner() {
13 14
  case "$1" in
......
20 21
    rapi)
21 22
      echo "@GNTRAPIUSER@:@GNTRAPIGROUP@"
22 23
      ;;
24
    noded)
25
      echo "root:@GNTMASTERDGROUP@"
26
      ;;
23 27
    daemons)
24 28
      echo "@GNTMASTERUSER@:@GNTDAEMONSGROUP@"
25 29
      ;;
30
    masterd-confd)
31
      echo "@GNTMASTERUSER@:@GNTCONFDGROUP@"
32
      ;;
26 33
    *)
27 34
      echo "root:root"
28 35
      ;;
29 36
  esac
30 37
}
31 38

  
39
_ensure_file() {
40
  local file="$1"
41
  local perm="$2"
42
  local owner="$3"
43

  
44
  [[ -e "${file}" ]] || return 1
45
  chmod ${perm} "${file}"
46

  
47
  if ! [[ -z "${owner}" ]]; then
48
    chown ${owner} "${file}"
49
  fi
50

  
51
  return 0
52
}
53

  
32 54
_ensure_dir() {
33 55
  local dir="$1"
34 56
  local perm="$2"
35 57
  local owner="$3"
36 58

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

  
61
  _ensure_file "${dir}" "${perm}" "${owner}"
62
}
63

  
64
_gather_files() {
65
  local path="$1"
66
  local perm="$2"
67
  local user="$3"
68
  local group="$4"
69

  
70
  shift 4
71

  
72
  find "${path}" -type f "(" "!" -perm ${perm} -or "(" "!" -user ${user} -or \
73
       "!" -group ${group} ")" ")" "$@"
74
}
75

  
76
_ensure_datadir() {
77
  _ensure_dir ${DATADIR} 0755 "$(_fileset_owner masterd)"
78
  _ensure_dir ${DATADIR}/queue 0700 "$(_fileset_owner masterd)"
79
  _ensure_dir ${DATADIR}/queue/archive 0700 "$(_fileset_owner masterd)"
80
  _ensure_dir ${DATADIR}/uidpool 0750 "$(_fileset_owner noded)"
81

  
82
  # We ignore these files if they don't exists (incomplete setup)
83
  _ensure_file ${DATADIR}/cluster-domain-secret 0640 \
84
               "$(_fileset_owner masterd)" || :
85
  _ensure_file ${DATADIR}/config.data 0640 "$(_fileset_owner masterd-confd)" || :
86
  _ensure_file ${DATADIR}/hmac.key 0440 "$(_fileset_owner confd)" || :
87
  _ensure_file ${DATADIR}/known_hosts 0644 "$(_fileset_owner masterd)" || :
88
  _ensure_file ${DATADIR}/rapi.pem 0440 "$(_fileset_owner rapi)" || :
89
  _ensure_file ${DATADIR}/rapi_users 0640 "$(_fileset_owner rapi)" || :
90
  _ensure_file ${DATADIR}/server.pem 0440 "$(_fileset_owner masterd)" || :
91
  _ensure_file ${DATADIR}/queue/serial 0600 "$(_fileset_owner masterd)" || :
92

  
93
  # To not change the utils.LockFile object
94
  touch ${DATADIR}/queue/lock
95
  _ensure_file ${DATADIR}/queue/lock 0600 "$(_fileset_owner masterd)"
96

  
97
  for file in $(_gather_files ${DATADIR}/queue 0600 @GNTMASTERUSER@ \
98
                @GNTMASTERDGROUP@); do
99
    _ensure_file "${file}" 0600 "$(_fileset_owner masterd)"
100
  done
101

  
102
  for file in $(_gather_files ${DATADIR} 0600 root \
103
                @GNTMASTERDGROUP@ -name 'ssconf_*'); do
104
    _ensure_file "${file}" 0444 "$(_fileset_owner noded)"
105
  done
40 106
}
41 107

  
42 108
_ensure_rundir() {
43
  _ensure_dir "${GNTRUNDIR}" 0775 "$(_fileset_owner "daemons")"
44
  _ensure_dir "${GNTRUNDIR}/socket" 0750 "$(_fileset_owner "daemons")"
109
  _ensure_dir ${GNTRUNDIR} 0775 "$(_fileset_owner daemons)"
110
  _ensure_dir ${GNTRUNDIR}/socket 0750 "$(_fileset_owner daemons)"
111
  _ensure_dir ${GNTRUNDIR}/bdev-cache 0755 "$(_fileset_owner noded)"
112
  _ensure_dir ${GNTRUNDIR}/instance-disks 0755 "$(_fileset_owner noded)"
113
  _ensure_dir ${GNTRUNDIR}/crypto 0700 "$(_fileset_owner noded)"
114
  _ensure_dir ${GNTRUNDIR}/import-export 0755 "$(_fileset_owner noded)"
115

  
116
  # We ignore this file if it don't exists (not yet start up)
117
  _ensure_file ${GNTRUNDIR}/socket/ganeti-master 0770 \
118
               "$(_fileset_owner daemons)" || :
45 119
}
46 120

  
47 121
_ensure_logdir() {
48
  _ensure_dir "${GNTLOGDIR}" 0770 "$(_fileset_owner "daemons")"
122
  _ensure_dir ${GNTLOGDIR} 0770 "$(_fileset_owner daemons)"
123
  _ensure_dir ${GNTLOGDIR}/os 0750 "$(_fileset_owner daemons)"
124

  
125
  # We ignore these files if they don't exists (incomplete setup)
126
  _ensure_file ${GNTLOGDIR}/master-daemon.log 0600 "$(_fileset_owner masterd)" || :
127
  _ensure_file ${GNTLOGDIR}/conf-daemon.log 0600 "$(_fileset_owner confd)" || :
128
  _ensure_file ${GNTLOGDIR}/node-daemon.log 0600 "$(_fileset_owner noded)" || :
129
  _ensure_file ${GNTLOGDIR}/rapi-daemon.log 0600 "$(_fileset_owner rapi)" || :
130
}
49 131

  
50
  touch "${GNTLOGDIR}/rapi-daemon.log"
51
  chown $(_fileset_owner "rapi") "${GNTLOGDIR}/rapi-daemon.log"
132
_ensure_lockdir() {
133
  _ensure_dir ${LOCKDIR} 1777 ""
52 134
}
53 135

  
54 136
_operate_while_hold() {
......
56 138
  local path=$2
57 139
  shift 2
58 140

  
59
  (cd "${path}";
141
  (cd ${path};
60 142
   ${fn} "$@")
61 143
}
62 144

  
63 145
main() {
64
  _operate_while_hold "_ensure_rundir" "${RUNDIR}"
65
  _operate_while_hold "_ensure_logdir" "${LOGDIR}"
146
  _operate_while_hold "_ensure_datadir" ${DATADIR}
147
  _operate_while_hold "_ensure_rundir" ${RUNDIR}
148
  _operate_while_hold "_ensure_logdir" ${LOGDIR}
149
  _operate_while_hold "_ensure_lockdir" @LOCALSTATEDIR@
66 150
}
67 151

  
68 152
main "$@"

Also available in: Unified diff