Skip to main content

Schedule

c.Schedule calls the API's Schedule group. The cron entries that osapi deploys.

Methods​

MethodReturnsPermissionDescription
List(ctx, hostname)*Response[Collection[ScheduleEntry]]schedule:readList the cron entries that osapi deployed.
Create(ctx, hostname, input)*Response[Collection[ScheduleResult]]schedule:writeDeploy a cron entry.
Get(ctx, hostname, name)*Response[Collection[ScheduleEntry]]schedule:readGet one cron entry that osapi deployed.
Update(ctx, hostname, input)*Response[Collection[ScheduleResult]]schedule:writeDeploy a cron entry that osapi deployed again.
Delete(ctx, hostname, name)*Response[Collection[ScheduleResult]]schedule:writeRemove a cron entry that osapi deployed.

List​

func (s *ScheduleService) List(
ctx context.Context,
hostname string,
) (*Response[Collection[ScheduleEntry]], error)

List the cron entries that osapi deployed.

Lists each file in /etc/cron.d and in /etc/cron.hourly, daily, weekly and monthly that osapi deployed, with its object, its cron expression or interval, and its user. A cron file that osapi did not deploy is not listed.

It sends GET /api/node/{hostname}/schedule, and needs the permission schedule:read.

The examples of the method's definition:

An entry that osapi deployed, go run schedule.go list:

resp, err := c.Schedule.List(ctx, target)

Create​

func (s *ScheduleService) Create(
ctx context.Context,
hostname string,
input ScheduleCreateInput,
) (*Response[Collection[ScheduleResult]], error)

Deploy a cron entry.

Gets the object from the object store and writes it as /etc/cron.d/backup for backup, mode 0644, for a cron expression, or as /etc/cron.daily/backup, mode 0755, for a daily interval. An object of content type template, or content_type template, is rendered with the agent's facts and the vars. A file that has the content does not change. An entry of the name in a different directory does not change: move it with delete and create. A file at the path that osapi did not deploy is refused. An entry runs as its user, root included, so only admin can deploy one.

It sends POST /api/node/{hostname}/schedule, and needs the permission schedule:write.

The examples of the method's definition:

An entry with a cron expression, go run schedule.go create:

resp, err := c.Schedule.Create(ctx, target, client.ScheduleCreateInput{
Name: "osapitest",
Object: "osapitest.cron",
Schedule: "0 2 * * *",
User: "root",
})

A script that runs daily, go run schedule.go create-2:

resp, err := c.Schedule.Create(ctx, target, client.ScheduleCreateInput{
Interval: types.Interval("daily"),
Name: "osapitest",
Object: "osapitest.sh",
})

A template, rendered with its vars, go run schedule.go create-3:

resp, err := c.Schedule.Create(ctx, target, client.ScheduleCreateInput{
ContentType: types.ContentType("template"),
Name: "osapitest",
Object: "osapitest.tmpl",
Schedule: "0 2 * * *",
Vars: map[string]string{"target": "/srv"},
})

Get​

func (s *ScheduleService) Get(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[ScheduleEntry]], error)

Get one cron entry that osapi deployed.

Reads the entry from /etc/cron.d, then from each interval directory. An entry that osapi did not deploy is not found.

It sends GET /api/node/{hostname}/schedule/{name}, and needs the permission schedule:read.

The examples of the method's definition:

An entry that osapi deployed, go run schedule.go get:

resp, err := c.Schedule.Get(ctx, target, "osapitest")

Update​

func (s *ScheduleService) Update(
ctx context.Context,
hostname string,
input ScheduleUpdateInput,
) (*Response[Collection[ScheduleResult]], error)

Deploy a cron entry that osapi deployed again.

Writes a new object, or the entry's own, at the entry's path, with the fields that the request gives and the entry's own for the rest. A file that has the content does not change. An entry that osapi did not deploy is not found. The entry stays in its directory: an interval does not change with update.

It sends PUT /api/node/{hostname}/schedule/{name}, and needs the permission schedule:write.

The examples of the method's definition:

A new object, go run schedule.go update:

resp, err := c.Schedule.Update(ctx, target, client.ScheduleUpdateInput{
Name: "osapitest",
Object: "osapitest-v2.cron",
})

A new cron expression, with the same object, go run schedule.go update-2:

resp, err := c.Schedule.Update(ctx, target, client.ScheduleUpdateInput{
Name: "osapitest",
Schedule: "30 2 * * *",
})

A new object, cron expression and user, go run schedule.go update-3:

resp, err := c.Schedule.Update(ctx, target, client.ScheduleUpdateInput{
Name: "osapitest",
Object: "osapitest-v2.cron",
Schedule: "30 2 * * *",
User: "nobody",
})

A daily script with a new object, go run schedule.go update-4:

resp, err := c.Schedule.Update(ctx, target, client.ScheduleUpdateInput{
Name: "osapitest",
Object: "osapitest-v2.sh",
})

Delete​

func (s *ScheduleService) Delete(
ctx context.Context,
hostname string,
name string,
) (*Response[Collection[ScheduleResult]], error)

Remove a cron entry that osapi deployed.

Removes the entry's file and its record. An entry that osapi did not deploy does not change, and a cron file that osapi did not deploy stays.

It sends DELETE /api/node/{hostname}/schedule/{name}, and needs the permission schedule:write.

The examples of the method's definition:

Remove an entry, go run schedule.go delete:

resp, err := c.Schedule.Delete(ctx, target, "osapitest")

Types​

The fields of each type are the properties of its schema in the API's spec.

ContentType​

ContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts.

A string, one of raw, template.

Interval​

Interval is how often a scheduled job runs, in place of a cron schedule.

A string, one of hourly, daily, weekly, monthly.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

ScheduleCreateInput​

FieldTypeDescription
ContentTypeContentTypeContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts.
IntervalIntervalInterval is how often a scheduled job runs, in place of a cron schedule.
NamestringThe entry, and its file name, such as backup.
ObjectstringThe object that holds the entry, from osapi client file upload.
SchedulestringA cron expression, such as */5 * * * *; give it or interval.
UserstringThe user the entry runs as.
Varsmap[string]stringThe vars of a template, as key=value.

ScheduleEntry​

FieldTypeDescription
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
IntervalstringIts interval, for a script in /etc/cron.daily and the like.
NamestringThe entry.
ObjectstringThe object it was deployed from.
SchedulestringIts cron expression, for an entry in /etc/cron.d.
SourcestringWhere its file is: cron.d, or the interval.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.
UserstringThe user it runs as.

ScheduleResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
NamestringThe entry.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

ScheduleUpdateInput​

FieldTypeDescription
NamestringThe name of the path. The entry, such as backup.
ContentTypeContentTypeContentType is how a deploy treats a file: raw writes its bytes as they are; template renders it with Go text/template and the agent's facts.
ObjectstringThe object to deploy; the entry's own when empty.
SchedulestringA new cron expression; the entry's own when empty.
UserstringThe user the entry runs as; the entry's own when empty.
Varsmap[string]stringThe vars of a template, as key=value.

Example​

examples/sdk/client/schedule.go runs each example of this page. With no argument, it lists them.