[Nix-dev] Hydra on NixOS
Mateusz Kowalczyk
fuuzetsu at fuuzetsu.co.uk
Mon Aug 11 04:58:38 CEST 2014
On 08/10/2014 02:04 PM, Peter Simons wrote:
> Hi Mateusz,
>
> > ExecStartPre=/nix/store/zlsf8wn19rl5qhs27lr5cs08xx718vdx-unit-script/bin/hydra-init-pre-start (code=exited, status=1/FAILURE)
> >
> > Aug 10 09:23:33 lenalee hydra-init-pre-start[6714]: createuser: creation
> > of new role failed: ERROR: role "hydra" already exists
> > Aug 10 09:23:33 lenalee systemd[1]: hydra-init.service: control process
> > exited, code=exited status=1
> > Aug 10 09:23:33 lenalee systemd[1]: Failed to start hydra-init.service.
> > Aug 10 09:23:33 lenalee systemd[1]: Unit hydra-init.service entered
> > failed state.
>
> on my machine, the hydra-init-pre-start script looks like this:
>
> | #! /nix/store/ihmkc7z2wqk3bbipfnlh0yjrlfkkgnv6-bash-4.2-p45/bin/bash -e
> | mkdir -m 0700 -p /var/lib/hydra/data
> | chown hydra /var/lib/hydra/data
> | ln -sf /nix/store/9nf5dyx4r6adlsy3dvfml859vjq6izlx-hydra.conf /var/lib/hydra/data/hydra.conf
> | if ! [ -e /var/lib/hydra/.db-created ]; then
> | /nix/store/m9dsdaxix24zsf5fs9wpi04i74dpl6rl-postgresql-9.2.8/bin/createuser hydra
> | /nix/store/m9dsdaxix24zsf5fs9wpi04i74dpl6rl-postgresql-9.2.8/bin/createdb -O hydra hydra
> | touch /var/lib/hydra/.db-created
> | fi
>
> Now, it appears that your machine has a properly initialized Postgres
> database, but it doesn't have the file /var/lib/hydra/.db-created. To
> remedy that, you can either create that file, or you can wipe the
> Postgres database for hydra. The first solution seems easier to me. :-)
>
> I hope this helps!
>
> Peter
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
OK, with this, help from an e-mail in private and some manual work, I
figured out how to setup up Hydra on NixOS. The gist of it is that there
is one vital step missing which is setting HYDRA_DBI before creating a
user. I'll try to outline it all in easy steps for future reference:
1. Set up everything as at [1] all the way until the point it tells you
should be read to log in. You will *not* have a /var/lib/hydra/.pgpass –
this is where the source of the problem is.
2. You need to create a user. If you simply hydra-create-user, you will
not succeed – the log in will not work. You first have to ensure that
the HYDRA_DBI variable is set or the user will go into the wrong
database, I think. There are few ways to find out your HYDRA_DBI. If you
set services.hydra.dbi then it's that. If you haven't, it's easy to check:
* run ‘systemctl status hydra-server’. This will tell you something like
“Loaded: loaded
(/nix/store/5w0r1va91pphmw3brafqgpp6l8bkc2d6-unit/hydra-server.service)”.
* Now you should run ‘cat
/nix/store/5w0r1va91pphmw3brafqgpp6l8bkc2d6-unit/hydra-server.service’,
adjusting to the appropriate path.
* You should see something along the lines of
“Environment="HYDRA_DBI=dbi:Pg:dbname=hydra;user=hydra"”
* export the variable, for example here I would run “export
HYDRA_DBI="dbi:Pg:dbname=hydra;user=hydra"”.
3. After you have set HYDRA_DBI, you should be able to hydra-create-user
and have it actually work on the proper database. You should now by able
to log in.
PS: The init service trouble I was having was because I wiped
/var/lib/hydra thinking it was permissions problem, wiping .db-create
alongside it. Recreating it fixes the init issue. I don't see any
problems due to my stupid wiping of /var/lib/hydra earlier just yet so
hopefully I don't get bitten by that.
Hope this helps someone.
[1]: https://nixos.org/wiki/Installing_hydra_as_nixos_module
--
Mateusz K.
More information about the nix-dev
mailing list