add serviceman to postgres
authorAJ ONeal <aj@therootcompany.com>
Mon, 26 Oct 2020 08:29:34 +0000 (08:29 +0000)
committerAJ ONeal <aj@therootcompany.com>
Mon, 26 Oct 2020 19:39:40 +0000 (19:39 +0000)
postgres/README.md

index 1c158ebc3b7f8b4a6bdfc1bc2b843dc2f2a5293f..8c6a83c987c82b72ee7a5366e518322ab8c396cb 100644 (file)
@@ -19,23 +19,20 @@ Use `@x.y.z` for a specific version.
 > handles SQL, 'NoSQL', JSON, HSTORE, Full-Text Search, Messages Queues and
 > more. Best bang for buck.
 
-### Initialize a database with a password
-
-```bash
-echo "postgres" > /tmp/pwfile
-mkdir -p $HOME/.local/share/postgres/var/
+### Start the postgres server
 
-initdb -D $HOME/.local/share/postgres/var/ \
-    --username postgres --pwfile "/tmp/pwfile" \
-    --auth-local=password --auth-host=password
+Run just once (for development):
 
-rm /tmp/pwfile
+```bash
+postgres -D $HOME/.local/share/postgres/var -p 5432
 ```
 
-### Start the postgres server
+Run as a system service on Linux:
 
 ```bash
-postgres -D $HOME/.local/share/postgres/var -p 5432
+sudo env PATH="$PATH" \
+    serviceman add --system --username $(whoami) --name postgres -- \
+    postgres -D "$HOME/.local/share/postgres/var" -p 5432
 ```
 
 ### Connect with the psql client
@@ -43,3 +40,16 @@ postgres -D $HOME/.local/share/postgres/var -p 5432
 ```bash
 psql 'postgres://postgres:postgres@localhost:5432/postgres'
 ```
+
+### Initialize a database with a password
+
+```bash
+echo "postgres" > /tmp/pwfile
+mkdir -p $HOME/.local/share/postgres/var/
+
+initdb -D $HOME/.local/share/postgres/var/ \
+    --username postgres --pwfile "/tmp/pwfile" \
+    --auth-local=password --auth-host=password
+
+rm /tmp/pwfile
+```