|
|
|
@ -116,9 +116,10 @@ func initJobScheduler() portainer.JobScheduler {
|
|
|
|
|
return cron.NewJobScheduler()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter portainer.Snapshotter, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, flags *portainer.CLIFlags) error {
|
|
|
|
|
if !*flags.Snapshot {
|
|
|
|
|
return nil
|
|
|
|
|
func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter portainer.Snapshotter, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, settingsService portainer.SettingsService) error {
|
|
|
|
|
settings, err := settingsService.Settings()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
schedules, err := scheduleService.SchedulesByJobType(portainer.SnapshotJobType)
|
|
|
|
@ -126,21 +127,21 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(schedules) != 0 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var snapshotSchedule *portainer.Schedule
|
|
|
|
|
if len(schedules) == 0 {
|
|
|
|
|
snapshotJob := &portainer.SnapshotJob{}
|
|
|
|
|
|
|
|
|
|
snapshotSchedule := &portainer.Schedule{
|
|
|
|
|
snapshotSchedule = &portainer.Schedule{
|
|
|
|
|
ID: portainer.ScheduleID(scheduleService.GetNextIdentifier()),
|
|
|
|
|
Name: "system_snapshot",
|
|
|
|
|
CronExpression: "@every " + *flags.SnapshotInterval,
|
|
|
|
|
CronExpression: "@every " + settings.SnapshotInterval,
|
|
|
|
|
Recurring: true,
|
|
|
|
|
JobType: portainer.SnapshotJobType,
|
|
|
|
|
SnapshotJob: snapshotJob,
|
|
|
|
|
Created: time.Now().Unix(),
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
snapshotSchedule = &schedules[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snapshotJobContext := cron.NewSnapshotJobContext(endpointService, snapshotter)
|
|
|
|
|
snapshotJobRunner := cron.NewSnapshotJobRunner(snapshotSchedule, snapshotJobContext)
|
|
|
|
@ -150,8 +151,11 @@ func loadSnapshotSystemSchedule(jobScheduler portainer.JobScheduler, snapshotter
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(schedules) == 0 {
|
|
|
|
|
return scheduleService.CreateSchedule(snapshotSchedule)
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func loadEndpointSyncSystemSchedule(jobScheduler portainer.JobScheduler, scheduleService portainer.ScheduleService, endpointService portainer.EndpointService, flags *portainer.CLIFlags) error {
|
|
|
|
|
if *flags.ExternalEndpoints == "" {
|
|
|
|
@ -538,46 +542,48 @@ func main() {
|
|
|
|
|
|
|
|
|
|
snapshotter := initSnapshotter(clientFactory)
|
|
|
|
|
|
|
|
|
|
jobScheduler := initJobScheduler()
|
|
|
|
|
endpointManagement := true
|
|
|
|
|
if *flags.ExternalEndpoints != "" {
|
|
|
|
|
endpointManagement = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = loadSchedulesFromDatabase(jobScheduler, jobService, store.ScheduleService, store.EndpointService, fileService)
|
|
|
|
|
swarmStackManager, err := initSwarmStackManager(*flags.Assets, *flags.Data, digitalSignatureService, fileService)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = loadEndpointSyncSystemSchedule(jobScheduler, store.ScheduleService, store.EndpointService, flags)
|
|
|
|
|
composeStackManager := initComposeStackManager(*flags.Data)
|
|
|
|
|
|
|
|
|
|
err = initTemplates(store.TemplateService, fileService, *flags.Templates, *flags.TemplateFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = loadSnapshotSystemSchedule(jobScheduler, snapshotter, store.ScheduleService, store.EndpointService, flags)
|
|
|
|
|
err = initSettings(store.SettingsService, flags)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobScheduler.Start()
|
|
|
|
|
|
|
|
|
|
endpointManagement := true
|
|
|
|
|
if *flags.ExternalEndpoints != "" {
|
|
|
|
|
endpointManagement = false
|
|
|
|
|
}
|
|
|
|
|
jobScheduler := initJobScheduler()
|
|
|
|
|
|
|
|
|
|
swarmStackManager, err := initSwarmStackManager(*flags.Assets, *flags.Data, digitalSignatureService, fileService)
|
|
|
|
|
err = loadSchedulesFromDatabase(jobScheduler, jobService, store.ScheduleService, store.EndpointService, fileService)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
composeStackManager := initComposeStackManager(*flags.Data)
|
|
|
|
|
|
|
|
|
|
err = initTemplates(store.TemplateService, fileService, *flags.Templates, *flags.TemplateFile)
|
|
|
|
|
err = loadEndpointSyncSystemSchedule(jobScheduler, store.ScheduleService, store.EndpointService, flags)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = initSettings(store.SettingsService, flags)
|
|
|
|
|
if *flags.Snapshot {
|
|
|
|
|
err = loadSnapshotSystemSchedule(jobScheduler, snapshotter, store.ScheduleService, store.EndpointService, store.SettingsService)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jobScheduler.Start()
|
|
|
|
|
|
|
|
|
|
err = initDockerHub(store.DockerHubService)
|
|
|
|
|
if err != nil {
|
|
|
|
|