mujx / hakatime

Wakatime server implementation & analytics dashboard
https://hakatime.mtx-dev.xyz
The Unlicense
631 stars 47 forks source link

Problem running on Raspberry Pi #10

Closed FredrikMeyer closed 3 years ago

FredrikMeyer commented 4 years ago

Hi!

I'm trying the mujx/hakatime:latest-arm image, and have some trouble getting hakatime to work.

Running docker-compose -f docker-compose-deploy.yml up works fine. I had to add privileged: true, because I got an error saying that it couldn't read the the time.

I also had to change

    ports:
      - "127.0.0.1:8080:8080"

to

    ports:
      - "0.0.0.0:8080:8080"

to be able to open the UI on my computer (and not the Pi).

However, I cannot get past the login screen. First, I see POST http://192.168.0.13:8080/auth/refresh_token 400 (Bad Request) in the console log in Chrome. And when I try to register a new user, I see

haka_db    | 2020-09-22 20:09:55.632 UTC [44] ERROR:  relation "users" does not exist at character 16
haka_db    | 2020-09-22 20:09:55.632 UTC [44] STATEMENT:   SELECT * FROM users WHERE username = $1
hakatime   | [2020-09-22 20:09:55][hakatime.server][Error][8332e554f052][PID 1][ThreadId 14][hakatime-0.1.0-inplace-libhaka:Haka.Authentication src/Haka/Authentication.hs:205:9] OperationException "relation \"users\" does not exist"

in the application logs.

For completeness, this is how my now edited Docker compose file looks like:

version: "3"
services:
  server:
    container_name: hakatime
    image: mujx/hakatime:latest-arm
    privileged: true
    environment:
      # DB settings.
      HAKA_DB_HOST: haka_db
      HAKA_DB_PORT: 5432
      HAKA_DB_NAME: test
      HAKA_DB_PASS: test
      HAKA_DB_USER: test
      # Server settings.
      HAKA_CORS_URL: "http://192.168.0.13:8080"
      HAKA_PORT: 8080
      HAKA_SHIELDS_IO_URL: "https://img.shields.io"
      HAKA_ENABLE_REGISTRATION: "true" # Toggle after you've created your account.
      # Number of hours after which inactive browser sessions will expire (login required).
      HAKA_SESSION_EXPIRY: "24"
    ports:
      - "0.0.0.0:8080:8080"
  haka_db:
    container_name: haka_db
    image: postgres:11-alpine
    environment:
      POSTGRES_DB: test
      POSTGRES_PASSWORD: test
      POSTGRES_USER: test
    volumes:
      - ./docker/:/docker-entrypoint-initdb.d/
      - deploy_db_data:/var/lib/postgresql/data

volumes:
  deploy_db_data: {}
FredrikMeyer commented 4 years ago

Never mind!

I found the (stupid) error. I didn't realize you had to clone the whole repo to start docker-compose...

I guess you can close the issue. Thanks for the cool project!

mujx commented 4 years ago

Thanks for trying hakatime!

The problem was that postgres wasn't initialized. You don't have to clone the repo, but you do need to apply the sql files in order to create the db schema.

Btw, you shouldn't need privileged: true to run the container. Could you provide the logs from this error?

FredrikMeyer commented 4 years ago

Here's the logs without privileged:

pi@raspberrypi:~/hakatime $ docker-compose -f docker-compose-deploy.yml up
Starting hakatime ... done
Starting haka_db  ... done
Attaching to haka_db, hakatime
haka_db    |
haka_db    | PostgreSQL Database directory appears to contain a database; Skipping initialization
haka_db    |
haka_db    | 2020-09-22 20:49:04.075 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
haka_db    | 2020-09-22 20:49:04.075 UTC [1] LOG:  listening on IPv6 address "::", port 5432
haka_db    | 2020-09-22 20:49:04.093 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
hakatime   | clock_gettime: Operation not permitted
haka_db    | 2020-09-22 20:49:04.166 UTC [21] LOG:  database system was shut down at 2020-09-22 20:48:58 UTC
haka_db    | 2020-09-22 20:49:04.233 UTC [1] LOG:  database system is ready to accept connections
hakatime exited with code 1
^CGracefully stopping... (press Ctrl+C again to force)
Stopping haka_db  ...
Killing haka_db   ... done
^C

I found out about this from this blog post: https://stackoverflow.com/questions/53748644/linux-syscall-clock-settime-fails-with-eperm-in-docker-container

christian-fei commented 4 years ago

👍 also needed to include privileged: true to get it to work, this error else would make the hakatime container fail:

clock_gettime: Operation not permitted

Thanks for the support on the Pi!

timvoet commented 3 years ago

I got the instance up and running, though I can't get the register to work. The SQL instance logs show me everything was created, and yes I have the enable registration flag to true in the docker-compose-deploy.yml

mujx commented 3 years ago

Do you have any errors in hakatime's logs?

timvoet commented 3 years ago

hakatime | 192.168.1.59 - - [02/Oct/2020:20:26:34 +0000] "POST /auth/refresh_token HTTP/1.1" 400 - "http://raspberrypi.main:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" hakatime | 192.168.1.59 - - [02/Oct/2020:20:26:34 +0000] "GET /nunito-latin-400.4a62a00a.woff HTTP/1.1" 400 - "http://raspberrypi.main:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" hakatime | 192.168.1.59 - - [02/Oct/2020:20:26:34 +0000] "GET /nunito-latin-400.3a5373d7.woff2 HTTP/1.1" 400 - "http://raspberrypi.main:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" hakatime | 192.168.1.59 - - [02/Oct/2020:20:26:57 +0000] "POST /auth/register HTTP/1.1" 400 - "http://raspberrypi.main:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"

mujx commented 3 years ago

Seems like a CORS issue, check the server response payload on your browser.

You can fix it by setting the environment variable HAKA_CORS_URL to your domain. In your case it should be http://raspberrypi.main:8080/

timvoet commented 3 years ago

that was it. Oddly enough, i had changed them all before having the raspberry pi build issues. it's up and running now.

mujx commented 3 years ago

@FredrikMeyer @timvoet @christian-fei I was wondering if adding the SYS_TIME capability when running the container fixes the issue so you don't have to run as privileged. An example would be docker run --cap-add=SYS_TIME .. or replace privileged: true in the docker compose file with the following

cap_add:
  - SYS_TIME
mujx commented 3 years ago

Closing as resolved. Please re-open if that's not the case.