Skip to content

feat: scheduled service start - #917

Open
hpidcock wants to merge 9 commits into
canonical:masterfrom
hpidcock:schedule
Open

feat: scheduled service start#917
hpidcock wants to merge 9 commits into
canonical:masterfrom
hpidcock:schedule

Conversation

@hpidcock

@hpidcock hpidcock commented Aug 6, 2026

Copy link
Copy Markdown
Member

This introduces scheduled starting of services using the existing timer format
defined by snapd. To achieve this, a new field, schedule, is added to the
service layer schema. Additionally, the pebble services command has an extra
column/field, scheduled, which necessitated adding a complementary field to
the /v1/services GET endpoint.

The internal mechanism for starting services on a schedule is implemented in
internals/overlord/servstate/schedule.go, which utilises changes/tasks for
state keeping. The timer wakeup is driven through deferring the task into the
future, when that time passes the schedule is reassessed either deferring again
or adding a service start task to the change to be handled immediately.

An example of a one-shot service that runs periodically:

services:
  cron:
    override: replace
    startup: disabled
    command: ping -c 3 1.1.1.1
    schedule: 00:00-24:00/1440
    on-success: ignore

To see when it is scheduled next we can use the pebble services command:

$ pebble services
Service  Startup   Scheduled            Current   Since
cron     disabled  today at 19:55 AEST  inactive  today at 19:54 AEST

If we need to see more information on past runs, we can use the pebble changes
command:

$ pebble changes
ID   Status  Spawn                Ready                Summary
1    Done    today at 19:53 AEST  today at 19:53 AEST  Scheduled start of service "cron"
2    Done    today at 19:53 AEST  today at 19:54 AEST  Scheduled start of service "cron"
3    Doing   today at 19:54 AEST  -                    Scheduled start of service "cron"

It is then possible to dive deeper into the change to look at the tasks with
the pebble tasks command:

$ pebble tasks 2
Status  Spawn                Ready                Summary
Done    today at 19:53 AEST  today at 19:54 AEST  Wait for scheduled start of service "cron"
Done    today at 19:54 AEST  today at 19:54 AEST  Start service "cron"

......................................................................
Wait for scheduled start of service "cron"

2026-08-06T19:54:00+10:00 INFO Started service "cron" on schedule; next scheduled start at 2026-08-06T19:55:00+10:00.

References

@hpidcock hpidcock added the roadmap An official roadmap item label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

roadmap An official roadmap item

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant