installChattrCronJob installs a cron job that runs "find -type d -exec chattr +a" every minute, ensuring directories created by NFS clients are protected.
(username string)
| 317 | // installChattrCronJob installs a cron job that runs "find <nfs-dir> -type d -exec chattr +a" |
| 318 | // every minute, ensuring directories created by NFS clients are protected. |
| 319 | func (n *NFSServerSetup) installChattrCronJob(username string) error { |
| 320 | // * * * * * - everytime |
| 321 | // 2>/dev/null - execute quietly |
| 322 | cronContent := fmt.Sprintf("* * * * * root /usr/bin/find %s -type d -exec /usr/bin/chattr +a {} + 2>/dev/null\n", shellQuote(n.nfsDir)) |
| 323 | cronPath := filepath.Join(nfsCronDir, fmt.Sprintf("%s-chattr", username)) |
| 324 | |
| 325 | if err := os.WriteFile(cronPath, []byte(cronContent), 0644); err != nil { |
| 326 | return fmt.Errorf("failed to write cron file -> %w", err) |
| 327 | } |
| 328 | color.PrintHint("✔ add chattr cron job: %s", cronPath) |
| 329 | return nil |
| 330 | } |
| 331 | |
| 332 | func (n *NFSServerSetup) removeChattrCronJob(username string) error { |
| 333 | cronPath := filepath.Join(nfsCronDir, fmt.Sprintf("%s-chattr", username)) |
no test coverage detected