diff --git a/main.go b/main.go index a6aea98..3a0880d 100644 --- a/main.go +++ b/main.go @@ -1068,7 +1068,7 @@ func performSetup(ctx *deploymentContext) error { step++ printStep(step, totalSetupSteps, "configuring systemd service") - if err := runSSHCommand(ctx.serverIP, systemdScript(ctx.unitServiceDir, ctx.unitEnvFile, ctx.unitVolume, ctx.serviceName)); err != nil { + if err := runSSHCommand(ctx.serverIP, systemdScript(ctx.unitServiceDir, ctx.unitEnvFile, ctx.serviceName)); err != nil { return fmt.Errorf("systemd setup failed: %w", err) } @@ -1557,23 +1557,26 @@ if [ ! -x "$binary" ]; then rm -f "$tmp" fi env_file="%s" -data_dir="%s" +data_dir="%[5]s" current_port="" -if [ -f "$env_file" ]; then - current_port=$(grep '^PORT=' "$env_file" | head -n 1 | cut -d= -f2) -fi +current_data_dir="" + if [ -f "$env_file" ]; then + current_port=$(grep '^PORT=' "$env_file" | head -n 1 | cut -d= -f2 || true) + current_data_dir=$(grep '^POCKETBASE_DATA_DIR=' "$env_file" | head -n 1 | cut -d= -f2 || true) + fi if [ -n "$data_dir" ]; then mkdir -p "$data_dir" fi -if [ "$current_port" != "%d" ]; then +if [ "$current_port" != "%d" ] || [ "$current_data_dir" != "%[5]s" ]; then cat <<'EOF' > "$env_file" PORT=%d +POCKETBASE_DATA_DIR=%[5]s EOF fi `, serviceDir, serviceDir, assetURL, envFile, volume, port, port) } -func systemdScript(serviceDir, envFile, volume, serviceName string) string { +func systemdScript(serviceDir, envFile, serviceName string) string { return fmt.Sprintf(`set -euo pipefail cat <<'EOF' > /etc/systemd/system/pb@.service [Unit] @@ -1591,7 +1594,7 @@ StandardOutput = append:%s/%%i.log StandardError = append:%s/%%i.log WorkingDirectory = %s EnvironmentFile = %s -ExecStart = %s/pocketbase serve --dir=%s --http="127.0.0.1:${PORT}" +ExecStart = %s/pocketbase serve --dir="${POCKETBASE_DATA_DIR}" --http="127.0.0.1:${PORT}" [Install] WantedBy = multi-user.target @@ -1599,7 +1602,7 @@ EOF systemctl daemon-reload systemctl --no-block enable --now pb@%s systemctl --no-block restart pb@%s -`, serviceDir, serviceDir, serviceDir, envFile, serviceDir, volume, serviceName, serviceName) +`, serviceDir, serviceDir, serviceDir, envFile, serviceDir, serviceName, serviceName) } func systemdRestartScript(serviceName string) string {