blob: 36dfa809435a5fa97bcf04530e84675fb38ac1e8 (
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
|
#!/sbin/openrc-run
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
depend() {
need net
after openafs-server
use logger dns
}
BSD_MOD="/boot/modules/libafs.ko"
choose_afsdoptions() {
CACHESIZE=$(cut -d ':' -f 3 /etc/openafs/cacheinfo)
if [ -z "$OPTIONS" ] || [ "$OPTIONS" = "AUTOMATIC" ] ; then
if [ $CACHESIZE -lt 131072 ] ; then
OPTIONS=$SMALL
elif [ $CACHESIZE -lt 524288 ] ; then
OPTIONS=$MEDIUM
elif [ $CACHESIZE -lt 1048576 ] ; then
OPTIONS=$LARGE
elif [ $CACHESIZE -lt 2097152 ] ; then
OPTIONS=$XLARGE
else
OPTIONS=$XXLARGE
fi
fi
AFSD_OPTIONS="$OPTIONS $VERBOSE"
[ "$ENABLE_AFSDB" = "yes" ] && AFSD_OPTIONS="$AFSD_OPTIONS -afsdb"
[ "$ENABLE_DYNROOT" = "yes" ] && AFSD_OPTIONS="$AFSD_OPTIONS -dynroot"
}
get_logfile() {
local redirect="/dev/null"
yesno ${ENABLE_STD_LOGGING} && redirect="/var/log/openafs/client.log"
echo ${redirect}
}
start() {
local ret=1
ebegin "Starting OpenAFS client"
eindent
# Check if afsd is already running -> abort
if pgrep -u 0 afsd >/dev/null ; then
eerror "afsd already running, not attempting to restart"
# Check if the openafs kernel module is loaded -> attempt unload
elif [ "${RC_UNAME}" = "Linux" ] && [ -d /proc/fs/openafs ] ; then
ewarn "OpenAFS already active, trying to unload module"
if ! modprobe -r libafs ; then
eerror "OpenAFS kernel module was loaded, unloading failed"
else
cleanstart
ret=$?
fi
elif [ "${RC_UNAME}" = "FreeBSD" ] && kldstat -n ${BSD_MOD} 2> /dev/null; then
ewarn "OpenAFS already active, trying to unload module"
if ! kldunload ${BSD_MOD}; then
eerror "OpenAFS kernel module was loaded, unloading failed"
else
cleanstart
ret=$?
fi
# Everything should be ok, start cleanly
else
cleanstart
ret=$?
fi
eend ${ret}
eoutdent
return ${ret}
}
cleanstart()
{
# Make sure the mountpoint exists
mkdir /afs 2> /dev/null
# Make sure the cache directory exists
# If config doesn't exist, create one
if [ ! -e /etc/openafs/cacheinfo ]; then
echo "/afs:/var/cache/openafs:200000" > /etc/openafs/cacheinfo
fi
CACHEDIR=$(cut -d ':' -f 2 /etc/openafs/cacheinfo)
if ! mkdir -p "${CACHEDIR}"; then
eerror "Unable to create cache dir ${CACHEDIR}"
return 1
fi
# Start openafs: module and daemon
ebegin "Loading OpenAFS kernel module"
if [ "${RC_UNAME}" = "Linux" ]; then
modprobe libafs
elif [ "${RC_UNAME}" = "FreeBSD" ]; then
kldload ${BSD_MOD}
else
eerror "Unknown system. Contact the package maintainer."
fi
eend $? || return 1
ebegin "Starting OpenAFS daemon"
choose_afsdoptions
/usr/sbin/afsd ${AFSD_OPTIONS} >$(get_logfile) 2>&1
eend $?
}
stop() {
local ret=1
ebegin "Stopping OpenAFS client"
eindent
# Three stage process: unmount / stop daemon / unload module
ebegin "Unmounting /afs"
umount /afs
if eend $? ; then
ebegin "Stopping OpenAFS daemon"
/usr/sbin/afsd -shutdown >$(get_logfile) 2>&1
if eend $? ; then
ebegin "Unloading OpenAFS module"
if [ "${RC_UNAME}" = "Linux" ]; then
modprobe -r libafs
elif [ "${RC_UNAME}" = "FreeBSD" ]; then
kldunload ${BSD_MOD}
else
eerror "Unknown system. Contact the package maintainer."
fi
eend $? && ret=0
fi
fi
eoutdent
# Clean up: remove the mountpoint if it's an empty directory
rmdir /afs 2>/dev/null
return ${ret}
}
|