7 use OpenAFS::ConfigUtils;
9 my $path = $OpenAFS::Dirpath::openafsdirpath;
12 # Create the named system object for OS specific init scripts
18 'ostype'=>$path->{'ostype'},
22 my $class = _get_class($self->{'ostype'});
23 $self = bless($self, $class);
24 $self->{'commands'} = $self->get_commands();
26 # Put the paths to the cache and afsd into the path
27 # table. Assume legacy paths if the the viceetcdir is set to
29 if ($path->{'viceetcdir'} eq '/usr/vice/etc') {
30 # set in the makefile dest targets
31 $path->{'cachedir'} = "/usr/vice" unless $path->{'cachedir'};
32 $path->{'afsddir'} = "/usr/vice/etc" unless $path->{'afsddir'};
35 # set in the makefile install targets
36 $path->{'cachedir'} = "$path->{'localstatedir'}/openafs" unless $path->{'cachedir'};
37 $path->{'afsddir'} = "$path->{'afssrvsbindir'}" unless $path->{'afsddir'};
44 # _get_class(name) - Return the package name for the ostype
48 if ($type=~/linux/i) {
49 return "OpenAFS::OS::Linux";
51 die "error: Unknow system type. Valid types are: linux\n";
55 # command(name [,params...]) - Return the command string or code reference.
60 my $cmd = $self->{'commands'}->{$name};
61 unless (defined $cmd) {
62 die "error: Unsupported command name $name for OS type $self->{'ostype'}\n";
64 # add parameters if present.
66 if (ref($cmd) eq 'CODE') {
67 $cmd = sub { &$cmd(@_) };
70 $cmd = join(' ', ($cmd, @_));
76 #--------------------------------------------------------------
77 # Common unix style os commands.
78 package OpenAFS::OS::Unix;
81 use OpenAFS::ConfigUtils;
83 our @ISA = qw(OpenAFS::OS);
86 # remove(target) - recursive remove
91 run("rm -rf $target");
97 sub fileserver_start {
99 run("$path->{'afssrvsbindir'}/bosserver");
105 sub fileserver_stop {
107 my @bosserver_pids = $self->find_pids("bosserver");
108 if (scalar @bosserver_pids) {
109 # bosserver is running, try to shutdown with bos.
111 run("$path->{'afssrvbindir'}/bos shutdown localhost -localauth");
114 warn "WARNING: Shutdown command failed.\n";
116 # Now shutdown bosserver process itself. Kill all of them
117 # in case there are remants.
118 foreach my $pid (@bosserver_pids) {
119 eval { run("kill $pid") };
125 # Restart the server.
127 sub fileserver_restart {
134 # Return a list of pids.
140 my $ps = "ps -e -o pid,cmd";
141 if ($self->{'debug'}) {
142 print("debug: searching for process $process\n");
144 open(PS, "$ps |") or die "Cannot run command: $ps: $!";
147 my ($pid,$cmd) = split;
148 if ($cmd=~/$process/) {
149 if ($self->{'debug'}) {
150 print("debug: found $pid $cmd\n");
159 #--------------------------------------------------------------
160 package OpenAFS::OS::Linux;
163 use OpenAFS::ConfigUtils;
164 use OpenAFS::Dirpath;
165 our @ISA = qw(OpenAFS::OS::Unix);
168 # OS-specific commands. Defer to init scripts where possible.
172 my $syscnf = "$path->{'initdir'}/testclient.conf";
175 'client-start' => "SYSCNF=$syscnf $path->{'initdir'}/afs.rc start",
176 'client-stop' => "SYSCNF=$syscnf $path->{'initdir'}/afs.rc stop",
177 'client-restart' => "SYSCNF=$syscnf $path->{'initdir'}/afs.rc restart",
178 'client-forcestop' => sub { $self->client_forcestop() },
179 'fileserver-start' => sub { $self->fileserver_start() },
180 'fileserver-stop' => sub { $self->fileserver_stop() },
181 'fileserver-restart' => sub { $self->fileserver_restart() },
182 'remove' => 'rm -rf',
188 # Setup the init script configuration, including the install paths.
189 # Create the required directories for the client, /afs and the
192 # N.B.The cacheinfo file is created by the init script.
194 sub configure_client {
198 'cachesize' => '50000',
203 my $debug = $self->{'debug'};
204 my $syscnf = "$path->{'initdir'}/testclient.conf";
206 open (SYSCNF, "> $syscnf") or
207 die "error: Cannot open afs.rc configuration file $syscnf, $!\n";
209 print "debug: creating afs.rc configuration file $syscnf\n" if $debug;
210 print SYSCNF <<"_SYSCNF_";
215 CACHESIZE=$config->{'cachesize'}
216 OPTIONS="-confdir $path->{'viceetcdir'}"
219 CACHEDIR=$path->{'cachedir'}/cache
220 CACHEINFO=$path->{'viceetcdir'}/cacheinfo
223 AFSD=$path->{'afsddir'}/afsd
224 BOSSERVER=$path->{'afssrvsbindir'}/bosserver
225 BOS=$path->{'afssrvbindir'}/bos
226 KILLAFS=$path->{'viceetcdir'}/killafs
227 MODLOADDIR=$path->{'afskerneldir'}
231 if (open(SYSCNF, "< $syscnf")) {
233 chomp; print "debug: $_\n";
239 # Create a cache directory if none.
240 unless ( -d "$path->{'cachedir'}/cache" ) {
241 print "debug: making cache directory: $path->{'cachedir'}/cache\n" if $debug;
242 system("mkdir -p $path->{'cachedir'}/cache");
243 system("chmod 0700 $path->{'cachedir'}/cache");
246 # Create the local /afs directory on which the afs filespace will be mounted.
248 print "debug: making the local /afs directory.\n" if $debug;
249 system("mkdir /afs");
250 system("chmod 0777 /afs");
255 # Force the client to stop. The sequence is:
257 # /usr/vice/etc/afsd -shutdown
258 # rmmod openafs (or rmmod libafs)
260 sub client_forcestop {
262 print "debug: client forcestop\n" if $self->{'debug'};
269 run("$path->{'afsddir'}/afsd -shutdown");
273 # Remove openafs modules still loaded.
274 my $mods = $self->list_modules();
275 if ($mods->{'openafs'}) {
276 eval { run("/sbin/rmmod openafs") };
278 if ($mods->{'libafs'}) {
279 eval { run("/sbin/rmmod libafs") };
283 $mods = $self->list_modules();
284 if ($mods->{'openafs'}) {
285 print "warning: kernel module still loaded: openafs\n";
287 if ($mods->{'libafs'}) {
288 print "warning: kernel module still loaded: libafs\n";
291 # remove stale lock set by init script.
292 run("rm -f /var/lock/subsys/afs");
296 # list_modules() - Returns a table of loaded module names.
301 if (open(LSMOD, "/sbin/lsmod |")) {