Developing on MacOS

23 views
Skip to first unread message

Marlon Hendred

unread,
Jul 3, 2020, 3:01:47 PM7/3/20
to moonfire-nvr-users
Hi all,
Very cool project! I would like to learn rust and contribute to this project, but im having problems getting up and running on MacOS. I read somewhere in the guide that the author is using a mac for development. there are really good instructions for running on ubuntu but i couldn't find anything for mac. ive tried running the build and install scripts, but i keep getting 
`E0703 145152.265 main moonfire_nvr] Sys(ENOENT)`
when trying to do `./moonfire-nvr run --read-only`

running moonfire-nvr does give the help menu. im just trying to get the project up and running to start with. any ideas?

thanks!
-m

Scott Lamb

unread,
Jul 3, 2020, 7:49:40 PM7/3/20
to Marlon Hendred, moonfire-nvr-users
On Fri, Jul 3, 2020 at 12:01 PM Marlon Hendred <mhen...@gmail.com> wrote:
Hi all,
Very cool project! I would like to learn rust and contribute to this project,

Awesome!
 
but im having problems getting up and running on MacOS. I read somewhere in the guide that the author is using a mac for development.

Yes, I do. It looks like you already got it built. But for the record, I think the instructions for it are something like the following. The trouble I have is that I almost never set up a Mac from scratch like I do with Linux VMs, so I don't really remember what I had to do to set up the prerequisites on my machine. How closely does this match what you did?

(1) install xcode, agree to terms so tools like git work
(2) download/install HomeBrew
(3) brew install ffmpeg yarn
(4) download rust as described on https://www.rust-lang.org/tools/install
(5) build from source, similar to what the Linux instructions say:

$ cd moonfire-nvr
$ yarn
$ yarn build
$ cargo test
$ cargo build --release

(6) for a development setup on my laptop, I don't create a dedicated user or launchd service, much less give it a dedicated hard drive. I just symlink stuff to my working copy and run as myself.

$ sudo mkdir /usr/local/moonfire-nvr
$ sudo ln -s `pwd`/ui-dist /usr/local/moonfire-nvr/ui
$ sudo mkdir /var/lib/moonfire-nvr
$ sudo chown $USER:$USER /var/lib/moonfire-nvr
$ ln -s `pwd`/target/release/moonfire-nvr $HOME/bin/moonfire-nvr 
$ ln -s moonfire-nvr $HOME/bin/nvr
$ nvr init
 
there are really good instructions for running on ubuntu but i couldn't find anything for mac. ive tried running the build and install scripts, but i keep getting 
`E0703 145152.265 main moonfire_nvr] Sys(ENOENT)`
when trying to do `./moonfire-nvr run --read-only`

running moonfire-nvr does give the help menu. im just trying to get the project up and running to start with. any ideas?

Oops, that's a horrible error message, sorry. Would you like fixing that to be your first contribution?

If you set the environmental variable RUST_BACKTRACE=1, you'll get a backtrace that will help figure out the problem. I can reproduce this error and think it's from running without a database directory. Did you do moonfire-nvr init first?

$ cargo run -- run --db-dir=nonexistent
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running `target/debug/moonfire-nvr run --db-dir=nonexistent`
E0703 162357.407 main moonfire_nvr] Sys(ENOENT)

vs

$ RUST_BACKTRACE=1 cargo run -- run --db-dir=nonexistent
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s
     Running `target/debug/moonfire-nvr run --db-dir=nonexistent`
E0703 162422.820 main moonfire_nvr] Sys(ENOENT)

   0: backtrace::backtrace::trace_unsynchronized
   1: backtrace::backtrace::trace
   2: backtrace::capture::Backtrace::create
   3: backtrace::capture::Backtrace::new_unresolved
   4: failure::backtrace::internal::InternalBacktrace::new
   5: failure::backtrace::Backtrace::new
   6: <failure::error::error_impl::ErrorImpl as core::convert::From<F>>::from
   7: <failure::error::Error as core::convert::From<F>>::from
   8: moonfire_nvr::cmds::open_dir
   9: moonfire_nvr::cmds::open_conn
  10: moonfire_nvr::cmds::run::run::{{closure}}
  11: <std::future::GenFuture<T> as core::future::future::Future>::poll
  12: tokio::runtime::enter::Enter::block_on::{{closure}}
  13: tokio::coop::budget::{{closure}}
  14: std::thread::local::LocalKey<T>::try_with
  15: std::thread::local::LocalKey<T>::with
  16: tokio::runtime::enter::Enter::block_on
  17: tokio::runtime::thread_pool::ThreadPool::block_on
  18: tokio::runtime::Runtime::block_on::{{closure}}
  19: tokio::runtime::context::enter
  20: tokio::runtime::handle::Handle::enter
  21: tokio::runtime::Runtime::block_on
  22: moonfire_nvr::cmds::run::run
  23: moonfire_nvr::Args::run
  24: moonfire_nvr::main
  25: std::rt::lang_start::{{closure}}
  26: std::panicking::try::do_call
  27: __rust_maybe_catch_panic
  28: std::rt::lang_start_internal
  29: std::rt::lang_start
  30: main

 
If you look at the function in question (in src/cmds/mod.rs):

/// Locks the directory without opening the database.
/// The returned `dir::Fd` holds the lock and should be kept open as long as the `Connection` is.
fn open_dir(db_dir: &Path, mode: OpenMode) -> Result<dir::Fd, Error> {
    let dir = dir::Fd::open(db_dir, mode == OpenMode::Create)?;
    let ro = mode == OpenMode::ReadOnly;
    dir.lock(if ro { FlockArg::LockSharedNonblock } else { FlockArg::LockExclusiveNonblock })
       .map_err(|e| e.context(format!("db dir {:?} already in use; can't get {} lock",
                                      db_dir, if ro { "shared" } else { "exclusive" })))?;
    Ok(dir)
}


When the open command fails, it's just passing through the OS-level error (ENOENT) without adding any context about what it was trying to do. The lock call a couple lines below does add context. A similar map_err on the open call should fix the horrible error message you saw.


thanks!
-m

--
You received this message because you are subscribed to the Google Groups "moonfire-nvr-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moonfire-nvr-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/moonfire-nvr-users/6c636a63-005e-4aa6-80e1-cfb9ed86a917o%40googlegroups.com.


--

Marlon Hendred

unread,
Jul 7, 2020, 11:38:46 AM7/7/20
to moonfire-nvr-users
(1) install xcode, agree to terms so tools like git work
(2) download/install HomeBrew
(3) brew install ffmpeg yarn
(4) download rust as described on https://www.rust-lang.org/tools/install
(5) build from source, similar to what the Linux instructions say:
 
yes i have done steps 1-5 here

$ sudo mkdir /usr/local/moonfire-nvr
$ sudo ln -s `pwd`/ui-dist /usr/local/moonfire-nvr/ui
$ sudo mkdir /var/lib/moonfire-nvr
$ sudo chown $USER:$USER /var/lib/moonfire-nvr
$ ln -s `pwd`/target/release/moonfire-nvr $HOME/bin/moonfire-nvr 
$ ln -s moonfire-nvr $HOME/bin/nvr
$ nvr init
 
thanks! this was it i was missing these symlinks. after running these steps i then `nvr init` said SUCCESS. I was then able to start moonfire with `nvr run` and see it on localhost:8080

Oops, that's a horrible error message, sorry. Would you like fixing that to be your first contribution?

sure!
 
If you set the environmental variable RUST_BACKTRACE=1, you'll get a backtrace that will help figure out the problem.

nice! thanks for this RUST_BACKTRACE=1, TIL :)

I can reproduce this error and think it's from running without a database directory. Did you do moonfire-nvr init first?

i did run that first but i don't think the symlinks were set up correctly so i was getting the os error, and i also didn't have RUST_BACKTRACE=1 exported so i couldn't see what was going on. 

When the open command fails, it's just passing through the OS-level error (ENOENT) without adding any context about what it was trying to do. The lock call a couple lines below does add context. A similar map_err on the open call should fix the horrible error message you saw.

cool. i would be happy to have a go at fixing this as my first contribution! thanks for the information and quick response!

-marlon
Reply all
Reply to author
Forward
0 new messages