MCPcopy Index your code
hub / github.com/celer-pkg/celer / Setup

Method Setup

pkgcache/cache_setup.go:134–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

132}
133
134func (n *NFSClientSetup) Setup() error {
135 // Parse --nfs-client-dir
136 mountPoint, serverExport, err := parseNFSClientDir(n.nfsClientDir)
137 if err != nil {
138 return err
139 }
140
141 // Check if dir to mount NFS exist.
142 mountPoint = filepath.Clean(mountPoint)
143 if !fileio.PathExists(mountPoint) {
144 return fmt.Errorf("directory to mount NFS is not exist: %s", mountPoint)
145 }
146
147 // Install NFS client packages.
148 if err := checkClientTools(); err != nil {
149 return err
150 }
151
152 // Unmount if already mounted.
153 if err := n.unmountExisting(mountPoint); err != nil {
154 return err
155 }
156
157 // Probe server reachability before mount(8). mount.nfs has built-in retries
158 // (default ~2 minutes) that make the command look hung.
159 if err := n.probeNFSServer(serverExport); err != nil {
160 return err
161 }
162
163 // Mount NFS dir first to validate the server export and detect its numeric GID.
164 if err := n.mountNFSDir(serverExport, mountPoint); err != nil {
165 return err
166 }
167
168 // Read GID of mounted dir.
169 mountedGID, err := mountedDirGID(mountPoint)
170 if err != nil {
171 return err
172 }
173
174 // Create celer group/user with the mounted export's numeric GID.
175 // NFS sec=sys checks numeric IDs, not group names.
176 if err := createSystemGroupAndUser(nfsUser, mountedGID); err != nil {
177 return err
178 }
179
180 // Add the current user to the celer group.
181 if err := addCurrentUserToGroup(nfsUser); err != nil {
182 return err
183 }
184
185 // Manage fstab entry only after the mounted share is known to be usable.
186 if err := n.updateFSTabEntry(serverExport, mountPoint); err != nil {
187 return err
188 }
189
190 fmt.Println() // Just a blank line.
191 color.PrintSuccess("NFS cache client setup complete: %q mounted from %q", mountPoint, serverExport)

Callers 1

doSetupMethod · 0.95

Calls 12

unmountExistingMethod · 0.95
probeNFSServerMethod · 0.95
mountNFSDirMethod · 0.95
updateFSTabEntryMethod · 0.95
PathExistsFunction · 0.92
PrintSuccessFunction · 0.92
parseNFSClientDirFunction · 0.85
checkClientToolsFunction · 0.85
createSystemGroupAndUserFunction · 0.85
addCurrentUserToGroupFunction · 0.85
mountedDirGIDFunction · 0.70
CleanMethod · 0.65

Tested by

no test coverage detected