refactor: ensure crontab files are properly deleted

This commit is contained in:
Jose Diaz-Gonzalez committed 2021-01-21 00:17:32 -05:00
1 parent 20b2773ea2
commit fc8c58a1e6
1 file changed
+20 -11
+20 -11
View File
@@ -67,10 +67,28 @@ func fetchCronEntries(appName string) ([]templateCommand, error) {
return commands, nil return commands, nil
} }
func deleteCrontab() error {
command := common.NewShellCmd("crontab -l -u dokku")
command.ShowOutput = false
if !command.Execute() {
return nil
}
command = common.NewShellCmd("crontab -r -u dokku")
command.ShowOutput = false
out, err := command.CombinedOutput()
if err != nil {
return fmt.Errorf("Unable to remove schedule file: %v", string(out))
}
common.LogInfo1("Removed")
return nil
}
func writeCronEntries() error { func writeCronEntries() error {
apps, err := common.DokkuApps() apps, err := common.DokkuApps()
if err != nil { if err != nil {
return nil return deleteCrontab()
} }
commands := []templateCommand{} commands := []templateCommand{}
@@ -89,16 +107,7 @@ func writeCronEntries() error {
} }
if len(commands) == 0 { if len(commands) == 0 {
if !common.FileExists("/var/spool/cron/crontabs/dokku") { return deleteCrontab()
return nil
}
command := common.NewShellCmd("crontab -r -u dokku")
command.ShowOutput = false
out, err := command.CombinedOutput()
if err != nil {
return fmt.Errorf("Unable to remove schedule file: %v", out)
}
} }
data := map[string]interface{}{ data := map[string]interface{}{