max / makenotwork
1 file changed,
+10 insertions,
-6 deletions
| @@ -59,13 +59,17 @@ BEGIN | |||
| 59 | 59 | END \$\$; | |
| 60 | 60 | SQL | |
| 61 | 61 | ||
| 62 | - | # Run the binary as the app user with the service env sourced and the seed | |
| 63 | - | # opt-in flag set. `--seed-examples` applies migrations to the empty schema, | |
| 64 | - | # runs the guarded seed, and exits(0) before the server binds a port — so this | |
| 65 | - | # is safe to run while the service is stopped. | |
| 62 | + | # Run the binary as the app user with the seed opt-in flag set. | |
| 63 | + | # `--seed-examples` applies migrations to the empty schema, runs the guarded | |
| 64 | + | # seed, and exits(0) before the server binds a port — so this is safe to run | |
| 65 | + | # while the service is stopped. Use systemd-run with the service's own | |
| 66 | + | # EnvironmentFile rather than shell-sourcing it: systemd parses `KEY=value` | |
| 67 | + | # literally, so secrets containing shell metacharacters (e.g. the DB password) | |
| 68 | + | # load correctly, whereas `. env` would choke on them. | |
| 66 | 69 | log "migrating + seeding the example catalog" | |
| 67 | - | ts_ssh "cd $BIN_DIR && sudo -u $SEED_USER env ALLOW_EXAMPLE_SEED=1 \ | |
| 68 | - | bash -c 'set -a; . $ENV_FILE; set +a; exec ./$BIN_NAME --seed-examples'" | |
| 70 | + | ts_ssh "systemd-run --pipe --wait --collect --service-type=exec \ | |
| 71 | + | -p EnvironmentFile=$ENV_FILE -p WorkingDirectory=$BIN_DIR -p User=$SEED_USER \ | |
| 72 | + | -E ALLOW_EXAMPLE_SEED=1 $BIN --seed-examples" | |
| 69 | 73 | ||
| 70 | 74 | log "starting $SERVICE" | |
| 71 | 75 | ts_ssh "systemctl start $SERVICE" |