# Schedules and lifecycle hooks

> Automate a FeatherPanel server with cron schedules and lifecycle hooks. Timed restarts, backups, commands, Discord webhooks and HTTP requests on start, stop or crash.

Source: https://featherpanel.com/docs/user/servers/schedules/

Both pages need `schedule.read`. Creating, editing and deleting schedules need `schedule.create`, `schedule.update`
and `schedule.delete`. Your host can turn either feature off for the whole panel.

## Schedules

A schedule is a cron expression plus a list of tasks.

| Field | Notes |
| --- | --- |
| Schedule name | For your own reference. |
| Cron expression | Minute, hour, day of month, month and day of week. Cron Helper links to cron.help. |
| Timezone | The timezone the expression is read in. |
| Only When Online | Skip the run if the server is offline. |
| Schedule Enabled | Disabled schedules never run. |

From the list you can enable or disable a schedule, **Run now** (it is queued and runs on the next cron tick), export
it as JSON and import one from JSON.

### Tasks

Open a schedule's tasks to add steps:

| Action | Payload |
| --- | --- |
| Power | Start, Stop, Restart or Kill. |
| Backup | Server files, Databases (all or selected) or Full server. See [Backups](https://featherpanel.com/docs/user/servers/backups). |
| Command | A console command, such as `say Server restarting...`. |
| Container Shell | A shell command run inside the container (`docker exec`), up to 4096 characters, with a 1 to 120 second timeout. Only shown when the host enabled it and you have `control.console`. |

Each task has a **Sequence** (run order), a **Time offset** in seconds to wait before it runs, and **Continue on
failure**. Move tasks up or down to reorder them.

A common restart schedule: Command `say Restarting in 1 minute`, then Power Restart with a 60 second offset.

## Lifecycle hooks

Lifecycle hooks run a pipeline of steps on power events instead of a timer. The host enables them with
`server_lifecycle_hooks_enabled`.

| Hook | When it runs |
| --- | --- |
| Pre-start | Before the server starts. |
| Post-start | When the server is detected as running. |
| Pre-stop | Before the server stops. |
| Post-stop | After the server stopped. Webhook, HTTP request and sleep steps only. |
| Server-crash | When Wings reports a crash. Holds one action. |

Step types:

| Step | Notes |
| --- | --- |
| Container Command | Sent to the console, like typing it. |
| Container Shell | Shell command inside the container, 1 to 120 second timeout. Host must enable it. |
| Backup | Same choices as the schedule task. |
| Discord Webhook | Message content plus an embed builder with title, description, color, fields, images, footer and author, and a live preview. Image URLs must be HTTPS. Placeholders such as `{{env.SERVER_NAME}}` are filled from the container environment. |
| HTTP Request | URL, method, headers and query params as JSON, and an optional body. |
| Sleep | Pause 1 to 300 seconds. |

Each hook can be enabled or disabled, steps can be reordered, and the whole set can be exported and imported as a file.

## Frequently asked questions

### What timezone do schedules use?

The one you pick on the schedule. 0 3 * * * with Europe/Paris runs at 3 AM Paris time, not 3 AM UTC.

### How do I post to Discord when my server crashes?

Open Lifecycle hooks, choose the Server-crash hook and add a Discord Webhook step with your webhook URL and an optional embed.

### Why do I not see Schedules or Lifecycle hooks?

Your host turned the feature off, or your subuser account lacks schedule.read.
