services
  1. forest (he/him)
    Profile picture
    : eyyyy I fixed it!!
  2. this was what fixed it:

    $ mv /var/lib/docker/volumes/microbin_microbin-data/_data/database.json /var/lib/docker/volumes/microbin_microbin-data/_data/database_backup.json
    $ systemctl restart microbin
    Failed to restart microbin.service: Unit microbin.service not found.
    $ systemctl restart docker-compose@microbin
    
    
    root@paimon:/etc/docker-compose/microbin# docker logs -n 100 microbin
    2023-11-22T21:17:15 [INFO] - MicroBin starting on http://0.0.0.0:8080
    2023-11-22T21:17:15 [INFO] - Database file pasta_data/database.json not found!
    2023-11-22T21:17:15 [INFO] - Database file pasta_data/database.json created.
    2023-11-22T21:17:15 [INFO] - Starting 1 workers
    2023-11-22T21:17:15 [INFO] - Actix runtime found; starting in Actix runtime
    
    
  3. Now, how did I know to do that ? Well, I cloned the microbin source code and opened it in vscode with the Rust language server plugin installed and working properly. Then I waited about 10 minutes for rust to figure out its entire existence 😴
  4. Figured it out by following the yellow brick road using the IDE tools in vscode after it finished rust-analyzing:
  5. which led me to

    pub fn read_all() -> Vec<Pasta> {
        if ARGS.json_db {
            super::db_json::read_all()
        } else {
            super::db_sqlite::read_all()
        }
    }
    
  6. json_db led me to

        #[clap(long, env = "MICROBIN_JSON_DB")]
        pub json_db: bool,
    
  7. I see in the docker-compose.yml thats one of the vars that it sets:
  8. root@paimon:/etc/docker-compose/microbin# cat docker-compose.yml 
    
    services:
      microbin:
        image: danielszabo99/microbin:latest
        container_name: microbin
    ....
        environment:
          MICROBIN_ADMIN_PASSWORD: ${MICROBIN_ADMIN_PASSWORD}
          MICROBIN_ADMIN_USERNAME: ${MICROBIN_ADMIN_USERNAME}
    ....
          MICROBIN_JSON_DB: ${MICROBIN_JSON_DB}
    ....
          MICROBIN_WIDE: ${MICROBIN_WIDE}
    
    (edited)
  9. and inside .env where the env vars are set, its set to true.
    (edited)
  10. root@paimon:/etc/docker-compose/microbin# cat .env | grep JSON_DB
    MICROBIN_JSON_DB=true
    
  11. so therefore I know its gonna call

            super::db_json::read_all()
    
  12. I followed that and found

    pub fn read_all() -> Vec<Pasta> {
        load_from_file().expect("Failed to load pastas from JSON")
    }
    
    fn load_from_file() -> io::Result<Vec<Pasta>> {
        let file = File::open(DATABASE_PATH);
        match file {
            Ok(_) => {
                ....
            }
            Err(_) => {
                ....
            }
        }
    }
    
  13. https://github.com/szabodanika/microbin/blob/master/src/util/db_json.rs#L45-L64

    if its OK then it tries to read the file and return it:

            Ok(_) => {
                let reader = BufReader::new(file.unwrap());
                let data: Vec<Pasta> = match serde_json::from_reader(reader) {
                    Ok(t) => t,
                    _ => Vec::new(),
                };
                Ok(data)
            }
    

    if its Err then it will create a new DB json file:

            Err(_) => {
                log::info!("Database file {} not found!", DATABASE_PATH);
                save_to_file(&Vec::<Pasta>::new());
    
                log::info!("Database file {} created.", DATABASE_PATH);
                load_from_file()
            }
    
  14. So I simply had the idea, Ok, this thing is not handling errors correctly, but it looks like it should be ... hmm what if I force it to take a different code path by removing the default database file "static DATABASE_PATH: &str = "pasta_data/database.json";"
    (edited)
  15. and that worked, after restarting the app, I can post pastas now 🍝
    (edited)