Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend setting WorkingDirectory #1064

Merged
merged 11 commits into from
Jun 1, 2024
18 changes: 10 additions & 8 deletions site/docs/hosting/vps.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,20 @@ systemd is a powerful service manager which is pre-installed on many Linux distr

:::

2. You should have the absolute path to your entry file, too.
2. You should have the absolute path to your bot's directory.

3. Your start command should look like the following:

```sh
<runtime_path> <options> <entry_file_path>
<runtime_path> <options> <entry_file_relative_path>

# Path to the bot directory: /home/user/bot1/

# Deno example:
# /home/user/.deno/bin/deno --allow-all /home/user/bot1/mod.ts
# /home/user/.deno/bin/deno --allow-all run ./mod.ts
rojvv marked this conversation as resolved.
Show resolved Hide resolved

# Node.js example:
# /home/user/.nvm/versions/node/v16.9.1/bin/node /home/user/bot1/index.js
# /home/user/.nvm/versions/node/v16.9.1/bin/node ./index.js
rojvv marked this conversation as resolved.
Show resolved Hide resolved
```

#### Creating the Service
Expand All @@ -181,21 +183,21 @@ systemd is a powerful service manager which is pre-installed on many Linux distr
After=network.target

[Service]
Environment=BOT_TOKEN=<token>
WorkingDirectory=<bot-directory-path>
ExecStart=<start-command>
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

Replace `<token>` with your bot's token and `<start-command>` with the command you received [above](#getting-the-start-command).
Replace `<bot-directory-path>` with the absolute path to your bot's directory and `<start-command>` with the command you received [above](#getting-the-start-command).

Here is a brief explanation of the service configuration:

- `After=network.target` --- indicates that the application should be launched after the Internet module is loaded.
- `Environment=BOT_TOKEN=<token>` --- sets the environment variable `BOT_TOKEN`.
Add other `Environment` entries if you need multiple environment variables.
- `WorkingDirectory=<bot-directory-path>` --- sets the current working directory of the process.
This allows you to use relative assets, such as the `.env` file, which contains all the necessary environment variables.
- `ExecStart=<start-command>` --- sets the startup command.
- `Restart=on-failure` --- indicates that the application should restart after a crash.
- `WantedBy=multi-user.target` --- defines the system state in which the service should be launched.
Expand Down
Loading