From 492a103104f25cfd43f5c6c4479f78d6138ba3ca Mon Sep 17 00:00:00 2001 From: Nazar Antoniuk Date: Sat, 25 May 2024 10:04:37 +0300 Subject: [PATCH 1/9] add a note about the possibility of using the `.env` file in systemd --- site/docs/hosting/vps.md | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/site/docs/hosting/vps.md b/site/docs/hosting/vps.md index 225885146..b6415d1a0 100644 --- a/site/docs/hosting/vps.md +++ b/site/docs/hosting/vps.md @@ -201,6 +201,49 @@ systemd is a powerful service manager which is pre-installed on many Linux distr - `WantedBy=multi-user.target` --- defines the system state in which the service should be launched. `multi-user.target` --- is a typical value for servers. + :::: tip Using the `.env` file + In the example above, we set the environment variables directly in the unit file. + This means that these variables are immediately available to the application. + + If you prefer to use the `.env` file, you need to change a few things in the unit file configuration: + + ```diff + [Service] + -Environment=BOT_TOKEN= + +WorkingDirectory= + ExecStart= + Restart=on-failure + ``` + + We deleted all the `Environment` entries and added `WorkingDirectory` instead. + systemd starts all services from the home directory by default. + + Replace `` with the absolute path to your bot's directory so that systemd uses it as a starting point for all relative paths used by your application. + + Now you can add loading the `.env` file to your code: + + ::: code-group + + ```ts [TypeScript] + // Don't forget to run `npm install dotenv`. + import "dotenv/config"; + ``` + + ```ts [JavaScript] + // Don't forget to run `npm install dotenv`. + require("dotenv").config(); + ``` + + ```ts [Deno] + import "https://deno.land/std/dotenv/load.ts"; + ``` + + ::: + + You can combine both ways of setting environment variables. + However, be careful, because the environment variables from the `.env` file can overwrite the environment variables from the unit file configuration. + :::: + > For more information on the unit files, read [this](https://access.redhat.com/documentation/te-in/red_hat_enterprise_linux/9/html/using_systemd_unit_files_to_customize_and_optimize_your_system/assembly_working-with-systemd-unit-files_working-with-systemd). 4. Reload systemd whenever you edit the service: From f3a1c56040f63f0eaa6be5add22b95876b03a30e Mon Sep 17 00:00:00 2001 From: Nazar Antoniuk Date: Sun, 26 May 2024 11:01:44 +0300 Subject: [PATCH 2/9] use only WorkingDirectory --- site/docs/hosting/vps.md | 51 ++++------------------------------------ 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/site/docs/hosting/vps.md b/site/docs/hosting/vps.md index b6415d1a0..1251c5584 100644 --- a/site/docs/hosting/vps.md +++ b/site/docs/hosting/vps.md @@ -181,7 +181,7 @@ systemd is a powerful service manager which is pre-installed on many Linux distr After=network.target [Service] - Environment=BOT_TOKEN= + WorkingDirectory= ExecStart= Restart=on-failure @@ -189,61 +189,18 @@ systemd is a powerful service manager which is pre-installed on many Linux distr WantedBy=multi-user.target ``` - Replace `` with your bot's token and `` with the command you received [above](#getting-the-start-command). + Replace `` with the absolute path to your bot's directory and `` 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=` --- sets the environment variable `BOT_TOKEN`. - Add other `Environment` entries if you need multiple environment variables. + - `WorkingDirectory=` --- 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=` --- 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. `multi-user.target` --- is a typical value for servers. - :::: tip Using the `.env` file - In the example above, we set the environment variables directly in the unit file. - This means that these variables are immediately available to the application. - - If you prefer to use the `.env` file, you need to change a few things in the unit file configuration: - - ```diff - [Service] - -Environment=BOT_TOKEN= - +WorkingDirectory= - ExecStart= - Restart=on-failure - ``` - - We deleted all the `Environment` entries and added `WorkingDirectory` instead. - systemd starts all services from the home directory by default. - - Replace `` with the absolute path to your bot's directory so that systemd uses it as a starting point for all relative paths used by your application. - - Now you can add loading the `.env` file to your code: - - ::: code-group - - ```ts [TypeScript] - // Don't forget to run `npm install dotenv`. - import "dotenv/config"; - ``` - - ```ts [JavaScript] - // Don't forget to run `npm install dotenv`. - require("dotenv").config(); - ``` - - ```ts [Deno] - import "https://deno.land/std/dotenv/load.ts"; - ``` - - ::: - - You can combine both ways of setting environment variables. - However, be careful, because the environment variables from the `.env` file can overwrite the environment variables from the unit file configuration. - :::: - > For more information on the unit files, read [this](https://access.redhat.com/documentation/te-in/red_hat_enterprise_linux/9/html/using_systemd_unit_files_to_customize_and_optimize_your_system/assembly_working-with-systemd-unit-files_working-with-systemd). 4. Reload systemd whenever you edit the service: From 0c24b868c5fc15977ad66e2c9c21414eeedf1baa Mon Sep 17 00:00:00 2001 From: Nazar Antoniuk Date: Thu, 30 May 2024 08:38:49 +0300 Subject: [PATCH 3/9] use relative path in the start command --- site/docs/hosting/vps.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/site/docs/hosting/vps.md b/site/docs/hosting/vps.md index 1251c5584..b461322b2 100644 --- a/site/docs/hosting/vps.md +++ b/site/docs/hosting/vps.md @@ -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 - + + + # 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 # 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 ``` #### Creating the Service From 3782a15de6f6936f95af2844a7b9b97df409c49f Mon Sep 17 00:00:00 2001 From: Roj Date: Thu, 30 May 2024 11:03:20 +0300 Subject: [PATCH 4/9] Apply suggestions from code review --- site/docs/hosting/vps.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/site/docs/hosting/vps.md b/site/docs/hosting/vps.md index b461322b2..f65b9030b 100644 --- a/site/docs/hosting/vps.md +++ b/site/docs/hosting/vps.md @@ -153,10 +153,10 @@ systemd is a powerful service manager which is pre-installed on many Linux distr # Path to the bot directory: /home/user/bot1/ # Deno example: - # /home/user/.deno/bin/deno --allow-all run ./mod.ts + # /home/user/.deno/bin/deno --allow-all run mod.ts # Node.js example: - # /home/user/.nvm/versions/node/v16.9.1/bin/node ./index.js + # /home/user/.nvm/versions/node/v16.9.1/bin/node index.js ``` #### Creating the Service From 029af7ebeb59944dd50371a6a5cdeaa68f9ffccd Mon Sep 17 00:00:00 2001 From: Nazar Antoniuk Date: Thu, 30 May 2024 11:33:47 +0300 Subject: [PATCH 5/9] sync to Ukrainian --- site/docs/uk/hosting/vps.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/site/docs/uk/hosting/vps.md b/site/docs/uk/hosting/vps.md index 1209936c3..e2971aa73 100644 --- a/site/docs/uk/hosting/vps.md +++ b/site/docs/uk/hosting/vps.md @@ -143,18 +143,20 @@ systemd --- це потужний менеджер служб, який пере ::: -2. Ви також повинні мати абсолютний шлях до файлу, який є точкою входу вашого застосунку. +2. Ви також повинні мати абсолютний шлях до каталогу вашого бота. 3. Ваша команда запуску повинна виглядати наступним чином: ```sh - <шлях-до-середовища-виконання> <опції> <шлях-до-вхідного-файлу> + <шлях-до-середовища-виконання> <опції> <відносний-шлях-до-вхідного-файлу> + + # Шлях до каталогу бота: /home/user/bot1/ # Приклад для Deno: - # /home/user/.deno/bin/deno --allow-all /home/user/bot1/mod.ts + # /home/user/.deno/bin/deno --allow-all run mod.ts # Приклад для Node.js: - # /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 ``` #### Створення служби @@ -181,7 +183,7 @@ systemd --- це потужний менеджер служб, який пере After=network.target [Service] - Environment=BOT_TOKEN=<токен-бота> + WorkingDirectory=<шлях-до-каталогу-бота> ExecStart=<команда-запуску> Restart=on-failure @@ -189,13 +191,13 @@ systemd --- це потужний менеджер служб, який пере WantedBy=multi-user.target ``` - Замініть `<токен-бота>` на токен вашого бота, а `<команда-запуску>` на команду, яку ви отримали [вище](#отримання-команди-запуску). + Замініть `<шлях-до-каталогу-бота>` на абсолютний шлях до каталогу вашого бота, а `<команда-запуску>` на команду, яку ви отримали [вище](#отримання-команди-запуску). Ось коротке пояснення конфігурації сервісу: - `After=network.target` --- вказує на те, що додаток повинен запускатися після завантаження інтернет-модуля. - - `Environment=BOT_TOKEN=<токен-бота>` --- встановлює змінну оточення `BOT_TOKEN`. - Додайте інші записи `Environment`, якщо вам потрібно декілька змінних оточення. + - `WorkingDirectory=<шлях-до-каталогу-бота>` --- встановлює поточний робочий каталог процесу. + Це дозволяє використовувати відносні ресурси, як-от файл `.env`, який містить всі необхідні змінні оточення. - `ExecStart=<команда-запуску>` --- встановлює команду запуску. - `Restart=on-failure` --- вказує на те, що програма повинна перезапускатися у разі збою. - `WantedBy=multi-user.target` --- визначає стан системи, в якому повинен запускатися сервіс. From c856c60dacea6706a42e38fe963dabed04a0d89d Mon Sep 17 00:00:00 2001 From: Qz Date: Thu, 30 May 2024 22:37:06 +0700 Subject: [PATCH 6/9] sync changes to Indonesian --- site/docs/id/hosting/vps.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/site/docs/id/hosting/vps.md b/site/docs/id/hosting/vps.md index ed5790dd8..199018a81 100644 --- a/site/docs/id/hosting/vps.md +++ b/site/docs/id/hosting/vps.md @@ -143,18 +143,20 @@ systemd merupakan pengelola service yang terinstal secara bawaan di mayoritas di ::: -2. Peroleh juga path absolut ke file entrinya. +2. Peroleh path absolut direktori bot. 3. Perintah permulaan kamu semestinya serupa dengan ini: ```sh - + + + # Path direktori bot: /home/user/bot1/ # Contoh untuk Deno: - # /home/user/.deno/bin/deno --allow-all /home/user/bot1/mod.ts + # /home/user/.deno/bin/deno --allow-all run mod.ts # Contoh untuk Node.js: - # /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 ``` #### Membuat Service @@ -181,7 +183,7 @@ systemd merupakan pengelola service yang terinstal secara bawaan di mayoritas di After=network.target [Service] - Environment=BOT_TOKEN= + WorkingDirectory= ExecStart= Restart=on-failure @@ -189,13 +191,13 @@ systemd merupakan pengelola service yang terinstal secara bawaan di mayoritas di WantedBy=multi-user.target ``` - Ganti `` dengan token bot kamu dan `` dengan perintah yang kamu terima [di atas tadi](#menyiapkan-perintah-mulai). + Ganti `` dengan path absolut direktori bot kamu dan `` dengan perintah yang kamu terima [di atas tadi](#menyiapkan-perintah-mulai). Berikut uraian singkat konfigurasi service di atas: - `After=network.target` --- mengindikasikan bahwa aplikasi harus dijalankan hanya setelah modul internet telah dimuat. - - `Environment=BOT_TOKEN=` --- menambahkan environment variable `BOT_TOKEN`. - Tambahkan entri `Environment` lainnya jika kamu membutuhkan environment variable tambahan. + - `WorkingDirectory=` --- menyetel path pemrosesan ke direktori yang saat ini dikerjakan. + Dengan begitu, kamu jadi bisa menggunakan file aset relatif dari path tersebut, contohnya file `.env`, yang mana berisi semua _environment variable_ yang dibutuhkan. - `ExecStart=` --- menyetel perintah permulaan (startup command). - `Restart=on-failure` --- mengindikasikan bahwa aplikasi harus dimulai ulang ketika terjadi kesalahan atau crash. - `WantedBy=multi-user.target` --- menentukan pada tahap sistem (system state) apa service mesti dijalankan. From 37828b8a74270f50419251987e151cef153c2ab7 Mon Sep 17 00:00:00 2001 From: Acer <> Date: Thu, 30 May 2024 18:53:30 +0000 Subject: [PATCH 7/9] sync zh #1064 --- site/docs/zh/hosting/vps.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/site/docs/zh/hosting/vps.md b/site/docs/zh/hosting/vps.md index af7b17b0b..b04304985 100644 --- a/site/docs/zh/hosting/vps.md +++ b/site/docs/zh/hosting/vps.md @@ -143,18 +143,20 @@ systemd 是一个功能强大的服务管理器,已预装在许多 Linux 发 ::: -2. 你还应该有入口文件(即通过哪一个文件启动你的 bot)的绝对路径。 +2. 你还应该有你的 bot 的目录的绝对路径。 3. 你的启动命令应该看起来像下面这样: ```sh - + + + # bot 目录的路径:/home/user/bot1/ # Deno 示例: - # /home/user/.deno/bin/deno --allow-all /home/user/bot1/mod.ts + # /home/user/.deno/bin/deno --allow-all run mod.ts # Node.js 示例: - # /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 ``` #### 创建服务 @@ -181,7 +183,7 @@ systemd 是一个功能强大的服务管理器,已预装在许多 Linux 发 After=network.target [Service] - Environment=BOT_TOKEN= + WorkingDirectory= ExecStart= Restart=on-failure @@ -189,13 +191,13 @@ systemd 是一个功能强大的服务管理器,已预装在许多 Linux 发 WantedBy=multi-user.target ``` - 将 `` 替换为你的 bot token,将 `` 替换为 [上文](#获取启动命令) 获取到的命令。 + 将 `` 替换为你的 bot 目录的绝对路径,将 `` 替换为 [上文](#获取启动命令) 获取到的命令。 以下是服务配置的简要说明: - `After=network.target` --- 表示应用程序应在网络模块加载后启动。 - - `Environment=BOT_TOKEN=` --- 设置环境变量 `BOT_TOKEN`。 - 如果需要多个环境变量,请添加其他 `Environment` 条目。 + - `WorkingDirectory=` --- 设置进程的工作目录。 + 这允许你使用相关资产,例如包含了所有必要的环境变量的 `.env` 文件。 - `ExecStart=` --- 设置启动命令。 - `Restart=on-failure` --- 表示应用程序应在崩溃后重新启动。 - `WantedBy=multi-user.target` --- 定义了服务启动时的系统状态。 From 1cd0e819d38aa55a782a3271c16288d8200c1236 Mon Sep 17 00:00:00 2001 From: Habemuscode <{ID}+{username}@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:21:30 +0200 Subject: [PATCH 8/9] Add Spanish --- site/docs/es/hosting/vps.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/site/docs/es/hosting/vps.md b/site/docs/es/hosting/vps.md index e2557985d..f1258da26 100644 --- a/site/docs/es/hosting/vps.md +++ b/site/docs/es/hosting/vps.md @@ -143,18 +143,20 @@ systemd is a powerful service manager which is pre-installed on many Linux distr ::: -2. Usted debe tener la ruta absoluta a su archivo de entrada, también. +2. Deberías tener la ruta absoluta al directorio de tu bot. 3. Tu comando de inicio debería ser como el siguiente: ```sh + # Ruta al directorio del bot: /home/user/bot1/ + # Ejemplo Deno: - # /home/user/.deno/bin/deno --allow-all /home/user/bot1/mod.ts + # /home/user/.deno/bin/deno --allow-all run mod.ts # Ejemplo Node.js: - # /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 ``` #### Creación del servicio @@ -181,20 +183,21 @@ systemd is a powerful service manager which is pre-installed on many Linux distr After=network.target [Service] - Environment=BOT_TOKEN= + WorkingDirectory= ExecStart= Restart=on-failure [Install] WantedBy=multi-user.target ``` - - Sustituye `` por el token de tu bot y `` por el comando que recibiste [arriba](#obtener-el-comando-de-inicio). + + Sustituye `` por la ruta absoluta al directorio de tu bot y `` por el comando que recibiste [arriba](#obtener-el-comando-de-inicio). He aquí una breve explicación de la configuración del servicio: - `After=network.target` --- indica que la aplicación debe lanzarse después de cargar el módulo de Internet. - - `Environment=BOT_TOKEN=` --- establece la variable de entorno `BOT_TOKEN`. Añade otras entradas `Environment` si necesitas múltiples variables de entorno. + - `WorkingDirectory=` --- establece el directorio de trabajo actual del proceso. + Esto le permite utilizar activos relativos, como el archivo `.env`, que contiene todas las variables de entorno necesarias. - `ExecStart=` --- establece el comando de inicio. - `Restart=on-failure` --- indica que la aplicación debe reiniciarse después de un fallo. - `WantedBy=multi-user.target` --- define el estado del sistema en el que debe iniciarse el servicio. From 67e4a3287e9499682db493970cc81f769f18ae9c Mon Sep 17 00:00:00 2001 From: Roj Date: Sat, 1 Jun 2024 21:25:25 +0300 Subject: [PATCH 9/9] fmt --- site/docs/es/hosting/vps.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/docs/es/hosting/vps.md b/site/docs/es/hosting/vps.md index f1258da26..dd3a768bb 100644 --- a/site/docs/es/hosting/vps.md +++ b/site/docs/es/hosting/vps.md @@ -190,7 +190,7 @@ systemd is a powerful service manager which is pre-installed on many Linux distr [Install] WantedBy=multi-user.target ``` - + Sustituye `` por la ruta absoluta al directorio de tu bot y `` por el comando que recibiste [arriba](#obtener-el-comando-de-inicio). He aquí una breve explicación de la configuración del servicio: