move work logs
This commit is contained in:
@@ -538,11 +538,11 @@ func (s *Service) applyNFSExport(ctx context.Context, mountPoint, options string
|
||||
clientList = strings.Join(clients, " ")
|
||||
}
|
||||
|
||||
// Build export line
|
||||
// Build export line (format: /path client(options))
|
||||
exportLine := fmt.Sprintf("%s %s(%s)", mountPoint, clientList, options)
|
||||
|
||||
// Read current /etc/exports
|
||||
exportsPath := "/etc/exports"
|
||||
// Read current exports file (use actual config file, not symlink)
|
||||
exportsPath := "/opt/calypso/conf/nfs/exports"
|
||||
exportsContent, err := os.ReadFile(exportsPath)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("failed to read exports file: %w", err)
|
||||
@@ -574,29 +574,43 @@ func (s *Service) applyNFSExport(ctx context.Context, mountPoint, options string
|
||||
newLines = append(newLines, exportLine)
|
||||
}
|
||||
|
||||
// Write back to file
|
||||
// Write back to file (use sudo to ensure proper permissions)
|
||||
newContent := strings.Join(newLines, "\n") + "\n"
|
||||
if err := os.WriteFile(exportsPath, []byte(newContent), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write exports file: %w", err)
|
||||
tempFile := exportsPath + ".tmp"
|
||||
if err := os.WriteFile(tempFile, []byte(newContent), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write temporary exports file: %w", err)
|
||||
}
|
||||
|
||||
// Move temp file to actual location using sudo
|
||||
cmd := exec.CommandContext(ctx, "sudo", "mv", tempFile, exportsPath)
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to move exports file: %s: %w", string(output), err)
|
||||
}
|
||||
|
||||
// Apply exports
|
||||
cmd := exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
||||
// Apply exports (reload NFS exports)
|
||||
cmd = exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to apply exports: %s: %w", string(output), err)
|
||||
}
|
||||
|
||||
// Restart NFS service to ensure changes are picked up
|
||||
cmd = exec.CommandContext(ctx, "sudo", "systemctl", "restart", "nfs-kernel-server")
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
s.logger.Warn("Failed to restart NFS service", "error", string(output))
|
||||
// Don't fail, as exportfs -ra should be sufficient
|
||||
}
|
||||
|
||||
s.logger.Info("NFS export applied", "mount_point", mountPoint, "clients", clientList)
|
||||
return nil
|
||||
}
|
||||
|
||||
// removeNFSExport removes an NFS export from /etc/exports
|
||||
// removeNFSExport removes an NFS export from exports file
|
||||
func (s *Service) removeNFSExport(ctx context.Context, mountPoint string) error {
|
||||
if mountPoint == "" || mountPoint == "none" {
|
||||
return nil // Nothing to remove
|
||||
}
|
||||
|
||||
exportsPath := "/etc/exports"
|
||||
exportsPath := "/opt/calypso/conf/nfs/exports"
|
||||
exportsContent, err := os.ReadFile(exportsPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -623,20 +637,34 @@ func (s *Service) removeNFSExport(ctx context.Context, mountPoint string) error
|
||||
newLines = append(newLines, line)
|
||||
}
|
||||
|
||||
// Write back to file
|
||||
// Write back to file (use sudo to ensure proper permissions)
|
||||
newContent := strings.Join(newLines, "\n")
|
||||
if newContent != "" && !strings.HasSuffix(newContent, "\n") {
|
||||
newContent += "\n"
|
||||
}
|
||||
if err := os.WriteFile(exportsPath, []byte(newContent), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write exports file: %w", err)
|
||||
tempFile := exportsPath + ".tmp"
|
||||
if err := os.WriteFile(tempFile, []byte(newContent), 0644); err != nil {
|
||||
return fmt.Errorf("failed to write temporary exports file: %w", err)
|
||||
}
|
||||
|
||||
// Move temp file to actual location using sudo
|
||||
cmd := exec.CommandContext(ctx, "sudo", "mv", tempFile, exportsPath)
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to move exports file: %s: %w", string(output), err)
|
||||
}
|
||||
|
||||
// Apply exports
|
||||
cmd := exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
||||
// Apply exports (reload NFS exports)
|
||||
cmd = exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("failed to apply exports: %s: %w", string(output), err)
|
||||
}
|
||||
|
||||
// Restart NFS service to ensure changes are picked up
|
||||
cmd = exec.CommandContext(ctx, "sudo", "systemctl", "restart", "nfs-kernel-server")
|
||||
if output, err := cmd.CombinedOutput(); err != nil {
|
||||
s.logger.Warn("Failed to restart NFS service", "error", string(output))
|
||||
// Don't fail, as exportfs -ra should be sufficient
|
||||
}
|
||||
|
||||
s.logger.Info("NFS export removed", "mount_point", mountPoint)
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user