root / daemons / ensure-dirs.in @ 158377f3
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 |
touch "${GNTLOGDIR}/rapi-daemon.log" |
51 |
chown $(_fileset_owner "rapi") "${GNTLOGDIR}/rapi-daemon.log" |
52 |
} |
53 |
|
54 |
_operate_while_hold() { |
55 |
local fn=$1 |
56 |
local path=$2 |
57 |
shift 2 |
58 |
|
59 |
(cd "${path}"; |
60 |
${fn} "$@") |
61 |
} |
62 |
|
63 |
main() { |
64 |
_operate_while_hold "_ensure_rundir" "${RUNDIR}" |
65 |
_operate_while_hold "_ensure_logdir" "${LOGDIR}" |
66 |
} |
67 |
|
68 |
main "$@" |