2018-08-24 23:45:46 -04:00
|
|
|
# Building and installing Moonfire NVR manually
|
2018-03-03 09:41:15 -05:00
|
|
|
|
2018-08-24 23:45:46 -04:00
|
|
|
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](install.md), and after completing these instructions you should go
|
|
|
|
back to that page to complete configuration.
|
2018-03-03 09:41:15 -05:00
|
|
|
|
|
|
|
## 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](https://www.rust-lang.org/en-US/). 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](http://ffmpeg.org/) 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](http://libav.org), 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](https://www.sqlite.org/).
|
|
|
|
|
|
|
|
* [`ncursesw`](https://www.gnu.org/software/ncurses/), 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 \
|
2018-08-31 20:19:24 -04:00
|
|
|
pkgconf \
|
|
|
|
tzdata
|
2018-03-03 09:41:15 -05:00
|
|
|
|
2019-05-31 19:19:04 -04:00
|
|
|
Next, you need Rust 1.33+ and Cargo. The easiest way to install them is by
|
2018-08-07 16:23:32 -04:00
|
|
|
following the instructions at [rustup.rs](https://www.rustup.rs/).
|
2018-03-03 09:41:15 -05:00
|
|
|
|
|
|
|
Finally, building the UI requires [yarn](https://yarnpkg.com/en/).
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-08-24 23:45:46 -04:00
|
|
|
## Creating the user and database
|
2018-03-03 09:41:15 -05:00
|
|
|
|
2018-08-24 23:45:46 -04:00
|
|
|
You can create Moonfire NVR's dedicated user and SQLite database with the
|
|
|
|
following commands:
|
2018-03-03 09:41:15 -05:00
|
|
|
|
|
|
|
$ sudo addgroup --system moonfire-nvr
|
|
|
|
$ sudo adduser --system moonfire-nvr --home /var/lib/moonfire-nvr
|
|
|
|
$ sudo mkdir /var/lib/moonfire-nvr
|
2018-08-24 23:45:46 -04:00
|
|
|
$ sudo chown moonfire-nvr:moonfire-nvr /var/lib/moonfire-nvr
|
2018-03-03 09:41:15 -05:00
|
|
|
$ sudo -u moonfire-nvr -H mkdir db sample
|
|
|
|
$ sudo -u moonfire-nvr moonfire-nvr init
|
|
|
|
|
2018-08-24 23:45:46 -04:00
|
|
|
## System Service
|
2018-03-03 09:41:15 -05:00
|
|
|
|
2018-08-24 23:45:46 -04:00
|
|
|
Moonfire NVR can be run as a systemd service. Create
|
2018-03-03 09:41:15 -05:00
|
|
|
`/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 \
|
2019-06-19 18:17:50 -04:00
|
|
|
--http-addr=0.0.0.0:8080 \
|
|
|
|
--allow_unauthenticated_scopes='view_video: true'
|
2018-03-03 09:41:15 -05:00
|
|
|
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-abnormal
|
|
|
|
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.
|
|
|
|
|
2018-08-24 23:45:46 -04:00
|
|
|
Tell `systemd` to look for the new file:
|
2018-03-03 09:41:15 -05:00
|
|
|
|
|
|
|
$ sudo systemctl daemon-reload
|
|
|
|
|
|
|
|
See the [systemd](http://www.freedesktop.org/wiki/Software/systemd/)
|
|
|
|
documentation for more information. The [manual
|
|
|
|
pages](http://www.freedesktop.org/software/systemd/man/) for `systemd.service`
|
|
|
|
and `systemctl` may be of particular interest.
|
2018-08-24 23:45:46 -04:00
|
|
|
|
|
|
|
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](install.md) to set up the sample file directory and
|
|
|
|
configure the system.
|