How to run stash-box bare metal?

I want to make a general purpose wiki based on stash-box but I’m unable to build it.

I’ve installed go, yarn and postgres

$ yay -S go yarn postgresql
$ sudo -u postgres initdb -D /var/lib/postgres/data
$ sudo systemctl enable --now postgresql.service
$ sudo -u postgres createuser -sW ${USER}
could not change directory to "/home/user": Permission denied
$ createdb stash-box
$ psql stash-box

stash-box=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 user      | Superuser, Create role, Create DB                          | {}

Then I’ve followed the given steps

$ make pre-ui
$ make ui
$ make build
$ ./stash-box --host 127.0.0.1 --port 9998
A new config file has been generated at /home/user/code/go/stash-box/stash-box-config.yml.
The database connection string has been defaulted to: postgres@localhost/stash-box?sslmode=disable
Please ensure this database is created and available, or change the connection string in the configuration file, then rerun stash-box.

On stash-box-config.yml I’ve written database: user:pass@postgres/stash-box?sslmode=disable and require_activation: false. Then I’ve executed stash-box for the second time and I get the error

$ ./stash-box --host 127.0.0.1 --port 9998
panic: setting PGSERVICEFILE not supported

goroutine 1 [running]:
github.com/lib/pq.parseEnviron.func2(...)
        /home/user/.local/share/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:1985
github.com/lib/pq.parseEnviron({0xc00036ca80, 0x99, 0xea83ac?})
        /home/user/.local/share/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:2008 +0xc4e
github.com/lib/pq.NewConnector({0xc0002d5e80, 0x37})
        /home/user/.local/share/go/pkg/mod/github.com/lib/pq@v1.10.5/connector.go:56 +0x12a
github.com/lib/pq.DialOpen({0x16cb8f8?, 0xc00004f0e0}, {0xc0002d5e80?, 0x1cb7400?})
        /home/user/.local/share/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:321 +0x37
github.com/lib/pq.Open(...)
        /home/user/.local/share/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:316
github.com/lib/pq.Driver.Open({}, {0xc0002d5e80, 0x37})
        /home/user/.local/share/go/pkg/mod/github.com/lib/pq@v1.10.5/conn.go:54 +0x85
database/sql.dsnConnector.Connect(...)
        /usr/lib/go/src/database/sql/sql.go:759
database/sql.(*DB).conn(0xc0003a52b0, {0x16cd710, 0xc00003e140}, 0x1)
        /usr/lib/go/src/database/sql/sql.go:1393 +0x763
database/sql.(*DB).PingContext(0xc0002d5e80?, {0x16cd710, 0xc00003e140})
        /usr/lib/go/src/database/sql/sql.go:851 +0x78
database/sql.(*DB).Ping(...)
        /usr/lib/go/src/database/sql/sql.go:873
github.com/golang-migrate/migrate/v4/database/postgres.WithInstance(0xc0003a52b0, 0xc0003ae0c0?)
        /home/user/.local/share/go/pkg/mod/github.com/golang-migrate/migrate/v4@v4.15.2/database/postgres/postgres.go:138 +0x3a
github.com/golang-migrate/migrate/v4/database/postgres.(*Postgres).Open(0xd97e80?, {0xc0002d5e40?, 0xc0002d5e40?})
        /home/user/.local/share/go/pkg/mod/github.com/golang-migrate/migrate/v4@v4.15.2/database/postgres/postgres.go:206 +0x71b
github.com/golang-migrate/migrate/v4/database.Open({0xc0002d5e40, 0x37})
        /home/user/.local/share/go/pkg/mod/github.com/golang-migrate/migrate/v4@v4.15.2/database/driver.go:98 +0xe9
github.com/golang-migrate/migrate/v4.NewWithSourceInstance({0xe873ba, 0x4}, {0x16cfc70?, 0xc000373950}, {0xc0002d5e40, 0x37})
        /home/user/.local/share/go/pkg/mod/github.com/golang-migrate/migrate/v4@v4.15.2/migrate.go:158 +0x149
github.com/stashapp/stash-box/pkg/database.(*PostgresProvider).runMigrations(0x474f66?, {0xc000039560, 0x2c})
        /home/user/code/go/stash-box/pkg/database/postgres.go:50 +0xe6
github.com/stashapp/stash-box/pkg/database.(*PostgresProvider).Open(0xd982a0?, {0xc000039560, 0x2c})
        /home/user/code/go/stash-box/pkg/database/postgres.go:31 +0x27
github.com/stashapp/stash-box/pkg/database.Initialize({0xe9c2e2, 0x8}, {0xc000039560, 0x2c})
        /home/user/code/go/stash-box/pkg/database/database.go:22 +0x6a
main.main()
        /home/user/code/go/stash-box/main.go:24 +0x3d

What am I doing wrong?

I have no specific knowledge about the process of setting this up
but some questions/issues present themselves to me when I read your post
of the sequence of commands and the results

Early on, at the third line/command:
$ sudo -u postgres createuser -sW ${USER}

you get the response:
could not change directory to "/home/user": Permission denied

Everything after that might fail because of that unhandled error.

sudo -u postgres
implies that you do have a system user named “postgres

Do you have it?

also, the variable ${USER} seems to hold the string: “user
which is probably from an example, but not a real user on your system
… the home directory /home/user does almost certainly not exist - it is likely meant to be replaced by a real, existing user account

… that is what I thought when I read your post
Maybe it helps.

The postgres user is the one that comes by default, and my user is indeed called user and /home/user does exist. I don’t know why it’s trying to change directory, but the postgres user doesn’t seem to have permission. But everything works fine anyways until later while trying to run the program. The postgres user with the same name as my user is created, so I can now use postgres commands without the need to change users. I read about creating this user in a tip in the wiki.

Ah. ok.

seems right, then.

Next issue, if that is so, is:

panic: setting PGSERVICEFILE not supported

I don’t know what investigation on it you have done
and I do not have any knowledge of setting up postgres database, at all

but googling for the term found this (for example)
it might help - don’t know
I really don’t

Grafana crashes when trying to connect to postgres: panic: setting PGSERVICEFILE not supported - #4 by svetb - Configuration - Grafana Labs Community Forums

… no experience with how to set up databases, be it postgres in particular or databases in general
I have no reference of what that means - but it may tell you something.
or
Perhaps someone else will know.

I’ve been told the same in the github issue, that the postgres database doesn’t appear to be listening but I’ve followed the steps in the wiki and when I use systemctl status everything looks ok.

❯ sudo systemctl status postgresql.service
● postgresql.service - PostgreSQL database server
     Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; preset: disabled)
     Active: active (running) since Mon 2022-10-17 19:12:56 CEST; 5 days ago
    Process: 2031844 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGROOT}/data (code=exited, status=0/SUCCESS)
   Main PID: 2031846 (postgres)
      Tasks: 7 (limit: 18434)
     Memory: 10.3M
        CPU: 1min 4.083s
     CGroup: /system.slice/postgresql.service
             ├─2031846 /usr/bin/postgres -D /var/lib/postgres/data
             ├─2031848 "postgres: checkpointer "
             ├─2031849 "postgres: background writer "
             ├─2031850 "postgres: walwriter "
             ├─2031851 "postgres: autovacuum launcher "
             ├─2031852 "postgres: stats collector "
             └─2031853 "postgres: logical replication launcher "

oct 17 19:12:56 arch-desktop systemd[1]: Starting PostgreSQL database server...
oct 17 19:12:56 arch-desktop postgres[2031846]: 2022-10-17 19:12:56.682 CEST [2031846] LOG:  starting PostgreSQL 14.5 o>
oct 17 19:12:56 arch-desktop postgres[2031846]: 2022-10-17 19:12:56.684 CEST [2031846] LOG:  listening on IPv6 address >

Maybe someone else will know.

… what about this linked support thread above?
Have you investigated whether the environment variable PGSERVICEFILE is set
for the user that runs your stash-box
and why?

1 Like

I don’t know how to set or unset the variable or how to check if it’s set as the arch wiki doesn’t mention anything on that.

Edit: oh wait this is an environment variable. Ok I thought it was a postgres variable. Well I’ve tried it and it’s set so I’ll have to find where it’s set, delete it and try again.

❯ echo $PGSERVICEFILE
/home/user/.config/pg/pg_service.conf

I don’t have that error after removing the PGSERVICEFILE export line I had in my .zshenv

Now I get the error

❯ ./stash-box --host 127.0.0.1 --port 9998
panic: dial tcp: lookup postgres on 192.168.1.1:53: no such host

The arch wiki says

Note: PostgreSQL uses TCP port 5432 by default for remote connections. Make sure this port is open in your firewall and able to receive incoming connections. You can also change it in the configuration file, right below listen_addresses

so I need to configure stash-box to listen to that port. But the only configuration they tell me to set in the stash-box readme is the postgres connection string.

192.168.1.1 is the router address, and I don’t know why would stash-box be looking there. And I don’t know what the port 53 is from.

According to this answer from another project, stash-box may be setup to work with the docker-compose.yml. So I may need to change the database url variable to point to my postgres installation instead. I’d just need to know what that variable is.

I think the address is configured like this so I may have made a mistake when writing mine:

environment:
  # DB_URL is formatted like: <databasetype>://<username>:<password>@<hostname>/<database>
  # Other examples are:
  # - mysql://hackmd:hackmdpassdatabase:3306/database
  # - sqlite:///data/sqlite.db (NOT RECOMMENDED)
  # - For details see the official sequelize docs: http://docs.sequelizejs.com/en/v3/
  - HMD_DB_URL=postgres://hackmd:hackmdpass@database:5432/hackmd

So probably instead of user:pass@postgres/stash-box?sslmode=disable as I had written it would be user:pass@localhost:5432/stash-box?sslmode=disable

the program is trying to do a DNS lookup - port 53 is DNS

But that is really as far as my knowledge goes - I cannot help any further.

After changing the postgres address it works. Thanks, I know it was a stupid error but I had been unable to solve it for a while and I couldn’t have done it without you noticing I had to change a variable.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.