zadam / trilium

Build your personal knowledge base with Trilium Notes
GNU Affero General Public License v3.0
27.2k stars 1.9k forks source link

Error when updating to 0.46-latest with docker container; database readonly #2146

Closed nhendin closed 3 years ago

nhendin commented 3 years ago

I was updating a trilium install from an older version (0.43-latest) since I've not updated in a while, and when I update past 0.45-latest to 0.46-latest, trilium doesn't start. I get the below error in the log from the docker container.

Is there a manual database update I have to do to get a new schema or something?

I first tried 0.47-latest and that didn't work, so I manually bisected versions to find the last know working and first known not-working versions. Reverting back to 0.45-latest works fine, so I've got my data accessible. 0.46 and later fail to work for me.

For bug reports, PLEASE mention version of Trilium you're using and also include log files from following location:

Trilium version 0.46-latest (docker container running on linux) or later

docker logs trilium: /usr/src/app/node_modules/better-sqlite3/lib/pragma.js:14 stmt = this.prepare(PRAGMA ${source}); ^ SqliteError: attempt to write a readonly database at Database.pragma (/usr/src/app/node_modules/better-sqlite3/lib/pragma.js:14:16) at Object. (/usr/src/app/src/services/sql.js:9:14) at Module._compile (internal/modules/cjs/loader.js:1015:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10) at Module.load (internal/modules/cjs/loader.js:879:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Module.require (internal/modules/cjs/loader.js:903:19) at require (internal/modules/cjs/helpers.js:74:18) at Object. (/usr/src/app/src/services/notes.js:1:13) at Module._compile (internal/modules/cjs/loader.js:1015:30)

zadam commented 3 years ago

Hi, this usually means the database file is still open by some other process. Perhaps "old" trilium process is still running and keeping the db file still open?

nhendin commented 3 years ago

Thanks! I was careful to stop the previous container, but I will of course double check.

I also found this issue which could be relevant since I have not moved the data directory location inside the container, so the app may be trying to write to a location inside the container which is not read only, and not the bind mounted volume intended: https://github.com/zadam/trilium/issues/1747#issuecomment-799646048

zDEFz commented 3 years ago

Thanks! I was careful to stop the previous container, but I will of course double check.

I also found this issue which could be relevant since I have not moved the data directory location inside the container, so the app may be trying to write to a location inside the container which is not read only, and not the bind mounted volume intended: #1747 (comment)

Yea you must kinda do 'tricks' to make it work again. I had asked for a more seamless upgrade, perhaps with a helper tool, so that we are sure nothing bad (should happen). But that wasn't available, and mysterious problems like those migrated into the software to the point where I stopped using future versions. But hear me out:

I went to versions above 0.45.10 and had several problems, that weren't solvable. Ever since then, I reverted to 0.45.10 and that was my version to go to.

I think most of my complaints stem from greater than 0.45.10 to newer versions were of the nature of a worse User Experience. The Design decisions of the new appearance weren't to the benefit of the program imo. The current program seems to be awkwardly filled up with too many small UI elements.

BTW, it would be great if the program would be capable of only being used with the Keyboard only. Using Browser Add-Ons like Vimium doesn't solve this, but give a good hint in what is possible and more.

Whenever I bring the problems up that relate to the acquired problems such as the UI suddenly taking much more space, the shortcuts are handled differently, and the general feel is off, I feel that @zadam is offended, as my messages are then often deleted.

nhendin commented 3 years ago

I fixed it, Thanks to all for guidance. It was https://github.com/zadam/trilium/issues/1747#issuecomment-799646048 --- the data-dir moved inside the container and I had to adjust the mountpoint. I had also had a TRILIUM_DATA_DIR variable set in the docker-compose so my fix was not exactly what was mentioned in that bug word for word, but the principle is the same..

Docker compose snippet (other services and not relevant things like my traefik config have been clipped out).

Thanks all. --Neil.


<deleted, not needed for this example>
services:
   trilium:
    container_name: trilium
    image: zadam/trilium:0.47-latest
    restart: always
    environment:
      #    - TRILIUM_DATA_DIR=/data       #commented it out 9/5/2021 to move data dir to /home/node/trilium-data inside container
      - TZ=America/Los_Angeles
    volumes:
      - trilium:/home/node/trilium-data  #was /data --- moved for trilium 0.47 and later upgrade.
    networks:
      - web
    ports:
      - 8888:8080    
    restart: always
    labels:
      - "traefik.enable=true"
      -<Traefik stuff deleted, as not relevant here>
volumes:
  trilium:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /opt/docker/trilium```
zadam commented 3 years ago

Great to hear you managed to fix it. I admit I've already forgot about #1747.

zincnode commented 3 years ago

Thanks! I was careful to stop the previous container, but I will of course double check. I also found this issue which could be relevant since I have not moved the data directory location inside the container, so the app may be trying to write to a location inside the container which is not read only, and not the bind mounted volume intended: #1747 (comment)

Yea you must kinda do 'tricks' to make it work again. I had asked for a more seamless upgrade, perhaps with a helper tool, so that we are sure nothing bad (should happen). But that wasn't available, and mysterious problems like those migrated into the software to the point where I stopped using future versions. But hear me out:

I went to versions above 0.45.10 and had several problems, that weren't solvable. Ever since then, I reverted to 0.45.10 and that was my version to go to.

I think most of my complaints stem from greater than 0.45.10 to newer versions were of the nature of a worse User Experience. The Design decisions of the new appearance weren't to the benefit of the program imo. The current program seems to be awkwardly filled up with too many small UI elements.

BTW, it would be great if the program would be capable of only being used with the Keyboard only. Using Browser Add-Ons like Vimium doesn't solve this, but give a good hint in what is possible and more.

Whenever I bring the problems up that relate to the acquired problems such as the UI suddenly taking much more space, the shortcuts are handled differently, and the general feel is off, I feel that @zadam is offended, as my messages are then often deleted.

Hi, that's great advice. I deployed 0.45.10 on docker (that is the real out of the box). When I tried to deploy latest, 0.47.6, 0.47.6, etc. on docker, I encountered the following errors. However, I did not find any official documentation to solve this problem.😢

internal/fs/utils.js:312
    throw err;
    ^

Error: EACCES: permission denied, mkdir '/home/node/trilium-data/log'
    at Object.mkdirSync (fs.js:1009:3)
    at Object.<anonymous> (/usr/src/app/src/services/log.js:7:8)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/src/app/src/app.js:1:13)
    at Module._compile (internal/modules/cjs/loader.js:1068:30) {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/home/node/trilium-data/log'
}
zDEFz commented 3 years ago

Thanks! I was careful to stop the previous container, but I will of course double check. I also found this issue which could be relevant since I have not moved the data directory location inside the container, so the app may be trying to write to a location inside the container which is not read only, and not the bind mounted volume intended: #1747 (comment)

Yea you must kinda do 'tricks' to make it work again. I had asked for a more seamless upgrade, perhaps with a helper tool, so that we are sure nothing bad (should happen). But that wasn't available, and mysterious problems like those migrated into the software to the point where I stopped using future versions. But hear me out: I went to versions above 0.45.10 and had several problems, that weren't solvable. Ever since then, I reverted to 0.45.10 and that was my version to go to. I think most of my complaints stem from greater than 0.45.10 to newer versions were of the nature of a worse User Experience. The Design decisions of the new appearance weren't to the benefit of the program imo. The current program seems to be awkwardly filled up with too many small UI elements. BTW, it would be great if the program would be capable of only being used with the Keyboard only. Using Browser Add-Ons like Vimium doesn't solve this, but give a good hint in what is possible and more. Whenever I bring the problems up that relate to the acquired problems such as the UI suddenly taking much more space, the shortcuts are handled differently, and the general feel is off, I feel that @zadam is offended, as my messages are then often deleted.

Hi, that's great advice. I deployed 0.45.10 on docker (that is the real out of the box). When I tried to deploy latest, 0.47.6, 0.47.6, etc. on docker, I encountered the following errors. However, I did not find any official documentation to solve this problem.😢

internal/fs/utils.js:312
    throw err;
    ^

Error: EACCES: permission denied, mkdir '/home/node/trilium-data/log'
    at Object.mkdirSync (fs.js:1009:3)
    at Object.<anonymous> (/usr/src/app/src/services/log.js:7:8)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/usr/src/app/src/app.js:1:13)
    at Module._compile (internal/modules/cjs/loader.js:1068:30) {
  errno: -13,
  syscall: 'mkdir',
  code: 'EACCES',
  path: '/home/node/trilium-data/log'
}

Replace names with your trilium instance name.

Warning, untested.

$ mkdir /root/triliumbackup/ $ cp "/root/YourDockerFolder/" /root/triliumbackup/ $ docker container stop YourDockerName $ docker run -d -p 0.0.0.0:8080:8080 -v ~/trilium-data:/root/trilium-data --name YourDockerName zadam/trilium:0.45.10 $ docker exec -t -i -u root YourDockerName chown -R node:node /root/trilium-data $ chown -R 1000:1000 ~/trilium-data $ docker stop YourDockerName $ docker run -d -p 0.0.0.0:8080:8080 -v ~/trilium-data:/home/node/trilium-data zadam/trilium:latest

After upgrade it might be possible that you have to delete the .wal file and the .shm file in your docker directory