7 use OpenAFS
::ConfigUtils
;
9 my $path = $OpenAFS::Dirpath
::openafsdirpath
;
12 # Create the named system object for OS specific init scripts
16 my $class = _get_class
($path->{'ostype'});
21 # Create the OS object.
27 'ostype'=>$path->{'ostype'},
31 $self = bless($self, $class);
32 $self->{'syscnf'} = "$path->{'initdir'}/test-afs-rc.conf";
33 $self->{'commands'} = $self->get_commands();
38 # _get_class(name) - Return the package name for the ostype
42 if ($type=~/linux/i) {
43 return "OpenAFS::OS::Linux";
45 die "error: Unknow system type. Valid types are: linux\n";
49 # command(name [,params...]) - Return the command string or code reference.
54 my $cmd = $self->{'commands'}->{$name};
55 unless (defined $cmd) {
56 die "error: Unsupported command name $name for OS type $self->{'ostype'}\n";
58 # add parameters if present.
60 if (ref($cmd) eq 'CODE') {
61 $cmd = sub { &$cmd(@_) };
64 $cmd = join(' ', ($cmd, @_));
70 #--------------------------------------------------------------
71 # Common unix style os commands.
72 package OpenAFS
::OS
::Unix
;
75 use OpenAFS
::ConfigUtils
;
77 our @ISA = qw(OpenAFS::OS);
80 # remove(target) - recursive remove
85 run
("rm -rf $target");
91 sub fileserver_start
{
93 run
("$path->{'afssrvsbindir'}/bosserver");
101 my @bosserver_pids = $self->find_pids("bosserver");
102 if (scalar @bosserver_pids) {
103 # bosserver is running, try to shutdown with bos.
105 run
("$path->{'afssrvbindir'}/bos shutdown localhost -localauth");
108 warn "WARNING: Shutdown command failed.\n";
110 # Now shutdown bosserver process itself. Kill all of them
111 # in case there are remants.
112 foreach my $pid (@bosserver_pids) {
113 eval { run
("kill $pid") };
119 # Restart the server.
121 sub fileserver_restart
{
128 # Return a list of pids.
134 my $ps = "ps -e -o pid,cmd";
135 if ($self->{'debug'}) {
136 print("debug: searching for process $process\n");
138 open(PS
, "$ps |") or die "Cannot run command: $ps: $!";
141 my ($pid,$cmd) = split;
142 if ($cmd=~/$process/) {
143 if ($self->{'debug'}) {
144 print("debug: found $pid $cmd\n");
154 # Returns the number of pids found for a program name.
159 my @pids = $self->find_pids($program);
163 #--------------------------------------------------------------
164 package OpenAFS
::OS
::Linux
;
167 use OpenAFS
::ConfigUtils
;
168 use OpenAFS
::Dirpath
;
169 our @ISA = qw(OpenAFS::OS::Unix);
172 # OS-specific commands. Defer to init scripts where possible.
178 'client-start' => "SYSCNF=$self->{'syscnf'} $path->{'initdir'}/afs.rc start",
179 'client-stop' => "SYSCNF=$self->{'syscnf'} $path->{'initdir'}/afs.rc stop",
180 'client-restart' => "SYSCNF=$self->{'syscnf'} $path->{'initdir'}/afs.rc restart",
181 'client-forcestop' => sub { $self->client_forcestop() },
182 'fileserver-start' => sub { $self->fileserver_start() },
183 'fileserver-stop' => sub { $self->fileserver_stop() },
184 'fileserver-restart' => sub { $self->fileserver_restart() },
185 'remove' => 'rm -rf',
191 # Setup the init script configuration, including the install paths.
192 # Create the required directories for the client, /afs and the
195 # N.B.The cacheinfo file is created by the init script.
197 sub configure_client
{
201 'cachesize' => '50000',
206 my $debug = $self->{'debug'};
208 open (SYSCNF
, "> $self->{'syscnf'}") or
209 die "error: Cannot open afs.rc configuration file $self->{'syscnf'}, $!\n";
211 print "debug: creating afs.rc configuration file $self->{'syscnf'}\n" if $debug;
212 print SYSCNF
<<"_SYSCNF_";
217 CACHESIZE
=$config->{'cachesize'}
218 OPTIONS
="-confdir $path->{'viceetcdir'}"
221 CACHEDIR
=$path->{'cachedir'}
222 CACHEINFO
=$path->{'viceetcdir'}/cacheinfo
225 AFSD
=$path->{'afsddir'}/afsd
226 BOSSERVER
=$path->{'afssrvsbindir'}/bosserver
227 BOS
=$path->{'afssrvbindir'}/bos
228 KILLAFS
=$path->{'viceetcdir'}/killafs
229 MODLOADDIR
=$path->{'afskerneldir'}
233 if (open(SYSCNF
, "< $self->{'syscnf'}")) {
235 chomp; print "debug: $_\n";
241 # Create a cache directory if none.
242 unless ( -d
"$path->{'cachedir'}" ) {
243 print "debug: making cache directory: $path->{'cachedir'}\n" if $debug;
244 system("mkdir -p $path->{'cachedir'}");
245 system("chmod 0700 $path->{'cachedir'}");
248 # Create the local /afs directory on which the afs filespace will be mounted.
250 print "debug: making the local /afs directory.\n" if $debug;
251 system("mkdir /afs");
252 system("chmod 0777 /afs");
257 # Force the client to stop. The sequence is:
259 # /usr/vice/etc/afsd -shutdown
260 # rmmod openafs (or rmmod libafs)
262 sub client_forcestop
{
264 print "debug: client forcestop\n" if $self->{'debug'};
271 run
("$path->{'afsddir'}/afsd -shutdown");
275 # Remove openafs modules still loaded.
276 my $mods = $self->list_modules();
277 if ($mods->{'openafs'}) {
278 eval { run
("/sbin/rmmod openafs") };
280 if ($mods->{'libafs'}) {
281 eval { run
("/sbin/rmmod libafs") };
285 $mods = $self->list_modules();
286 if ($mods->{'openafs'}) {
287 print "warning: kernel module still loaded: openafs\n";
289 if ($mods->{'libafs'}) {
290 print "warning: kernel module still loaded: libafs\n";
293 # remove stale lock set by init script.
294 run
("rm -f /var/lock/subsys/afs");
298 # list_modules() - Returns a table of loaded module names.
303 if (open(LSMOD
, "/sbin/lsmod |")) {