Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1a3bcf0
feat: added app lifecycle page
Kemi-Elizabeth Nov 7, 2025
706227a
Optimize images
actions-user Nov 7, 2025
ddf83ba
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Nov 13, 2025
c06fcad
Update sites/upsun/src/learn/overview/app-life-cycle.md
Kemi-Elizabeth Nov 13, 2025
374d6c1
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Nov 19, 2025
0fa894d
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Nov 20, 2025
154d12f
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Nov 20, 2025
a9e5ff9
Apply suggestion from @Kemi-Elizabeth
Kemi-Elizabeth Nov 20, 2025
1216c2c
feat: added note and adjusted table
Kemi-Elizabeth Nov 20, 2025
8cb82e1
Merge branch '5185-new-page-to-be-added-about-hooks' of https://githu…
Kemi-Elizabeth Nov 20, 2025
71ebbf1
feat: adjusted vale allowances
Kemi-Elizabeth Nov 20, 2025
24e3060
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Nov 21, 2025
057cefd
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Nov 26, 2025
1feed1d
feat: adjusted to include deploy hooks
Kemi-Elizabeth Nov 26, 2025
7ca70cb
Merge branch '5185-new-page-to-be-added-about-hooks' of https://githu…
Kemi-Elizabeth Nov 26, 2025
c4a3652
Optimize images
actions-user Nov 26, 2025
79f3c8d
Removed sentence start
Kemi-Elizabeth Nov 26, 2025
1b854c1
Merge branch '5185-new-page-to-be-added-about-hooks' of https://githu…
Kemi-Elizabeth Nov 26, 2025
a5cdfec
feat: removed diagram
Kemi-Elizabeth Nov 26, 2025
cbddf82
feat: added new diagrams
Kemi-Elizabeth Nov 27, 2025
ebbc9d3
feat: removed image
Kemi-Elizabeth Nov 27, 2025
d3f654d
Apply suggestion from @Kemi-Elizabeth
Kemi-Elizabeth Nov 28, 2025
e36400f
feat: removed note about blocking
Kemi-Elizabeth Dec 1, 2025
2b67d48
feat: corrected typo and removed section
Kemi-Elizabeth Dec 1, 2025
989e9b8
feat: adjusted table description
Kemi-Elizabeth Dec 1, 2025
ea6040b
feat: added links
Kemi-Elizabeth Dec 1, 2025
3de0454
Apply suggestion from @catplat
Kemi-Elizabeth Dec 4, 2025
027ba5d
Apply suggestion from @catplat
Kemi-Elizabeth Dec 4, 2025
b78b6b4
Apply suggestion from @catplat
Kemi-Elizabeth Dec 4, 2025
c2814b0
Apply suggestion from @catplat
Kemi-Elizabeth Dec 4, 2025
faa0df2
Apply suggestion from @catplat
Kemi-Elizabeth Dec 4, 2025
1d9f658
feat: removed block traffic column
Kemi-Elizabeth Dec 4, 2025
42d0c77
Merge branch '5185-new-page-to-be-added-about-hooks' of https://githu…
Kemi-Elizabeth Dec 4, 2025
703a4a5
Apply suggestion from @Kemi-Elizabeth
Kemi-Elizabeth Dec 4, 2025
03c2233
Apply suggestion from @Kemi-Elizabeth
Kemi-Elizabeth Dec 4, 2025
d352dcd
Merge branch 'main' into 5185-new-page-to-be-added-about-hooks
Kemi-Elizabeth Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions sites/upsun/src/learn/overview/app-life-cycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
title: The application lifecycle
weight: 3
description: "Understand the {{% vendor/name %}} application lifecycle and learn how to use build, deploy, and runtime hooks to control app behavior"
---

Hooks let you run custom commands at specific points in your application’s lifecycle during [`build`, `deploy`](/learn/overview/build-deploy.html), or `runtime`. They’re essential for setting up your app, managing graceful shutdowns, or preparing instances to handle traffic in autoscaling environments.

Each web application on {{% vendor/name %}} can define web commands inside its `.upsun/config.yaml` file:

```yaml
applications:
myapp:
type: 'python:3.13'
web:
commands:
pre_start: "./scripts/setup.sh"
start: "uwsgi --ini conf/server.ini"
post_start: "./scripts/warm-up.sh"
```
## Web commands

| Name | Type | Required | Description |
|------|------|-----------|--------------|
| **pre_start** | string | No | Runs just before `start`. Useful for short setup actions that must run per instance, such as moving cache files or setting permissions. |

Check failure on line 25 in sites/upsun/src/learn/overview/app-life-cycle.md

View workflow job for this annotation

GitHub Actions / vale

[vale] sites/upsun/src/learn/overview/app-life-cycle.md#L25

[Vale.Spelling] Did you really mean 'pre_start'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'pre_start'?", "location": {"path": "sites/upsun/src/learn/overview/app-life-cycle.md", "range": {"start": {"line": 25, "column": 5}}}, "severity": "ERROR"}
| **start** | string | Yes | The main command that launches your app. If it terminates, {{% vendor/name %}} restarts it immediately. |
| **post_start** | string | No | Runs after the `start` command but before the container is added to the router. This lets you complete warm-up tasks before the app starts handling traffic. |

Check failure on line 27 in sites/upsun/src/learn/overview/app-life-cycle.md

View workflow job for this annotation

GitHub Actions / vale

[vale] sites/upsun/src/learn/overview/app-life-cycle.md#L27

[Vale.Spelling] Did you really mean 'post_start'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'post_start'?", "location": {"path": "sites/upsun/src/learn/overview/app-life-cycle.md", "range": {"start": {"line": 27, "column": 5}}}, "severity": "ERROR"}

{{< note theme="info" title="Note" >}}

For more information about web commands, visit the [Single-runtime Image page](/create-apps/app-reference/single-runtime-image.html#web-commands).

{{< /note >}}

## Lifecycle overview

Every application instance follows the same start-up flow:

- Pre-start prepares each instance before launch.
- Post-start completes warm-up tasks before the instance is routed into live traffic.

![The steps in the start-up flow](/images/hook-cycle.png "0.50")

This structure ensures applications can start cleanly, scale horizontally, and serve requests reliably, especially in autoscaling environments.

## Use cases

| Hook | When to use | Example task |
|------|--------------|----------------|
| **pre_start** | For configuration and prep that must complete before your app starts | Moving cache, updating file permissions |

Check failure on line 50 in sites/upsun/src/learn/overview/app-life-cycle.md

View workflow job for this annotation

GitHub Actions / vale

[vale] sites/upsun/src/learn/overview/app-life-cycle.md#L50

[Vale.Spelling] Did you really mean 'pre_start'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'pre_start'?", "location": {"path": "sites/upsun/src/learn/overview/app-life-cycle.md", "range": {"start": {"line": 50, "column": 5}}}, "severity": "ERROR"}
| **post_start** | For initialization after your app starts but before it serves traffic | Cache warming, dependency loading |

Check failure on line 51 in sites/upsun/src/learn/overview/app-life-cycle.md

View workflow job for this annotation

GitHub Actions / vale

[vale] sites/upsun/src/learn/overview/app-life-cycle.md#L51

[Vale.Spelling] Did you really mean 'post_start'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'post_start'?", "location": {"path": "sites/upsun/src/learn/overview/app-life-cycle.md", "range": {"start": {"line": 51, "column": 5}}}, "severity": "ERROR"}

### Autoscaling example

When autoscaling [adds new instances](/manage-resources/autoscaling.html#thresholds), each instance must start and warm up before serving live requests. Use `post-start` to complete initialization tasks such as:

- Cache priming or session loading
- Running lightweight readiness checks
- Loading config or dependencies into memory

This ensures new instances are ready to perform immediately when the router adds them.

{{< note theme="tip" title="Autoscaling" >}}

For more information about Autoscaling, visit the [Autoscaling docs page](/manage-resources/autoscaling.html).

{{< /note >}}

### Zero-downtime example

If your [application takes longer to become responsive](/learn/overview/build-deploy.html#application-is-slow-to-start), traffic might be switched back to your original application before it’s fully ready. This can cause temporary errors immediately after deployment.

If your framework needs time to initialize, `post_start` can help co-ordinate so the app receives traffic only when it’s ready. An example of a `post_start` command waiting for your application would be:

```
web:
commands:
post_start: |
date
curl -sS --retry 20 --retry-delay 1 --retry-connrefused localhost -o /dev/null
```
{{< note theme="info" title="Zero Downtime Deployment" >}}

For more information about Zero Downtime Deployment, visit the [build deploy documentation page](/learn/overview/build-deploy.html#zero-downtime-deployments).

{{< /note >}}

## Related content

- [Build and Deploy overview](/learn/overview/build-deploy.html)
- [Autoscaling](/manage-resources/autoscaling.html)
- [Single-runtime Image reference](/create-apps/app-reference/single-runtime-image.html#web-commands)
- [Zero-downtime deployments](/learn/overview/build-deploy.html#zero-downtime-deployments)



Binary file added sites/upsun/static/images/hook-cycle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading