Statistics
| Branch: | Tag: | Revision:

root / daemons / ensure-dirs.in @ d9c82a4e

History | View | Annotate | Download (4.4 kB)

1 46a8da3b René Nussbaumer
#!/bin/bash
2 46a8da3b René Nussbaumer
3 46a8da3b René Nussbaumer
set -e
4 46a8da3b René Nussbaumer
5 46a8da3b René Nussbaumer
LIBDIR="@LOCALSTATEDIR@/lib"
6 46a8da3b René Nussbaumer
DATADIR="${LIBDIR}/ganeti"
7 46a8da3b René Nussbaumer
RUNDIR="@LOCALSTATEDIR@/run"
8 46a8da3b René Nussbaumer
GNTRUNDIR="${RUNDIR}/ganeti"
9 46a8da3b René Nussbaumer
LOGDIR="@LOCALSTATEDIR@/log"
10 46a8da3b René Nussbaumer
GNTLOGDIR="${LOGDIR}/ganeti"
11 5224330e René Nussbaumer
LOCKDIR="@LOCALSTATEDIR@/lock"
12 46a8da3b René Nussbaumer
13 46a8da3b René Nussbaumer
_fileset_owner() {
14 46a8da3b René Nussbaumer
  case "$1" in
15 46a8da3b René Nussbaumer
    masterd)
16 46a8da3b René Nussbaumer
      echo "@GNTMASTERUSER@:@GNTMASTERDGROUP@"
17 46a8da3b René Nussbaumer
      ;;
18 46a8da3b René Nussbaumer
    confd)
19 46a8da3b René Nussbaumer
      echo "@GNTCONFDUSER@:@GNTCONFDGROUP@"
20 46a8da3b René Nussbaumer
      ;;
21 46a8da3b René Nussbaumer
    rapi)
22 46a8da3b René Nussbaumer
      echo "@GNTRAPIUSER@:@GNTRAPIGROUP@"
23 46a8da3b René Nussbaumer
      ;;
24 5224330e René Nussbaumer
    noded)
25 5224330e René Nussbaumer
      echo "root:@GNTMASTERDGROUP@"
26 5224330e René Nussbaumer
      ;;
27 46a8da3b René Nussbaumer
    daemons)
28 46a8da3b René Nussbaumer
      echo "@GNTMASTERUSER@:@GNTDAEMONSGROUP@"
29 46a8da3b René Nussbaumer
      ;;
30 5224330e René Nussbaumer
    masterd-confd)
31 5224330e René Nussbaumer
      echo "@GNTMASTERUSER@:@GNTCONFDGROUP@"
32 5224330e René Nussbaumer
      ;;
33 46a8da3b René Nussbaumer
    *)
34 46a8da3b René Nussbaumer
      echo "root:root"
35 46a8da3b René Nussbaumer
      ;;
36 46a8da3b René Nussbaumer
  esac
37 46a8da3b René Nussbaumer
}
38 46a8da3b René Nussbaumer
39 5224330e René Nussbaumer
_ensure_file() {
40 5224330e René Nussbaumer
  local file="$1"
41 5224330e René Nussbaumer
  local perm="$2"
42 5224330e René Nussbaumer
  local owner="$3"
43 5224330e René Nussbaumer
44 5224330e René Nussbaumer
  [[ -e "${file}" ]] || return 1
45 5224330e René Nussbaumer
  chmod ${perm} "${file}"
46 5224330e René Nussbaumer
47 5224330e René Nussbaumer
  if ! [[ -z "${owner}" ]]; then
48 5224330e René Nussbaumer
    chown ${owner} "${file}"
49 5224330e René Nussbaumer
  fi
50 5224330e René Nussbaumer
51 5224330e René Nussbaumer
  return 0
52 5224330e René Nussbaumer
}
53 5224330e René Nussbaumer
54 46a8da3b René Nussbaumer
_ensure_dir() {
55 46a8da3b René Nussbaumer
  local dir="$1"
56 46a8da3b René Nussbaumer
  local perm="$2"
57 46a8da3b René Nussbaumer
  local owner="$3"
58 46a8da3b René Nussbaumer
59 5224330e René Nussbaumer
  [[ -d "${dir}" ]] || mkdir "${dir}"
60 5224330e René Nussbaumer
61 5224330e René Nussbaumer
  _ensure_file "${dir}" "${perm}" "${owner}"
62 5224330e René Nussbaumer
}
63 5224330e René Nussbaumer
64 5224330e René Nussbaumer
_gather_files() {
65 5224330e René Nussbaumer
  local path="$1"
66 5224330e René Nussbaumer
  local perm="$2"
67 5224330e René Nussbaumer
  local user="$3"
68 5224330e René Nussbaumer
  local group="$4"
69 5224330e René Nussbaumer
70 5224330e René Nussbaumer
  shift 4
71 5224330e René Nussbaumer
72 5224330e René Nussbaumer
  find "${path}" -type f "(" "!" -perm ${perm} -or "(" "!" -user ${user} -or \
73 5224330e René Nussbaumer
       "!" -group ${group} ")" ")" "$@"
74 5224330e René Nussbaumer
}
75 5224330e René Nussbaumer
76 5224330e René Nussbaumer
_ensure_datadir() {
77 b370482d René Nussbaumer
  local full_run="$1"
78 b370482d René Nussbaumer
79 5224330e René Nussbaumer
  _ensure_dir ${DATADIR} 0755 "$(_fileset_owner masterd)"
80 5224330e René Nussbaumer
  _ensure_dir ${DATADIR}/queue 0700 "$(_fileset_owner masterd)"
81 5224330e René Nussbaumer
  _ensure_dir ${DATADIR}/queue/archive 0700 "$(_fileset_owner masterd)"
82 5224330e René Nussbaumer
  _ensure_dir ${DATADIR}/uidpool 0750 "$(_fileset_owner noded)"
83 5224330e René Nussbaumer
84 5224330e René Nussbaumer
  # We ignore these files if they don't exists (incomplete setup)
85 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/cluster-domain-secret 0640 \
86 5224330e René Nussbaumer
               "$(_fileset_owner masterd)" || :
87 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/config.data 0640 "$(_fileset_owner masterd-confd)" || :
88 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/hmac.key 0440 "$(_fileset_owner confd)" || :
89 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/known_hosts 0644 "$(_fileset_owner masterd)" || :
90 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/rapi.pem 0440 "$(_fileset_owner rapi)" || :
91 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/rapi_users 0640 "$(_fileset_owner rapi)" || :
92 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/server.pem 0440 "$(_fileset_owner masterd)" || :
93 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/queue/serial 0600 "$(_fileset_owner masterd)" || :
94 5224330e René Nussbaumer
95 5224330e René Nussbaumer
  # To not change the utils.LockFile object
96 5224330e René Nussbaumer
  touch ${DATADIR}/queue/lock
97 5224330e René Nussbaumer
  _ensure_file ${DATADIR}/queue/lock 0600 "$(_fileset_owner masterd)"
98 5224330e René Nussbaumer
99 b370482d René Nussbaumer
  if ! [[ -z "${full_run}" ]]; then
100 b370482d René Nussbaumer
    for file in $(_gather_files ${DATADIR}/queue 0600 @GNTMASTERUSER@ \
101 b370482d René Nussbaumer
                  @GNTMASTERDGROUP@); do
102 b370482d René Nussbaumer
      _ensure_file "${file}" 0600 "$(_fileset_owner masterd)"
103 b370482d René Nussbaumer
    done
104 5224330e René Nussbaumer
105 b370482d René Nussbaumer
    for file in $(_gather_files ${DATADIR} 0600 root \
106 b370482d René Nussbaumer
                  @GNTMASTERDGROUP@ -name 'ssconf_*'); do
107 b370482d René Nussbaumer
      _ensure_file "${file}" 0444 "$(_fileset_owner noded)"
108 b370482d René Nussbaumer
    done
109 b370482d René Nussbaumer
  fi
110 46a8da3b René Nussbaumer
}
111 46a8da3b René Nussbaumer
112 46a8da3b René Nussbaumer
_ensure_rundir() {
113 5224330e René Nussbaumer
  _ensure_dir ${GNTRUNDIR} 0775 "$(_fileset_owner daemons)"
114 5224330e René Nussbaumer
  _ensure_dir ${GNTRUNDIR}/socket 0750 "$(_fileset_owner daemons)"
115 5224330e René Nussbaumer
  _ensure_dir ${GNTRUNDIR}/bdev-cache 0755 "$(_fileset_owner noded)"
116 5224330e René Nussbaumer
  _ensure_dir ${GNTRUNDIR}/instance-disks 0755 "$(_fileset_owner noded)"
117 5224330e René Nussbaumer
  _ensure_dir ${GNTRUNDIR}/crypto 0700 "$(_fileset_owner noded)"
118 5224330e René Nussbaumer
  _ensure_dir ${GNTRUNDIR}/import-export 0755 "$(_fileset_owner noded)"
119 5224330e René Nussbaumer
120 5224330e René Nussbaumer
  # We ignore this file if it don't exists (not yet start up)
121 5224330e René Nussbaumer
  _ensure_file ${GNTRUNDIR}/socket/ganeti-master 0770 \
122 5224330e René Nussbaumer
               "$(_fileset_owner daemons)" || :
123 46a8da3b René Nussbaumer
}
124 46a8da3b René Nussbaumer
125 46a8da3b René Nussbaumer
_ensure_logdir() {
126 5224330e René Nussbaumer
  _ensure_dir ${GNTLOGDIR} 0770 "$(_fileset_owner daemons)"
127 5224330e René Nussbaumer
  _ensure_dir ${GNTLOGDIR}/os 0750 "$(_fileset_owner daemons)"
128 5224330e René Nussbaumer
129 5224330e René Nussbaumer
  # We ignore these files if they don't exists (incomplete setup)
130 5224330e René Nussbaumer
  _ensure_file ${GNTLOGDIR}/master-daemon.log 0600 "$(_fileset_owner masterd)" || :
131 5224330e René Nussbaumer
  _ensure_file ${GNTLOGDIR}/conf-daemon.log 0600 "$(_fileset_owner confd)" || :
132 5224330e René Nussbaumer
  _ensure_file ${GNTLOGDIR}/node-daemon.log 0600 "$(_fileset_owner noded)" || :
133 5224330e René Nussbaumer
  _ensure_file ${GNTLOGDIR}/rapi-daemon.log 0600 "$(_fileset_owner rapi)" || :
134 5224330e René Nussbaumer
}
135 46a8da3b René Nussbaumer
136 5224330e René Nussbaumer
_ensure_lockdir() {
137 5224330e René Nussbaumer
  _ensure_dir ${LOCKDIR} 1777 ""
138 46a8da3b René Nussbaumer
}
139 46a8da3b René Nussbaumer
140 46a8da3b René Nussbaumer
_operate_while_hold() {
141 46a8da3b René Nussbaumer
  local fn=$1
142 46a8da3b René Nussbaumer
  local path=$2
143 46a8da3b René Nussbaumer
  shift 2
144 46a8da3b René Nussbaumer
145 5224330e René Nussbaumer
  (cd ${path};
146 46a8da3b René Nussbaumer
   ${fn} "$@")
147 46a8da3b René Nussbaumer
}
148 46a8da3b René Nussbaumer
149 46a8da3b René Nussbaumer
main() {
150 b370482d René Nussbaumer
  local full_run
151 b370482d René Nussbaumer
152 b370482d René Nussbaumer
  while getopts "f" OPTION; do
153 b370482d René Nussbaumer
    case ${OPTION} in
154 b370482d René Nussbaumer
      f) full_run=1 ;;
155 b370482d René Nussbaumer
    esac
156 b370482d René Nussbaumer
  done
157 b370482d René Nussbaumer
158 b370482d René Nussbaumer
  _operate_while_hold "_ensure_datadir" ${DATADIR} ${full_run}
159 5224330e René Nussbaumer
  _operate_while_hold "_ensure_rundir" ${RUNDIR}
160 5224330e René Nussbaumer
  _operate_while_hold "_ensure_logdir" ${LOGDIR}
161 5224330e René Nussbaumer
  _operate_while_hold "_ensure_lockdir" @LOCALSTATEDIR@
162 46a8da3b René Nussbaumer
}
163 46a8da3b René Nussbaumer
164 46a8da3b René Nussbaumer
main "$@"