How to install Shinobi in a FreeNAS (11.3-RELEASE) Jail

I've been running Shinobi in a FreeNAS jail for more than 2 years now and although there were some hiccups, they are still manageable. I created a blog post on how to do that as well but that's for a previous version of FreeNAS. FreeNAS has had several updates since then and so did Shinobi so I decided to write up another post on how to setup and install the latest Shinobi (as of writing) to a FreeNAS (11.3-RELEASE) jail.

NOTE: The following setup guide is actually taken from the freebsd.sh and freenas.csh scripts that comes with Shinobi. Unfortunately, running either scripts produces some errors for me and installation fails at some point. So what I did is get the commands that works and I execute them one by one.

Installation and Setup

  1. Login to FreeNAS ui as root and navigate to Jails and add a Jail.
  2. Launch the Shell for that Jail. Must be root.
  3. To download Shinobi, we'll need to install the git application. Run the command below and follow the installation instructions.

    TIP: You can copy the commands here and paste them in FreeNAS shell by pressing Shift + Insert keys on your keyboard.
    pkg install git
  4. Shinobi requires certain software to run properly so we'll need to install them first. Type the following commands and follow the installation instructions to install.
    pkg install ffmpeg
    pkg install x264
    pkg install x265
    pkg install node
    pkg install npm
    pkg install mysql57-server
    
  5. Now we download Shinobi.
    git clone https://gitlab.com/Shinobi-Systems/Shinobi.git Shinobi
  6. Change directory to Shinobi..
    cd Shinobi
    It is also a good idea to know which directory Shinobi was installed.
    pwd
    Take note of this as you might need to change the path on some of my setups later. In this tutorial, I installed Shinobi in /root so you might see me referencing /root/Shinobi. Yours might be different so just replace the path if necessary.

  7. We'll need to do some additional setups for the MySQL server.
    • First of, enable mysql.
      sysrc mysql_enable=YES
    • Then start mysql.
      service mysql-server start
    • Now we need to login to mysql via command line but before we can do that, we need to know the password. After a fresh install of MySQL server, a file with a temporary password is generated. This file is usually located in /home/.mysql_secret. In this case, it should be in /root/.mysql_secret. To view the file, run the command below and make sure to take note of the password.
      cat /root/.mysql_secret
    • Login to MySQL
      mysql -h localhost -u root -p
      It will now ask you to type the password. Once logged in, we need to change the password for security purposes.
      alter user 'root'@'localhost' identified by 'newpassword';
    • Assuming we are still in the mysql command line interface, let's now add Shinobi user to the database.
      source /root/Shinobi/sql/user.sql
      If this work properly, you should see a message similar to "Query OK..."
    • Next, setup Shinobi framework to the database.
      source /root/Shinobi/sql/framework.sql
      This is it for the MySQL setup. Type quit to exit mysql command line interface.
  8. Now on to the Shinobi setups. I've listed the commands below. Just type them one by one.
    npm install -g npm -g
    npm install --unsafe-perm
    npm install pm2@3.0.0 -g
    cd Shinobi
    cp conf.sample.json conf.json
    cp super.sample.json super.json
    pm2 start camera.js
    pm2 start cron.js
    pm2 save
    pm2 list
    pm2 startup rcd

That's it. If everything went well, you should be able to access your Shinobi server through your browser and opening http://your_jail_ip_address:8080. Default username is admin@shinobi.video and password is admin.

P.S. I also developed an android application which you can get at Google Play. It needs a lot of work but if setup correctly, you will be able to view and control your cameras.