# onShutdown (Server)

> Fired when a script calls `shutdown`, right before the server shuts down.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Server
- **Category**: Server
- **URL**: https://wiki.mymp.gg/en/onShutdown

## Syntax

```lua
addEventHandler("onShutdown", root, function(element resource, string reason) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `resource` | `element` | The root element of the resource that called `shutdown`. |
| `reason` | `string` | The reason given to `shutdown`. |

## Source

The root element (`root`).

## Example

```lua
addEventHandler("onShutdown", root, function(resource, reason)
    dbExec(db, "INSERT INTO server_log (event, detail) VALUES (?, ?)", "shutdown", reason)
end)
```

## See also

- [shutdown (Server)](https://wiki.mymp.gg/en/shutdown.md): Shuts the server down. It fires onShutdown first.
