I’m trying this on Ubuntu 22.04 Rust’s cargo install seems to keep creating permission problems between what I have to install, compile and what gets published in the cargo “registry”, which causes issues at runtime when I run as lemmy:lemmy through systemctl.

If I run: cargo install lemmy_server --target-dir /usr/bin/ --locked --features embed-pictrs as a non-root user, I get permission denied issues with /usr/bin/.future-incompat-report.json and /usr/bin/release

If I run the build as a root user, and then manually copy the binaries to /usr/bin and chmod them to lemmy:lemmy, then try to run as lemmy:lemmy, it appears the binary is trying to access some “registry” files in /root/.cargo/registry (for which of course it does not have permissions.)

How do I fix this?

  • derek@lemmy.one
    link
    fedilink
    arrow-up
    7
    ·
    2 years ago

    I’ve seen guys here making PR’s to docs and install scripts, hope someone gonna do the same after finding solution for your question.

    • KIM_JONG_JUICEBOXOP
      link
      fedilink
      arrow-up
      3
      ·
      2 years ago

      Thanks.

      So if I go on a mad chmod spree, making /usr/bin/lemmy_server and all of its dependencies readable/executable (which is super insecure) I finally get to this log message in journalctl:

      Jun 07 13:50:57 ip-172-31-4-153 lemmy_server[3868]: thread 'main' panicked at 'C
      ouldn't run DB Migrations', /home/ubuntu/.cargo/registry/src/index.crates.io-6f1
      7d22bba15001f/lemmy_db_schema-0.17.3/src/utils.rs:165:25
      

      Which is this code:

      pub fn run_migrations(db_url: &str) {
        // Needs to be a sync connection
        let mut conn =
          PgConnection::establish(db_url).unwrap_or_else(|_| panic!("Error connecting to {db_url}"));
        info!("Running Database migrations (This may take a long time)...");
        let _ = &mut conn
          .run_pending_migrations(MIGRATIONS)
          .unwrap_or_else(|_| panic!("Couldn't run DB Migrations"));
        info!("Database migrations complete.");
      }
      

      Hope that helps someone figure this out.

      I’m pretty unhappy that I can’t get this to work.

        • KIM_JONG_JUICEBOXOP
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          2 years ago

          So I am able to build from the git repo.

          Had to remove rust from apt (v 1.65)

          And install rust from rustup (v 1.70)

          That fixes the build, but now I still get this db migrations error on startup.

          Jun 09 15:47:37 ip-x systemd[1]: Started Lemmy - A link aggregator for the fediverse.
          Jun 09 15:47:37 ip-x lemmy_server[15239]: 2023-06-09T15:47:37.238544Z  INFO lemmy_db_schema::utils: Running Database migrations (This may take a long time)...
          Jun 09 15:47:37 ip-x lemmy_server[15239]: thread 'main' panicked at 'Couldn't run DB Migrations', crates/db_schema/src/utils.rs:165:25
          Jun 09 15:47:37 ip-x lemmy_server[15239]: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
          Jun 09 15:47:37 ip-x systemd[1]: lemmy.service: Main process exited, code=exited, status=101/n/a
          
          

          I know it can connect to the db because I see it created some tables already.

          I wonder if this is related to this warning regarding schema, which I see during the build.

          warning: /root/git-clones/lemmy/crates/api_common/Cargo.toml: `default-features` is ignored for lemmy_db_schema, since `default-features` was not specified for `workspace.dependencies.lemmy_db_schema`, this could become a hard error in the future
          
          • RoundSparrow
            link
            fedilink
            arrow-up
            3
            ·
            edit-2
            2 years ago

            > thread ‘main’ panicked at ‘Couldn’t run DB Migrations’, crates/db_schema/src/utils.rs:165:25

            I fixed this by issuing:

            sudo -iu postgres psql -c “ALTER USER lemmy WITH SUPERUSER;”

            Obviously this has database security implications, but at least it identified that was why DB Migrations is failing.

            EDIT: I found the developers of Lemmy seem to have identified the cause for this, it’s just a couple SQL statements: https://github.com/LemmyNet/lemmy/pull/2983/commits/29c4144e61e97e895fb7eb37d2c257c8520fd6a6

            EDIT 2: The developers are currently treating this as a documentation bug: https://github.com/LemmyNet/lemmy-docs/issues/201

            • KIM_JONG_JUICEBOXOP
              link
              fedilink
              arrow-up
              2
              ·
              2 years ago

              Thank you!

              So the git based build instructions from @Grouchy@lemmy.grouchysysadmin.com works.

              What was missing for me was then the rust version and the full list of sql commands.

              1. Rust version
              
              Remove rust installed from Ubuntu apt repo (v 1.65)
              Install rust from rustup (v 1.70)
              
              2. Postgres commands
              
              sudo -iu postgres psql -c "CREATE USER lemmy WITH PASSWORD 'db-passwd';"
              sudo -iu postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy;"
              sudo -iu postgres psql -c "ALTER USER lemmy WITH SUPERUSER;"
              
              
              
              • RoundSparrow
                link
                fedilink
                arrow-up
                2
                ·
                2 years ago

                The lemmy-ui steps, the next part - are pretty outdated. It has instructions to install NodeJS 12.x, which is really far back. I have no idea which version the Docker install is using…

                The latest version of Node is 20

                • KIM_JONG_JUICEBOXOP
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  edit-2
                  2 years ago

                  Before I even get there, the instructions say I should be able to run

                  curl localhost:8536/api/{version}/site
                  

                  And it should return some json structure.

                  But I see this returning 404

                  lemmy_server[41511]: 2023-06-09T17:02:35.296098Z  INFO actix_web::middleware::logger: 127.0.0.1 "GET /api/0.17.3/site HTTP/1.1" 404 0 "-" "curl/7.81.0" 0.000074
                  

                  Is that the correct way to specify the version?

                  Is there a better log than journalctl which would actually tell me what REST endpoints it is using?

  • Grouchy@lemmy.grouchysysadmin.com
    link
    fedilink
    arrow-up
    4
    ·
    2 years ago

    Here’s how I do it. Might be worth giving it a shot. This is on FreeBSD, but I doubt that matters.

    git clone https://github.com/LemmyNet/lemmy.git lemmy
    cd lemmy
    git checkout 0.17.3
    git submodule init
    git submodule update --recursive --remote
    echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
    cargo build --release
    strip target/release/lemmy_server
    

    Then copy target/release/lemmy_server to wherever you want to run it.

    • KIM_JONG_JUICEBOXOP
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      Thanks. On cargo build --release I get this

      ...
         Compiling strum_macros v0.24.3
         Compiling deadpool v0.9.5
         Compiling tokio-postgres v0.7.8
         Compiling enum_delegate v0.2.0
         Compiling doku v0.20.0
         Compiling jsonwebtoken v8.3.0
      error: failed to run custom build command for `lemmy_utils v0.17.3 (/home/ubuntu/git-clones/lemmy/crates/utils)`
      
      Caused by:
        process didn't exit successfully: `/home/ubuntu/git-clones/lemmy/target/release/build/lemmy_utils-6fa456450f9c975a/build-script-build` (exit status: 1)
        --- stdout
        cargo:rerun-if-changed=translations/email/en.json
        cargo:rerun-if-changed=translations/email/ko.json
        cargo:rerun-if-changed=translations/email/pt.json
      
        --- stderr
        Error: Parse(InvalidParameters { key: "new_application_subject", missing: ["hostname"], unknown: ["instance"] })
      warning: build failed, waiting for other jobs to finish...
      ubuntu@xxx:~/git-clones/lemmy$ 
      
      
      • RoundSparrow
        link
        fedilink
        arrow-up
        3
        ·
        2 years ago

        I was able to follow these build from git checkout instructions on Ubuntu 22.04, I didn’t get the error you got.

        What version of rust/cargo are you using? cargo --version I get:
        cargo 1.70.0 (ec8a8a0ca 2023-04-25)

      • Grouchy@lemmy.grouchysysadmin.com
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        2 years ago

        Yes, my instructions above are only for Lemmy. Here’s my complete setup.

        1: Build Lemmy
        cd /root
        git clone https://github.com/LemmyNet/lemmy.git lemmy
        cd lemmy
        git checkout 0.17.3
        git submodule init
        git submodule update --recursive --remote
        echo "pub const VERSION: &str = \"$(git describe --tag)\";" > "crates/utils/src/version.rs"
        cargo build --release
        strip target/release/lemmy_server
        
        2: Build lemmy-ui
        cd /root
        git clone https://github.com/LemmyNet/lemmy-ui.git --recursive lemmy-ui
        cd lemmy-ui
        git checkout 0.17.3
        yarn install --pure-lockfile
        yarn build:prod
        
        3: Built pict-rs
        cd /root
        git clone https://git.asonix.dog/asonix/pict-rs.git pictrs
        cd pictrs
        git checkout v0.3.3
        cargo build --release
        strip target/release/pict-rs
        

        I’m running the binaries generated from those instructions at my own instance. Again, this is FreeBSD, not Linux, so your results may vary. I can’t imagine there’s any real difference though. I suspect the errors you’re getting are due to missing dependencies on your OS.

  • Kakise@mlem.a-smol-cat.fr
    link
    fedilink
    arrow-up
    1
    ·
    2 years ago

    A fix would be to not use the —target-dir option, compile as the lemmy user, and then use sudo to move target/release/lemmy_server to /usr/bin. It should fix all your issues

  • zergling_man@lemmy.perthchat.org
    link
    fedilink
    arrow-up
    1
    ·
    2 years ago

    … Build as non-root, install as root? AUR PKGBUILD just werks. All the functions in here are run as non-root though, the package() function installs to a fake directory tree, and then pacman, run as root, copies that into real tree. It works out to be one file total. Not sure why cargo install wants to put some other garbage in.

    • zergling_man@lemmy.perthchat.org
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      Oh and warning to anyone who wants to use that AUR package: You’ll need to fix pkgver and _commit before running it. Actually fixing pkgver may not be necessary. But yeah, grab the commit hash for 0.17.3 tag.