]> andersk Git - moira.git/blame - incremental/afs/afs_create.pl
Retry volume releases three times, and don't treat a failure as fatal.
[moira.git] / incremental / afs / afs_create.pl
CommitLineData
6ff63c15 1#!/usr/athena/bin/perl
6231b320 2# Usage: afs_create locker type cell path quota user group
3
4require "/moira/bin/afs_utils.pl";
5
c09dcc8c 6$protodir="/moira/dotfiles";
6231b320 7$quota=1;
8
6231b320 9%proc =
10 ("ATHENA.MIT.EDU", 'athena_proc' );
11
12umask(0);
13
14die "Usage: $0 locker type cell path user group\n" if (@ARGV != 6);
15($locker,$type,$cell,$path,$user,$group) = @ARGV;
16
17# Lookup volume type
18($c = $cell) =~ s/\./_/g;
c3c80a2e 19$vtype = eval "\$vtypes_${c}{$type}";
754ef493 20die "Cannot create $type volumes in $cell\n" unless $vtype;
21$vname = $vtype . "." . $locker;
22$vname =~ s/[^-A-Za-z0-9_.]//g; # strip out illegal characters
6231b320 23
97798f36 24# Find free space/Create volume
c9e7ea4d 25$tries = 0; $code = 1;
26while ($tries<3 && $code) {
97798f36 27 ($asrv,$apart) = &afs_find($cell,$type,$quota,@except);
28 die "Unable to find space to create $vname in $cell\n" unless ($asrv&&$apart);
29 $code = system("$vos create $asrv $apart $vname -cell $cell >/dev/null");
30 push(@except, $asrv);
c9e7ea4d 31 $tries++;
97798f36 32}
33&fatal("Unable to create $vname in $cell") if ($code); # Too many create errors
6231b320 34push(@clean, "$vos remove $asrv $apart $vname -cell $cell >/dev/null");
35
36# Create mountpoint and set quota
37$path =~ s:^/afs/([^.]):/afs/.\1:;
870213d6 38system("$fs checkv >/dev/null; $fs mkm $path $vname");
6231b320 39&fatal("Unable to create $path") if ($?);
40push(@clean, "$fs rmm $path");
41
6ff63c15 42# Obtain user/group information (uid >= 0, gid <= 0)
6231b320 43$uid = $gid = 0;
44open(PTS, "$pts ex $user -cell $cell|");
45chop($_ = <PTS>);
46close(PTS);
47($uid,$uid,$uid,$uid) = split(/[:,] /, $_) unless ($?);
48
49open(PTS, "$pts ex system:$group -cell $cell|");
50chop($_ = <PTS>);
51close(PTS);
52($gid,$gid,$gid,$gid) = split(/[:,] /, $_) unless ($?);
6231b320 53
54# Dispatch to the cell-specific creation routines
55eval "&$proc{$cell}";
56&fatal($@) if ($@);
57
58# Set the filesystem quota
59system("$fs sq $path $quota");
60&fatal("Unable to set the quota on $path") if ($?);
61
62# Release the parent volume
63($p = $path) =~ s:/[^/]+$::;
64open(FS, "$fs lv $p|") || &fatal("Can't get information about $p");
65chop($_ = <FS>);
66close(FS);
67&fatal("Can't get information about $p") if ($?);
68@tmp = (split(/ /,$_));
9efb71b3 69if ($tmp[$#tmp] !~ /user\../) {
7e859e26 70 $tries = 0; $code = 1;
71 while ($tries<3 && $code) {
72 $code = system("$vos release $tmp[$#tmp] -cell $cell >/dev/null");
73 $tries++;
74 }
75 warn "Couldn't release $tmp[$#tmp] in cell $cell" if ($code) # Don't treat as fatal.
9efb71b3 76}
6231b320 77
9205b505 78# Update the quota records.
79&afs_quota_adj($cell,$asrv,$apart,$quota,0);
6231b320 80exit(0);
81
82sub fatal
83{
84 local($cmd);
85 $_ = join(' ',@_);
86 s/\n$//;
87
88 while (@clean) {
89 $cmd = pop(@clean);
90 warn "$locker: Cleanup failed: $cmd\n" if (system("$cmd"));
91 }
92 die "$locker: $_\n";
93}
94
95# Cell specific procedures
96sub athena_proc
97{
98 # Default acls:
99 #
100 # ACTIVITY <user> all <group> all system:anyuser rl
101 # APROJ <user> all <group> all system:anyuser rl
102 # AREF <user> all <group> rl
103 # CONTRIB <user> all system:anyuser rl
104 # COURSE <user> all <group> all system:facdev all system:authuser rl
105 # HOMEDIR <user> all
a2a8b2f6 106 # LEASE <user> all
015368a6 107 # ORG <user> all <group> all system:cwisfac all system:anyuser rl
6231b320 108 # PROJECT <user> all <group> all
109 # REF <user> all system:anyuser rl
110 # SW <user> all system:swmaint all system:authuser rl
111 # SYSTEM system:administrators all system:anyuser rl
9edc1a1d 112 # UROP <user> all <group> all system:facdev all system:authuser rl
6231b320 113 #
114 # Notes:
115 # 1. All directories also have "system:expunge ld".
116
117 @acl=("system:expunge ld");
9edc1a1d 118 push(@acl,"system:facdev all") if ($type =~ /^(COURSE|UROP)/);
6231b320 119 push(@acl,"system:swmaint all") if ($type =~ /^(SW)/);
b22cf8b8 120 push(@acl,"system:cwisfac all") if ($type =~ /^(ORG)/);
6231b320 121 push(@acl,"system:administrators all") if ($type =~ /^(SYSTEM)/);
122 push(@acl,"$user all")
b22cf8b8 123 if ($uid != 0 && $type =~ /^(ACTIVITY|APROJ|AREF|CONTRIB|COURSE|HOMEDIR|LEASE|ORG|PROJECT|REF|SW|UROP)/);
6231b320 124 push(@acl,"system:$group all")
b22cf8b8 125 if ($gid != 0 && $type =~ /^(ACTIVITY|APROJ|COURSE|ORG|PROJECT|UROP)/);
6ff63c15 126 push(@acl,"system:$group rl") if ($gid != 0 && $type =~ /^(AREF)/);
6231b320 127 push(@acl,"system:authuser rl")
9edc1a1d 128 if ($type =~ /^(COURSE|SW|UROP)/);
6231b320 129 push(@acl,"system:anyuser rl")
015368a6 130 if ($type =~ /^(ACTIVITY|APROJ|CONTRIB|ORG|REF|SYSTEM)/);
6231b320 131
1738dc4c 132 if ($type !~ /^(AREF|ORG|SYSTEM)/) {
d9f9b5c8 133 system("$vos backup $vname >/dev/null");
6231b320 134 system("$fs mkm $path/OldFiles $vname.backup");
135 warn "$locker: Unable to create OldFiles mountpoint\n" if ($?);
136 }
137
6ff63c15 138 if ($type =~ /ACTIVITY|APROJ|PROJECT/) {
e2666aac 139 system("/moira/bin/uchown $path $gid");
140 die "Unable to set volume ownership\n" if ($?);
6ff63c15 141 } elsif ($type =~ /HOMEDIR|UROP/) {
142 chown($uid,0,$path) ||
143 die "Unable to set volume ownership\n";
144 }
145
015368a6 146 if ($type eq "COURSE") {
0f9040b4 147 mkdir("$path/www",0755) &&
5eaef520 148 chown(0,0,"$path/www") ||
0f9040b4 149 die "Unable to create subdirectories\n";
1738dc4c 150 system("$fs sa $path/www @acl system:anyuser rl -clear") &&
b22cf8b8 151 die "Unable to set acl on www directory\n";
152
153 system("$fs sa $path @acl system:anyuser l -clear") &&
154 die "Unable to set acl on top-level directory\n";
1738dc4c 155 return;
b22cf8b8 156 }
157
6231b320 158 if ($type eq "HOMEDIR") {
159 die "Unable to get uid for user\n" unless ($uid);
160
0e376ad6 161 chmod(0755, $path);
691a1ce3 162 mkdir("$path/Public",0755) && mkdir("$path/www",0755) &&
6231b320 163 mkdir("$path/Private",0700) && mkdir("$path/Mail", 0700) &&
691a1ce3 164 chown($uid,0,"$path/Public","$path/www",
165 "$path/Private","$path/Mail") ||
166 die "Unable to create subdirectories\n";
167 system("$fs sa -dir $path/Public $path/www -acl @acl system:anyuser rl -clear") &&
6231b320 168 die "Unable to set acl on Public directory";
169 system("$fs sa -dir $path/Private $path/Mail -acl @acl -clear") &&
170 die "Unable to set acl on Private and/or Mail directories\n";
171
172 opendir(DIR,$protodir) || die "Unable to open prototype directory\n";
173 @files=readdir(DIR);
174 closedir(DIR);
175
176 for $i (@files) {
177 next if ($i eq "." || $i eq "..");
178 next unless -f "$protodir/$i";
179 open(IN,"<$protodir/$i") || die "Unable to open $protodir/$i\n";
180 open(OUT,">$path/$i") || die "Unable to create $i\n";
181 while ($_=<IN>) { print OUT $_; };
182 close(OUT);
183 close(IN);
184 chown($uid,0,"$path/$i");
185 }
6ff63c15 186 system("$fs sa $path @acl system:anyuser l -clear") &&
187 die "Unable to set acl on top-level directory\n";
6231b320 188 return;
189 }
190
191 system("$fs sa $path @acl -clear") &&
192 die "Unable to set acl of $path\n";
193}
This page took 0.10608 seconds and 5 git commands to generate.