Solved postgres appjail not starting

I tried following the appjail version for postgres:

but, it appears to be in a crash loop:
Code:
2026-08-29 13:15:09.770143851  Initializing PostgreSQL database...
2026-08-29 13:15:09.792961816  The files belonging to this database system will be owned by user "bsd".
2026-08-29 13:15:09.792968100  This user must also own the server process.
2026-08-29 13:15:09.792970413  
2026-08-29 13:15:09.793119609  The database cluster will be initialized with locale "C".
2026-08-29 13:15:09.793125712  The default text search configuration will be set to "english".
2026-08-29 13:15:09.793128020  
2026-08-29 13:15:09.793130543  Data page checksums are enabled.
2026-08-29 13:15:09.793132593  
2026-08-29 13:15:09.852266586  Creating user 'postgres'...
2026-08-29 13:15:09.861701675  Setting password for 'postgres'...
2026-08-29 13:15:09.901951238  Starting PostgreSQL...
2026-08-29 13:15:09 [s6] Service 'postgresql' crashed (Exit: 1, Signal: 0)

The only settings I tweaked were the fstab location. Additionally, I ensured that that directory is owned by 1000:1000 and the permissions are 700.

I would expect this to work out of the box and I likely have a simple typo somewhere.

Thoughts?
 
Last edited by a moderator:
Code:
2026-08-29 13:15:09.792961816 The files belonging to this database system will be owned by user "bsd".
2026-08-29 13:15:09.792968100 This user must also own the server process.
PostgreSQL generally uses the postgres user to own files and processes etc. Can you start from scratch again but use the "postgres" user instead of the "bsd" user and see if you get any further?
 
I tried following the appjail version for postgres:

but, it appears to be in a crash loop:


The only settings I tweaked were the fstab location. Additionally, I ensured that that directory is owned by 1000:1000 and the permissions are 700.

I would expect this to work out of the box and I likely have a simple typo somewhere.

Thoughts?
PostgreSQL requires more jail(8) parameters than usual; otherwise, it will refuse to start. The command listed on daemonless.io does not specify them. I'll submit a pr to fix this, but the only thing missing is the following:

template.conf

Code:
exec.start: "/bin/sh /etc/rc"
exec.stop: "/bin/sh /etc/rc.shutdown jail"
mount.devfs
persist
sysvmsg: new
sysvsem: new
sysvshm: new

Console:

Code:
$ install -d -m 0700 mydata
$ appjail oci run -Pd \
   -o overwrite=force \
   -o container="args:--pull" \
   -o virtualnet=":<random> default" \
   -o nat \
   -e POSTGRES_USER=postgres \
   -e POSTGRES_PASSWORD=postgres  \
   -e POSTGRES_DB=postgres \
   -e PUID=1000 \
   -e PGID=1000 \
   -e TZ=UTC \
   -e POSTGRES_INITDB_ARGS= \
   -e POSTGRES_HOST_AUTH_METHOD= \
   -o template=template.conf \ # missing
   -o fstab="${PWD}/mydata /var/lib/postgresql/data" \
    ghcr.io/daemonless/postgres:latest postgres
...
[00:00:38] [ info  ] [postgres] Detached: pid:1676, log:jails/postgres/container/2026-08-30.log

Log:

Code:
$ appjail logs tail jails/postgres/container/2026-08-30.log -f
server started
Creating user 'postgres'...
CREATE ROLE
Setting password for 'postgres'...
ALTER ROLE
waiting for server to shut down.... done
server stopped
Starting PostgreSQL...
2026-08-30 21:53:30.260 UTC [21300] LOG:  ending log output to stderr
2026-08-30 21:53:30.260 UTC [21300] HINT:  Future log output will go to log destination "syslog".

The entrypoint correctly maps the owner and group, but it still needs to set the file mode [1].

I have migrated to OCI images recently in AppJail-makejails in case you want to test them: https://github.com/appjail-makejails/postgres

[1] https://github.com/daemonless/postgres/blob/main/root/etc/cont-init.d/20-postgres-config#L26
 
Thanks, that seems to have done it. It wasn't much at all, actually this is what I ran:
Code:
appjail oci run -Pd \
-o overwrite=force \
-o container="args:--pull" \
-o virtualnet=":<random> default" \
-o nat \
-o expose="5432:5432 proto:tcp" \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres  \
-e POSTGRES_DB=postgres \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=UTC \
-e POSTGRES_INITDB_ARGS= \
-e POSTGRES_HOST_AUTH_METHOD= \
-o template=template.conf \
-o fstab="$PWD/mydata /var/lib/postgresql/data" \
ghcr.io/daemonless/postgres:latest postgres

Without the expose arg, it doesn't expose the postgres port.

This is great because it really simplifies setting up appjails altogether. I use jails for my systems (such as router and workstation and this is much simpler and quicker than that).
 
Back
Top