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, " ")
|
clientList = strings.Join(clients, " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build export line
|
// Build export line (format: /path client(options))
|
||||||
exportLine := fmt.Sprintf("%s %s(%s)", mountPoint, clientList, options)
|
exportLine := fmt.Sprintf("%s %s(%s)", mountPoint, clientList, options)
|
||||||
|
|
||||||
// Read current /etc/exports
|
// Read current exports file (use actual config file, not symlink)
|
||||||
exportsPath := "/etc/exports"
|
exportsPath := "/opt/calypso/conf/nfs/exports"
|
||||||
exportsContent, err := os.ReadFile(exportsPath)
|
exportsContent, err := os.ReadFile(exportsPath)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("failed to read exports file: %w", 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)
|
newLines = append(newLines, exportLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write back to file
|
// Write back to file (use sudo to ensure proper permissions)
|
||||||
newContent := strings.Join(newLines, "\n") + "\n"
|
newContent := strings.Join(newLines, "\n") + "\n"
|
||||||
if err := os.WriteFile(exportsPath, []byte(newContent), 0644); err != nil {
|
tempFile := exportsPath + ".tmp"
|
||||||
return fmt.Errorf("failed to write exports file: %w", err)
|
if err := os.WriteFile(tempFile, []byte(newContent), 0644); err != nil {
|
||||||
|
return fmt.Errorf("failed to write temporary exports file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply exports
|
// Move temp file to actual location using sudo
|
||||||
cmd := exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
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 (reload NFS exports)
|
||||||
|
cmd = exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
||||||
if output, err := cmd.CombinedOutput(); err != nil {
|
if output, err := cmd.CombinedOutput(); err != nil {
|
||||||
return fmt.Errorf("failed to apply exports: %s: %w", string(output), err)
|
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)
|
s.logger.Info("NFS export applied", "mount_point", mountPoint, "clients", clientList)
|
||||||
return nil
|
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 {
|
func (s *Service) removeNFSExport(ctx context.Context, mountPoint string) error {
|
||||||
if mountPoint == "" || mountPoint == "none" {
|
if mountPoint == "" || mountPoint == "none" {
|
||||||
return nil // Nothing to remove
|
return nil // Nothing to remove
|
||||||
}
|
}
|
||||||
|
|
||||||
exportsPath := "/etc/exports"
|
exportsPath := "/opt/calypso/conf/nfs/exports"
|
||||||
exportsContent, err := os.ReadFile(exportsPath)
|
exportsContent, err := os.ReadFile(exportsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
@@ -623,21 +637,35 @@ func (s *Service) removeNFSExport(ctx context.Context, mountPoint string) error
|
|||||||
newLines = append(newLines, line)
|
newLines = append(newLines, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write back to file
|
// Write back to file (use sudo to ensure proper permissions)
|
||||||
newContent := strings.Join(newLines, "\n")
|
newContent := strings.Join(newLines, "\n")
|
||||||
if newContent != "" && !strings.HasSuffix(newContent, "\n") {
|
if newContent != "" && !strings.HasSuffix(newContent, "\n") {
|
||||||
newContent += "\n"
|
newContent += "\n"
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(exportsPath, []byte(newContent), 0644); err != nil {
|
tempFile := exportsPath + ".tmp"
|
||||||
return fmt.Errorf("failed to write exports file: %w", err)
|
if err := os.WriteFile(tempFile, []byte(newContent), 0644); err != nil {
|
||||||
|
return fmt.Errorf("failed to write temporary exports file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply exports
|
// Move temp file to actual location using sudo
|
||||||
cmd := exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
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 (reload NFS exports)
|
||||||
|
cmd = exec.CommandContext(ctx, "sudo", "exportfs", "-ra")
|
||||||
if output, err := cmd.CombinedOutput(); err != nil {
|
if output, err := cmd.CombinedOutput(); err != nil {
|
||||||
return fmt.Errorf("failed to apply exports: %s: %w", string(output), err)
|
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)
|
s.logger.Info("NFS export removed", "mount_point", mountPoint)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user