summaryrefslogtreecommitdiff
blob: a3c7a4d3cf351c69f62bf8ac7f8ee565eaa8729f (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#! /sbin/runscript
#RCUPDATE:34:77:This line is required for script management

# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

# AFS	Start and stop AFS components
# 
# 
# chkconfig: 345 60 20
# description:  AFS is a distributed file system which provides location
#		transparency, caching and secure authentication.
#		Additional configuration can be done in the /etc/sysconfig/afs
#		file. Read the documentation in that file for more information.
#
# Note that AFS does not use a pid file in /var/run. It is turned off by
# unmounting /afs.
#
# Modified by Holger Brueckner <darks@fet.org> for gentoo-linux 

# Gather up options and post startup script name, if present
if [ -f /etc/afs/afs.conf ]; then
	. /etc/afs/afs.conf
fi


# dependecies
depend() {
    need net
}

# check for ext2 partition

check_ext2() {
  PART=`cat /proc/mounts | grep vice | grep ext2 | awk '{print $1}'`
  if [ -z $PART ]
  then
    echo ">>> PLEASE CREATE A EXT2 (no reiserfs) PARTITION (of aprox. 200M)"
    echo ">>> AND MOUNT IT TO /USR/VICE/CACHE !!!"
    return 1
  fi
}

# check if cacheinfo exist, otherwise create it !!

check_cacheinfo(){
 [ ! -f /usr/vice/etc/cacheinfo ] && {
    PART=`cat /proc/mounts | grep vice | grep ext2 | awk '{print $1}'`
    CACHESIZE=`df $PART | grep ^/ | awk '{print $4}'`
    CACHESIZE=`expr $CACHESIZE \* 9`
    CACHESIZE=`expr $CACHESIZE / 10`
    echo "/afs:/usr/vice/cache:$CACHESIZE" > /usr/vice/etc/cacheinfo     
 }
}

# is_on returns 1 if value of arg is "on"
is_on() {
	if  test "$1" = "on" ; then return 0
	else return 1
	fi
}

# If choose_client can't correctly determine which client to use, set
# LIBAFS manually.
choose_client() {

	# Use the second field of the uname -v output instead of just
	# doing a match on the whole thing to protect against matching
	# a timezone named SMP -- I don't know of one, but let's be
	# paranoid.

	set X `uname -v`; shift
	case $2 in
	SMP) MP=.mp ;;	# MP system
	*)   MP= ;;	# SP system
	esac

	# For now, just use uname -r to get the module version. 
	VERSION=`uname -r`

	LIBAFS=libafs-$VERSION$MP.o
}

#
# Find prefix symbol to use with insmod.  We find the unregister_filesystem
# string from /proc/ksyms since we know it's there.  If /proc/ksyms does not
# exist, we print that info to the console and use the uname -v output to
# decide on a prefix.
# unregister_filesystem_Rsmp_b240cad8 is a typcial SMP version string from
# a kernel built from ftp.kernel.org
#

KSYMS_FILE=/proc/ksyms
SEARCH_STR="unregister_filesystem"
DEFAULT_SMP_PREFIX="smp_" # Redhat kernels need "smp" instead
PREFIX="" # none needed for UP with <= 1Gig memory

set_prefix()
{
	h='[0-9a-fA-F]'
	h8="$h$h$h$h$h$h$h$h"
	prefix_set=0

	set X `fgrep $SEARCH_STR $KSYMS_FILE 2> /dev/null`; shift
	str=$2
	case $str in
	${SEARCH_STR}_R$h8)
		# No prefix required
		;;
	$SEARCH_STR)
		# No versioning in kernel symbols
		;;
	${SEARCH_STR}_R*$h8)
		suffix=${str#${SEARCH_STR}_R}
		PREFIX=${suffix%$h8}
		;;
	*)
		case $str in
		'')
			echo afsd: Cannot find \"$SEARCH_STR\" in file $KSYMS_FILE
			;;
		*)
			echo afsd: Malformed kernel version symbol \"$str\"
			;;
		esac

		echo Guessing prefix from output of uname -v
		set X `uname -v`; shift
		case $2 in
		SMP)
			PREFIX=$DEFAULT_SMP_PREFIX
			;;
		esac
		;;
	esac
}


MODLOADDIR=/usr/vice/etc/modload
# load_client loads the AFS client module if it's not already loaded. 
load_client() {
	# If LIBAFS is set, use it.
	if [ -z "$LIBAFS" ] ; then
		# Try to determine the right client.
		choose_client
	fi
    
	if [ ! -f $MODLOADDIR/$LIBAFS ] ; then
		echo AFS module $MODLOADDIR/$LIBAFS does not exist. Not starting AFS.
		return 1
	fi

	# use the prefix command if required
	set_prefix
	/sbin/insmod ${PREFIX:+-P $PREFIX} -f -m $MODLOADDIR/$LIBAFS > $MODLOADDIR/libafs.map 2>&1
}

start(){
	# Load kernel extensions
	
	if check_ext2 ; then :
	else
		eend 1 "Error: No ext2 partition for afs cache"
	fi
	check_cacheinfo

	ebegin "Starting AFS services"
	
	if  load_client  ; then :
	else
		echo Failed to load AFS client, not starting AFS services.
		eend "Error Starting AFS client"
	fi

	# Start bosserver, it if exists
	if  is_on $AFS_SERVER && test -x /usr/afs/bin/bosserver  ; then
		/usr/afs/bin/bosserver 
	fi

	# Start AFS client
	if  is_on $AFS_CLIENT && test -x /usr/sbin/afsd  ; then
		/usr/sbin/afsd ${OPTIONS} 1>&2
                STATUS=$? 
		# Start AFS version of inetd.conf if present.
		#if  test -f /usr/afsws/etc/inetd.conf -a -x /usr/afsws/etc/inetd.afs ; then
		#	/usr/afsws/etc/inetd.afs /usr/afsws/etc/inetd.conf
		#fi
		$AFS_POST_INIT
	fi
	eend $STATUS "Error starting AFS"

}

stop() {
	# Stop AFS
	ebegin "Stopping AFS services"

	if  is_on $AFS_CLIENT  ; then
#		killall inetd.afs
		umount /afs
                STATUS=$? 
	fi

	if  is_on $AFS_SERVER && test -x /usr/afs/bin/bos ; then
		echo "Stopping AFS bosserver"
		/usr/afs/bin/bos shutdown localhost -localauth -wait
		killall -HUP bosserver
	fi

	LIBAFS=`/sbin/lsmod | fgrep libafs`
	if [ -n "$LIBAFS" ] ; then
		LIBAFS=`echo $LIBAFS | awk 'BEGIN { FS = " " } { print $1 }'`
		/sbin/rmmod $LIBAFS
                STATUS=$? 
	fi
       eend $STATUS "Error starting AFS"

}