-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron.go
More file actions
28 lines (22 loc) · 713 Bytes
/
Copy pathcron.go
File metadata and controls
28 lines (22 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package matcha
import (
"fmt"
"os"
)
const cronTemplate = `# Matcha auto-update for %s
# Runs daily at 3 AM
0 3 * * * root %s update >> %s/logs/update.log 2>&1
`
// setupCron creates a cron job for automatic updates.
func (m *Matcha) setupCron() error {
logsDir := m.DataDir() + "/logs"
if err := os.MkdirAll(logsDir, 0755); err != nil {
return fmt.Errorf("failed to create logs directory: %w", err)
}
cronFile := fmt.Sprintf("/etc/cron.d/%s-update", m.config.Name)
content := fmt.Sprintf(cronTemplate, m.config.Name, m.config.BinaryPath, m.DataDir())
if err := os.WriteFile(cronFile, []byte(content), 0644); err != nil {
return fmt.Errorf("failed to write cron file: %w", err)
}
return nil
}