2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 12:40:25 +08:00
Files
panel/app/services/cron.go
2023-07-20 01:06:49 +08:00

41 lines
977 B
Go

package services
import (
"panel/app/models"
"panel/pkg/tools"
)
type Cron interface {
AddToSystem(cron models.Cron)
DeleteFromSystem(cron models.Cron)
}
type CronImpl struct {
}
func NewCronImpl() *CronImpl {
return &CronImpl{}
}
// AddToSystem 添加到系统
func (r *CronImpl) AddToSystem(cron models.Cron) {
if tools.IsRHEL() {
tools.ExecShell("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/root")
} else {
tools.ExecShell("echo \"" + cron.Time + " " + cron.Shell + " >> " + cron.Log + " 2>&1\" >> /var/spool/cron/crontabs/root")
}
tools.ExecShell("systemctl restart crond")
}
// DeleteFromSystem 从系统中删除
func (r *CronImpl) DeleteFromSystem(cron models.Cron) {
if tools.IsRHEL() {
tools.ExecShell("sed -i '/" + cron.Shell + "/d' /var/spool/cron/root")
} else {
tools.ExecShell("sed -i '/" + cron.Shell + "/d' /var/spool/cron/crontabs/root")
}
tools.ExecShell("systemctl restart crond")
}