aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2025-07-05 17:51:23 -0500
committerGitHub <noreply@github.com>2025-07-05 17:51:23 -0500
commit8551ea1930b6639007d18fdca35bfb4073b16914 (patch)
tree2430f701f8359e602f4c16847331c588cb473cca /docs
parent8ab0cda52fda8b7e4f0353065c6f0dc5caeeb1f1 (diff)
parent4914c3832358218d28f977baed2ddfb1e7e92723 (diff)
downloadslskd-8551ea1930b6639007d18fdca35bfb4073b16914.tar.gz
Merge branch 'master' into dependabot/npm_and_yarn/src/web/http-proxy-middleware-2.0.9
Diffstat (limited to 'docs')
-rw-r--r--docs/README.md6
-rw-r--r--docs/config.md37
-rw-r--r--docs/migrations.md44
3 files changed, 80 insertions, 7 deletions
diff --git a/docs/README.md b/docs/README.md
index ce8316a7..eb08d969 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -17,4 +17,8 @@
## Building slskd from Source
-### [Build](https://github.com/slskd/slskd/blob/master/docs/build.md) \ No newline at end of file
+### [Build](https://github.com/slskd/slskd/blob/master/docs/build.md)
+
+## Troubleshooting
+
+### [Migrations](https://github.com/slskd/slskd/blob/master/docs/migrations.md) \ No newline at end of file
diff --git a/docs/config.md b/docs/config.md
index 78d1db48..6f01c2af 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -1033,11 +1033,23 @@ integration:
### Scripts
-User-defined scripts can be configured to run when application events are raised. Scripts are given a name (useful for troubleshooting!), a list of triggering events, and a `run` command that's used to execute the script.
+User-defined scripts can be configured to run when application events are raised. Scripts are given a name (useful for troubleshooting!), a list of triggering events, and a `run` configuration that's used to execute the script.
-The `run` command must be at least one word, with the first word identifying the executable to run and the rest of the string being the command and arguments that will be passed to the executable when the script is run. The executable needs to be on the system's PATH, otherwise it must be the fully qualified path to the file on disk.
+The `run` configuration can take a few different forms (see examples below), but in all cases a new process is started using either the `executable` you specify or, if you don't specify one, the executable set in your system's `$SHELL` environment variable, or `cmd.exe` on Windows.
-A reserved placeholder value `$DATA` is replaced with the stringified JSON data associated with the event that caused the script to run. It's the responsibility of the script to parse and handle this JSON.
+Processes are started in the `/scripts` directory (meaning the working directory), and stdout and stderr are redirected to slskd for logging purposes. Depending on the `run` configuration your defined command will be passed as either a single argument or list of arguments, with the latter being easier to properly quote and escape.
+
+The data associated with the event that's invoking your script is stringified to JSON and set as the value of the `SLSKD_SCRIPT_DATA` environment variable. Whatever command or script you specify will need to read this value and handle the data.
+
+> [!CAUTION]
+> **Remote Code Execution Risk**: The event data in `$SLSKD_SCRIPT_DATA` originates from the Soulseek network and may contain malicious content. Passing this data as command-line arguments could allow attackers to inject shell commands through specially crafted filenames, usernames, or other fields. For example, a filename like `song"; rm -rf /; echo "` could delete your entire filesystem if passed unsafely to a shell command.
+>
+> **Best practices:**
+> - ✅ Read `$SLSKD_SCRIPT_DATA` as an environment variable
+> - ✅ Parse the JSON and validate/sanitize individual fields before use
+> - ✅ Use programming languages with proper JSON parsing (Python, Node.js, etc.)
+> - ❌ Avoid using `$SLSKD_SCRIPT_DATA` in shell command substitution like `$(echo $SLSKD_SCRIPT_DATA)`
+> - ❌ Avoid passing the raw data as arguments: `my_script.sh "$SLSKD_SCRIPT_DATA"`
#### **YAML**
```yaml
@@ -1047,11 +1059,22 @@ integration:
on:
- DownloadFileComplete
- DownloadDirectoryComplete
- run: /bin/sh data/my_script.sh --json-to-process "$DATA" # Linux/macOS
+ run:
+ command: "echo "new event!" >> event_log.txt # command is run with system $SHELL/cmd.exe on Windows
my_logging_script:
on:
- - All
- run: cmd.exe echo $DATA >> event_log.txt # Windows
+ - All
+ run:
+ executable: /bin/sh # explicitly setting executable; if omitted, $SHELL/cmd.exe is used
+ args: '-c "echo "new event!" >> event_log.txt"'
+ another_script:
+ on:
+ - All
+ run:
+ executable: /bin/sh # as above, can omit to use $SHELL/cmd.exe
+ arglist: # easier to properly quote
+ - /c
+ - 'echo "new event!" >> event_log.txt'
```
## System-Defined
@@ -1231,6 +1254,7 @@ Several additional feature flags are provided to change the application's runtim
| `--no-connect` | `SLSKD_NO_CONNECT` | Start the application, but don't connect to the server |
| `--no-share-scan` | `SLSKD_NO_SHARE_SCAN` | Don't perform a scan of shared directories on startup |
| `--force-share-scan` | `SLSKD_FORCE_SHARE_SCAN` | Force a scan of shared directories on startup |
+| `--force-migrations` | `SLSKD_FORCE_MIGRATIONS` | Force database migrations to be applied on startup |
| `--no-version-check` | `SLSKD_NO_VERSION_CHECK` | Don't perform a version check on startup |
| `--log-sql` | `SLSKD_LOG_SQL` | Log SQL queries generated by Entity Framework |
| `--volatile` | `SLSKD_VOLATILE` | Use volatile data storage (all data will be lost at shutdown) |
@@ -1247,6 +1271,7 @@ flags:
no_connect: false
no_share_scan: false
force_share_scan: false
+ force_migrations: false
no_version_check: false
log_sql: false
experimental: false
diff --git a/docs/migrations.md b/docs/migrations.md
new file mode 100644
index 00000000..2fec53bd
--- /dev/null
+++ b/docs/migrations.md
@@ -0,0 +1,44 @@
+# Database Migrations
+
+Database migrations are used to update the structure of the application's databases to support new features or improve functionality. These migrations are applied automatically when the application starts. If a migration fails, the application will attempt to restore the database to its pre-migration state using backups created before the migration process began.
+
+## Migration Process
+
+When the application detects that a migration is required, it performs the following steps:
+
+1. Back up existing databases: Before applying any changes, the application creates a backup of each database. These backups are stored in the `backups` directory within the application's data directory. The backup files are named using the format `<database>.pre-migration-backup.<migration id>.db`.
+
+2. Apply migrations: The application applies the necessary changes to the database schema and data.
+
+At the start of each migration a unique `migration id` is generated. If anything goes wrong, this ID can be used to locate the backup files created before the error occured (as subsequent migration attempts/retries will generate new backups, which may contain partially applied migrations).
+
+## What to Do If a Migration Fails
+
+If a migration fails, the application will attempt to restore the databases from the backups created before the migration. However, if the automatic restoration process fails, you can manually recover your data by following these steps:
+
+1. Locate the Backup Files:
+ - Find the _first_ failed migration attempt and note the associated ID (it will be in application logs). If it can't be located, it is safe to assume that the oldest ID is the correct one.
+ - Navigate to the `backups` directory within the application's data directory.
+ - Look for files named `<database>.pre-migration-backup.<migration id>.db`.
+
+2. Restore the Backup:
+ - Rename the backup file to replace the current database file. For example, rename `transfers.pre-migration-backup.040123_123456.db` to `transfers.db`.
+ - Ensure the restored file is placed in the root of the application's data directory (move it up, out of the `backups` directory).
+
+3. Restart the Application:
+ - Start the application again. It will detect the restored database and attempt to reapply the migration.
+
+## If the Migration Continues to Fail
+
+If the application gets "stuck" in a reboot loop and can't complete migration(s) successfully, you will need to rename (or delete) the existing database files and allow the application to re-generate them.
+
+It should be possible to recover the old data, but the process will need to be manual. Create a GitHub issue and provide logs from the failing migration(s).
+
+## Preventing Migration Issues
+
+To minimize the risk of migration failures:
+
+- Ensure Sufficient Disk Space: Verify that there is enough disk space available for creating backups and applying migrations.
+- Avoid Interruptions: Do not stop the application while a migration is in progress.
+- Monitor Logs: Check the application logs for detailed information about the migration process and any errors encountered.
+