# Server Scripts

Server scripts work just like [Package Scripts](/package-management/package-scripts.md), but they only apply to server-related interceptor points, and they go in your `server.json`. If you have several servers in a folder with their own `server-name.json` files, the server scripts can be different per server.

The interception points which will fire a server script are:

* `preServerStart`
* `onServerStart`
* `onServerInstall`
* `onServerInitialInstall`
* `onServerStop`
* `preServerForget`
* `postServerForget`

Read more about when these interception points fire [here](/developing-for-commandbox/interceptors/core-interception-points.md).

Configure server scripts like so in your `server.json`:

```json
{
    "scripts":{
        "onServerInstall":"cfpm list"
    }
}
```

### Ad-hoc server scripts

Just like package scripts, you can also create ad-hoc scripts for a given server. They are executed with the `server run-script` command. Define them as additional keys in the `scripts` block.

```json
{
    "name" : "My Server"
    "scripts":{
        "myScript":"server log --follow"
    }
}
```

And run them like so:

```
server run-script myScript
```

### Running multiple commands

You can run several commands into a single one using `&&`.  You can also do this by specifying an array of strings instead of a string like so:

```json
{
  "name" : "My Server",
  "scripts" : {
      "updateCode" : [
          "server stop",
          "!git pull",
          "server start"
       ],
  }
}
```

This can be much more readable for multiple commands.  Note, this is functionality equivalent to using `&&`, which means any erroring command will stop execution.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://commandbox.ortusbooks.com/embedded-server/server-scripts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
