Skip to content

Instantly share code, notes, and snippets.

@Matho
Created June 22, 2023 17:49
Show Gist options
  • Save Matho/54cdeb242be058bba75207468bd24c53 to your computer and use it in GitHub Desktop.
Save Matho/54cdeb242be058bba75207468bd24c53 to your computer and use it in GitHub Desktop.
Reolink camera with Shinobi FTP

I'm using Shinobi via Docker. I have Reolink Duo 2 cameras which are configured to store videos via ftp in Shinobi FTP.

I have following configuration: /data/shinobi/config$ cat conf.json

{
   "port": 8080,
   "orphanedVideoCheckMax": 1000,
   "insertOrphans": true,
   "debugLog": false,
   "enableFaceManager": false,
   "videosDir": "__DIR__/videos",
   "passwordType": "sha256",
   "detectorMergePamRegionTriggers": true,
   "wallClockTimestampAsDefault": true,
   "useBetterP2P": true,
   "smtpServerOptions": {
      "allowInsecureAuth": true
   },
   "addStorage": [
      {
         "name": "second",
         "path": "__DIR__/videos2"
      }
   ],
   "db": {
      "host": "localhost",
      "user": "USER",
      "password": "PASSWORD",
      "database": "ccio",
      "port": 3306
   },
   "mail": {
      "service": "gmail",
      "auth": {
         "user": "your_email@gmail.com",
         "pass": "your_password_or_app_specific_password"
      }
   },
   "cron": {},
   "pluginKeys": {},
   "cpuUsageMarker": "CPU",
   "subscriptionId": "sub_XXXXXXXXXXXX",
   "thisIsDocker": true,
   "ssl": {},
   "dropInEventServer": true,
   "ftpServer": true,
   "dropInEventsDir": "/dev/shm/streams/dropInEvents",
   "ftpServerPort": 21212,
   "ftpServerUrl": "ftp://0.0.0.0:{{PORT}}",
   "ftpServerPasvMinPort": 10052,
   "ftpServerPasvMaxPort": 10085,
   "ftpServerPasvUrl": "YOURIP"
}

If you are using PASV transport port, you need to specify min-max ports and open firewall for the ports

sudo ufw allow 21212
sudo ufw allow 10052:10085/tcp
sudo ufw allow 10052:10085/udp

I have folowing docker compose recipe. I'm using Traefik and my custom image for aarch64 Raspberry PI 4:

version: "3.6"

services:
  shinobi-systems:
    image: 'matho-shinobi-image-5th-feb-2023:latest'
    #shm_size: "1024M" # this doesnt work for swarm
    networks:
      spilo_db-nw: # my network name and IP
        ipv4_address: 10.0.2.4
    ports:
      - '7999:8080/tcp' # Traefik will listen on 7999 and Docker will forward 7999 to port 8080 in Docker container
      - '10052-10085:10052-10085' # ports for PASV ftp transport mode
      - '21212:21212' # main control FTP port
      - '20:20' 
    volumes:
      - '/data/shinobi/streams:/dev/shm/streams:rw'
      - '/data/shinobi/config:/config:rw'
      - '/data/shinobi/customAutoLoad:/home/Shinobi/libs/customAutoLoad:rw'
      - '/data/shinobi/database:/var/lib/mysql:rw'
      - '/data/shinobi/videos:/home/Shinobi/videos:rw'
      - '/data/shinobi/plugins:/home/Shinobi/plugins:rw'
      - '/etc/localtime:/etc/localtime:ro'
      - type: tmpfs
        target: /dev/shm
        tmpfs:
          size: 700000000 # (700MB ) If `Max File Size (MB)` in Reolink camera is set to 100MB, you need to set it to minimum 100MB 
    deploy:
      resources: # optional
        limits:
          cpus: '0.5'
          memory: 1024M
      labels:
        - traefik.http.middlewares.shinobi-redirect-web-secure.redirectscheme.scheme=https
        - traefik.http.routers.shinobi.middlewares=shinobi-redirect-web-secure
        - traefik.http.routers.shinobi.rule=Host(`shinobi.YOURDOMAIN.com`)
        - traefik.http.routers.shinobi.entrypoints=web

        - traefik.http.routers.shinobi-secure.rule=Host(`shinobi.YOURDOMAIN.com`)
        - traefik.http.routers.shinobi-secure.tls.certresolver=le # if you want Lets encrypt cert auto-regenerated each 3 months by Traefic
        - traefik.http.routers.shinobi-secure.entrypoints=web-secure
        - traefik.http.services.shinobi-secure.loadbalancer.server.port=8080
        - traefik.docker.network=spilo_db-nw

      placement: # optional, for my architecture
        constraints:
          - "node.role==worker" 
      replicas: 1

networks:
  spilo_db-nw:
    external: true

Probably it is needed to create data folders, so do:

sudo mkdir /data/shinobi/config
sudo mkdir /data/shinobi/customAutoLoad
sudo mkdir /data/shinobi/database
sudo mkdir /data/shinobi/videos
sudo mkdir /data/shinobi/plugins
sudo mkdir /dev/shm/streams

Then change password for your superuser at https://shinobi.YOURDOMAIN.com/super and create new subaccount. You will use your subaccount credentials to connect to FTP, not your super user credentials.

Also, I'm having issues with FileZilla conections, so I need to connect via Ubuntu Nautilus folder viewer program.

At this point, I didnt get to work FTPS, only basic FTP connection. So do not check FTPS in your Reolink camera, use plain ftp.

If you are using Reolink cameras, I have found, that I need to switch "Generate subfolder by" under FTP settings to "Close". It will not create subfolders by datetime, but it will upload everything to one folder. With another selected option, the processed videos in Shinobi was cuted to smaller video duration.

Zabbix: I'm using Zabbix agent on my server. If you specify port 10050 for Shinobi FTP, this will create conflict. Make sure 10050 is free and if you are using Zabbix, do not specify this port to min-max range in config.

If you have still issues with uploading, you can create new docker image. My inspiration is from https://trzeci.eu/fixing-permission-of-files-created-from-docker/

Navigate to ~/docker/build/ShinobiSource/Docker and open init.sh

Add umask 0000, so the file begin with following lines:

#!/bin/sh
set -e

umask 0000 # Added by Matho

$ cd ShinobiSource/

Build your own image
$ sudo docker build --tag matho-shinobi-image-5th-feb-2023 .

Not sure if the umask hotfix is correct, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment