moonfire-nvr/guide/install-manual.md
Scott Lamb 1c904b925a many improvements to install docs/procedures
* in markdown files, use code fences rather than indented blocks.
    This is harder to screw up (one of them was off by a space so didn't
    render properly) and allows me to add info strings.

  * uniformly use "useradd" to create the user and group in all three
    places (install-manual.md, script-functions.sh, Dockerfile) rather
    than addgroup + adduser. Create a full home dir, which I suspect was
    the problem in #67. Don't allow customizing group name; it's always
    the same as the user.

  * install the sqlite3 package so that the "moonfire-nvr sql" command
    works properly.

  * remove "setup_db" function, which was out of place. Since the
    creation of the "moonfire-nvr init" command, this has to happen
    after installation of the binary. install.md gives instructions on
    this part anyway so remove it from the script.

  * give a proper command to create the db dir. It was creating it
    within the current directory, not within /var/lib/moonfire-nvr.
    Don't bother creating sample directory; "moonfire-nvr config"
    will do this.

  * when setting owners on a newly created directory, use a single
    "install -d" command rather than "mkdir" + "chown".

  * address confusion about whether sample file dirs need to be
    precreated. (Only when Moonfire NVR doesn't have write permissions
    on the parent.)

  * always just install the packaged version of ffmpeg rather than
    building our own. This has been usable since Debian/Raspbian 9
    Stretch; Debian/Raspbian 10 Buster is out now so there's no excuse
    for still running Debian/Raspbian 8 Jessie.

  * don't chown the UI directory; it can be owned by root as with
    the binary.

  * in scripts/install.sh, don't enable/start the service yet. It hasn't
    been configured.
2019-07-10 00:56:43 -07:00

3.9 KiB

Building and installing Moonfire NVR manually

This guide will walk you through building and installing Moonfire NVR manually. You should have already downloaded the source code as mentioned in install.md, and after completing these instructions you should go back to that page to complete configuration.

Building from source

There are no binary packages of Moonfire NVR available yet, so it must be built from source.

Moonfire NVR is written in the Rust Programming Language. In the long term, I expect this will result in a more secure, full-featured, easy-to-install software.

You will need the following C libraries installed:

  • ffmpeg version 2.x or 3.x, including libavutil, libavcodec (to inspect H.264 frames), and libavformat (to connect to RTSP servers and write .mp4 files).

    Note ffmpeg library versions older than 55.1.101, along with all versions of the competing project libav, don't support socket timeouts for RTSP. For reliable reconnections on error, it's strongly recommended to use ffmpeg library versions >= 55.1.101.

  • SQLite3.

  • ncursesw, the UTF-8 version of the ncurses library.

On recent Ubuntu or Raspbian, the following command will install all non-Rust dependencies:

$ sudo apt-get install \
               build-essential \
               libavcodec-dev \
               libavformat-dev \
               libavutil-dev \
               libncurses5-dev \
               libncursesw5-dev \
               libsqlite3-dev \
               libssl-dev \
               pkgconf \
               sqlite3 \
               tzdata

Next, you need Rust 1.33+ and Cargo. The easiest way to install them is by following the instructions at rustup.rs.

Finally, building the UI requires yarn.

Once prerequisites are installed, Moonfire NVR can be built as follows:

$ yarn
$ yarn build
$ cargo test
$ cargo build --release
$ sudo install -m 755 target/release/moonfire-nvr /usr/local/bin
$ sudo mkdir /usr/local/lib/moonfire-nvr
$ sudo cp -R ui-dist /usr/local/lib/moonfire-nvr/ui

Creating the user and database

You can create Moonfire NVR's dedicated user and SQLite database with the following commands:

$ sudo useradd --system --user-group --create-home --home /var/lib/moonfire-nvr moonfire-nvr
$ sudo -u moonfire-nvr -H sh -c 'cd && mkdir --mode=700 db'
$ sudo -u moonfire-nvr moonfire-nvr init

System Service

Moonfire NVR can be run as a systemd service. Create /etc/systemd/system/moonfire-nvr.service:

[Unit]
Description=Moonfire NVR
After=network-online.target

[Service]
ExecStart=/usr/local/bin/moonfire-nvr run \
    --db-dir=/var/lib/moonfire-nvr/db \
    --http-addr=0.0.0.0:8080
Environment=TZ=:/etc/localtime
Environment=MOONFIRE_FORMAT=google-systemd
Environment=MOONFIRE_LOG=info
Environment=RUST_BACKTRACE=1
Type=simple
User=moonfire-nvr
Nice=-20
Restart=on-failure
CPUAccounting=true
MemoryAccounting=true
BlockIOAccounting=true

[Install]
WantedBy=multi-user.target

Note that the HTTP port currently has no authentication, encryption, or logging; it should not be directly exposed to the Internet.

Tell systemd to look for the new file:

$ sudo systemctl daemon-reload

See the systemd documentation for more information. The manual pages for systemd.service and systemctl may be of particular interest.

Don't enable or start the service just yet; you'll need to do some more configuration first.

Completing installation

After the steps on this page, go back to Downloading, installing, and configuring Moonfire NVR to set up the sample file directory and configure the system.