nsg / immich-distribution

Experimental Immich distribution inside a snap
MIT License
30 stars 1 forks source link

Postgres Not Running #184

Closed manjotsc closed 5 months ago

manjotsc commented 5 months ago

Question

Hi,

The prostgres server is not running, Screenshot 2024-06-11 004138

`root@Immich:~# snap logs immich-distribution.postgres

2024-06-11T04:32:35Z immich-distribution.postgres[12742]: setpriv: setresuid failed: Invalid argument

2024-06-11T04:32:35Z systemd[1]: snap.immich-distribution.postgres.service: Main process exited, code=exited, status=127/n/a

2024-06-11T04:32:35Z systemd[1]: snap.immich-distribution.postgres.service: Failed with result 'exit-code'.

2024-06-11T04:32:46Z systemd[1]: snap.immich-distribution.postgres.service: Scheduled restart job, restart counter is at 82.

2024-06-11T04:32:46Z systemd[1]: Started snap.immich-distribution.postgres.service - Service for snap application immich-distribution.postgres.

2024-06-11T04:32:46Z immich-distribution.postgres[12815]: setpriv: setresuid failed: Invalid argument

2024-06-11T04:32:46Z immich-distribution.postgres[12817]: setpriv: setresuid failed: Invalid argument

2024-06-11T04:32:46Z immich-distribution.postgres[12819]: setpriv: setresuid failed: Invalid argument

2024-06-11T04:32:46Z systemd[1]: snap.immich-distribution.postgres.service: Main process exited, code=exited, status=127/n/a

2024-06-11T04:32:46Z systemd[1]: snap.immich-distribution.postgres.service: Failed with result 'exit-code'.`

nsg commented 5 months ago

Hi, can you provide some additional information about your system and installation? Is this a new installation, or did it break during an upgrade? What OS/distribution do you use?

manjotsc commented 5 months ago

@nsg It's a new installation, 24.04 LTS

nsg commented 5 months ago

Have you any other processes running on port 5432? Do you see any output from this command? ss -ntl | grep 5432

Do you have this folder, and what do it contain? /var/snap/immich-distribution/common/pgsql/data/

manjotsc commented 5 months ago

@nsg Nothing is running on the port 5432 and "data"directory under "pgsql doesn't exit.

I created the "data" folder manually but still didn't work

nsg commented 5 months ago

I did a fresh install in a Ubuntu 24.04 VM and everything starts as expected. Have you changed anything with your snapd installation and or system that is non-standard?

Can you try to enter a shell inside the sandbox and manually run the setpriv command? Like this:

Enter the sandbox as the postgres service

sudo snap run --shell immich-distribution.postgres

Run setpriv and just print the environment. You should get something like uid=584788(snap_daemon) gid=584788(snap_daemon) groups=584788(snap_daemon)

$SNAP/usr/bin/setpriv --clear-groups --reuid snap_daemon --regid snap_daemon -- id

Do you see any errors or anything unexpected?

g-stick commented 5 months ago

I'm not the OP however I have the same issue. Ubuntu 24.04. Running sudo snap services results in the below.

$ sudo snap services
Service                                      Startup  Current   Notes
immich-distribution.acme                     enabled  inactive  timer-activated
immich-distribution.haproxy                  enabled  active    -
immich-distribution.immich-machine-learning  enabled  active    -
immich-distribution.immich-server            enabled  active    -
immich-distribution.manager                  enabled  active    -
immich-distribution.postgres                 enabled  inactive  -
immich-distribution.redis-server             enabled  active    -
immich-distribution.sync-service             enabled  active    -

when I check /etc/services, i see the below line for port 5432 postgresql 5432/tcp postgres # PostgreSQL Database finally running setpriv --clear-groups --reuid snap_daemon --regid snap_daemon -- id results in setpriv: setresuid failed: Invalid argument

nsg commented 5 months ago

Thank you!

Are you running this inside some form of container, or directly on hardware/virtual machine? Asking because nested containers (snapd is using container technologies) can sometimes cause problems.

Whats the output of snap version?

manjotsc commented 5 months ago

@g-stick @nsg I am running inside LXC container on Proxmox.

root@Immich:~# snap version
snap    2.63
snapd   2.63
series  16
ubuntu  24.04
kernel  6.8.4-3-pve
root@Immich:~# 

`root@Immich:~# $SNAP/usr/bin/setpriv --clear-groups --reuid snap_daemon --regid snap_daemon -- id

setpriv: setresuid failed: Invalid argument`

nsg commented 5 months ago

Ah, I have never tried to run a snap inside LXC. Most likely there is something missing, or not allowed by the LXC container.

I have no experience with Proxmox but reading https://pve.proxmox.com/wiki/Linux_Container I'm curious if you run privileged or unprivileged containers? Have you enabled nesting and fuse? (maybe that's default).

(Note: I think a VM should work, if that's an option)

g-stick commented 5 months ago

Thanks. I suspect it might be because of the LXC. I run it as unprivileged.

nsg commented 5 months ago

Let me know if you like some assistance to troubleshoot this. I think the problem is around user namespaces for the unprivileged user. The feature in snapd that I use is called System usernames. But my guess is that you will get better support at the Proxmox forums.

I use setpriv to change user and group from root to snap_daemon. I notice that the name is deprecated (but not removed), I run snapd 2.63 myself. I do this because postgres refuses to start as the root user.

I run immich-distribution (and snapd) inside an LXD container, but that's privileged (snapd implements a sandbox anyway). If you like the extra isolation a VM is probably easier, I did that for Home Assistant myself for example.