blob: 75f45b7f155826e498bb225e778bc99a9eb8f87f (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#!/sbin/runscript
extra_commands="probe status"
extra_started_commands="reload flush restart_clean"
description="The CernVM-FS init script"
init() {
# Initialization, read config
[ -x /etc/cernvm/config ] && /etc/cernvm/config
if [ -f /etc/cvmfs/config.sh ]; then
. /etc/cvmfs/config.sh
else
exit 1
fi
cvmfs_readconfig
[ -f /etc/cernvm/repositories.sh ] && . /etc/cernvm/repositories.sh
export LANG=C LC_ALL=C
[ -f /etc/cernvm/custom/init.sh ] && . /etc/cernvm/custom/init.sh
}
depend() {
need net fuse autofs
after logger
}
list_mounts() {
mount -t fuse | grep "^cvmfs2[[:space:]]"
}
repository_status() {
local fqrn=$1 ret=0 pid
if list_mounts | grep ${CVMFS_MOUNT_DIR}/${fqrn} > /dev/null; then
pid=$(cvmfs-talk -c "${CVMFS_CACHE_BASE}" -i "${fqrn}" pid)
ret=$(echo ${pid} | grep ^[0-9]*$ > /dev/null)
if [ ${ret} -eq 0 ]; then
einfo "CernVM-FS mounted on ${CVMFS_MOUNT_DIR}/${fqrn} with pid ${pid}"
else
ewarn "CernVM-FS running with process ${pid}"
fi
else
einfo "CernVM-FS not mounted on ${CVMFS_MOUNT_DIR}/${fqrn}"
fi
return ${ret}
}
repository_flush() {
local fqrn=$1
ebegin "Flushing ${fqrn}"
stat ${CVMFS_MOUNT_DIR}/${fqrn}/. > /dev/null 2>&1 && \
cvmfs-talk -c "${CVMFS_CACHE_BASE}" -i "${fqrn}" cleanup 0 > /dev/null
eend $?
}
repository_reload() {
local fqrn=$1 ret=0 hosts
if cvmfs-talk -i ${fqrn} pid > /dev/null 2>&1; then
ebegin "Reloading ${fqrn}"
[[ $(cvmfs-talk -i ${fqrn} timeout set ${CVMFS_TIMEOUT} ${CVMFS_TIMEOUT_DIRECT} 2>&1) == OK ]]
ret=$((ret + $?))
[[ $(cvmfs-talk -i ${fqrn} proxy set ${CVMFS_HTTP_PROXY} 2>&1) == OK ]]
ret=$((ret + $?))
hosts=$(echo ${CVMFS_SERVER_URL} | sed -e "s/@org@/$(cvmfs_getorg ${fqrn})/g" -e "s/@fqrn@/${fqrn}/g")
[[ $(cvmfs-talk -i ${fqrn} host set ${hosts} 2>&1) == OK ]]
ret=$((ret + $?))
[[ $(cvmfs-talk -i ${fqrn} max ttl set ${CVMFS_MAX_TTL:-0} 2>&1) == OK ]]
eend $?
ret=$((ret + $?))
else
einfo "${frqn} not mounted"
fi
return ${ret}
}
repository_wipe() {
local fqrn=$1
ebegin "Wiping out ${CVMFS_CACHE_BASE}/${fqrn}"
[ ! -d "${CVMFS_CACHE_BASE}/${fqrn}" ] || rm -rf "${CVMFS_CACHE_BASE}/${fqrn}"
eend $?
}
repository_probe() {
local fqrn=$1
ebegin "Probing ${CVMFS_MOUNT_DIR}/${fqrn}"
df -P "${CVMFS_MOUNT_DIR}/${fqrn}" 2>&1 | grep -q ^cvmfs2
eend $?
}
cvmfs_action() {
local action=$1 org fqrn
for org in ${CVMFS_REPOSITORIES/,/ /}; do
case ${org} in
none)
;;
*)
. /etc/cvmfs/config.sh
cvmfs_readconfig
fqrn=$(cvmfs_mkfqrn ${org})
cvmfs_readconfig ${fqrn}
[[ $(type -t "${action}") == "function" ]] && ${action} ${fqrn}
;;
esac
done
}
start() {
ebegin "Starting CernVM-FS"
cvmfs_action repository_start
eend $?
}
stop() {
local m ret=0
# FIXME: do we need to unmount here or?
for m in $(list_mounts | awk '{print $3}'); do
ebegin "Unmounting ${m}"
umount ${m} 2>/dev/null
eend $?
if [ $? -ne 0 ]; then
ret=$((ret + $?))
fuser -m -a -v ${m}
fi
done
if [ ${ret} -eq 0 ]; then
ebegin "Shutting down CernVM-FS"
cvmfs_action repository_stop
eend $?
ret=$((ret + $?))
fi
return ${ret}
}
status() {
ebegin "Checking status on CernVM-FS"
cvmfs_action repository_status
local org processed repo ret=0
for org in ${CVMFS_REPOSITORIES/,/ /}; do
case ${org} in
none)
;;
*)
. /etc/cvmfs/config.sh # start with fresh repository_... functions
cvmfs_readconfig
fqrn=$(cvmfs_mkfqrn ${org})
processed="${fqrn} ${processed}"
cvmfs_readconfig ${fqrn}
# in an action?
list_mounts | grep ${CVMFS_MOUNT_DIR}/${fqrn} > /dev/null
if [ $? -eq 0 ]; then
local pid=$(/usr/bin/cvmfs-talk -c "${CVMFS_CACHE_BASE}" -i "${fqrn}" pid)
if echo ${pid} | grep ^[0-9]*$ > /dev/null; then
einfo "CernVM-FS mounted on ${CVMFS_MOUNT_DIR}/${fqrn} with pid ${pid}"
else
ret=$((ret + $?))
ewarn "CernVM-FS running with process ${pid}"
fi
else
einfo "CernVM-FS not mounted on ${CVMFS_MOUNT_DIR}/${fqrn}"
fi
;;
esac
done
for repo in $(list_mounts | awk '{print $3}'); do
repo=$(basename "${repo}")
echo "${processed}" | grep -q "${repo}" || \
ewarn "CernVM-FS mounted on ${CVMFS_MOUNT_DIR}/${repo} (not in CVMFS_REPOSITORIES)"
done
eend ${ret}
}
flush() {
cvmfs_action repository_flush
}
reload() {
cvmfs_action repository_reload
}
restart_clean() {
stop
local ret=$?
cvmfs_action repository_wipe
ret=$((ret + $?))
[[ ${ret} == 0 ]] && start
ret=$((ret + $?))
return ${ret}
}
probe() {
cvmfs_action repository_probe
}
|