November 11, 2015

Real time mirroring new Zone Minder event to Box.net cloud

Overview

This is my configuration:
  • Server OS: Ubuntu Server 14.04
  • ZoneMinder:1.28.1

Mounting box.com to local location 

This is how you can mount a box.com directory manually:
sudo mount -t davfs https://dav.box.com/dav /home/sergi/box.com
However it is better to do this via fstab. Information how to mount box.com locally is here. This will be mounted on startup.
If you do not want reboot run: sudo mount ~/box.com

Node installation 

I am using node.js 5.x, however this should work with node.js 0.12.x and above.
Installation information.

Fetching zmwatcher from GIT

Make sure you have installed git (sudo apt-get git)
  1. CD to some location (in my case I used home directory)
  2. Grab sources from github "git clone https://github.com/solvek/zmwatcher.git"

Running mirroring script

The mirroring script is located inside zmwatcher/samples/zmmirror/mirror.js
Open this file and add your config (basing on your hostname, hostname you can see at command prompt).
  • Before running the script you have to install it (its dependencies). Go to "cd ~/zmwatcher/samples/zmmirror"
  • Run "npm install" to install necessary dependencies
  • Run "sudo nodejs mirror.js" (in my case I am running it with root permissions because my regular user does not have permissions to events directory)
  • Modify samples/zmmirror/config.js with your values 
To run script mirroring manually:  sudo nodejs ~/zmwatcher/samples/zmmirror/mirror.js

Running mirroring script on linux startup 

Using systemd

  1. Create service file: sudo nano /etc/systemd/system/zmmirror.service
  2. Copy my systemd script from here
  3. Correct paths to node and index.js script
  4. Save
  5. Enable the service: sudo systemctl enable zmmirror.service
  6. Start the servcie: sudo systemctl start zmmirror.service
  7. Verify it is running: sudo systemctl status zmmirror.service

Using upstart system

A good description how to configure an upstart script.
  1. Create starting service script: sudo nano /etc/init/zmmirror.conf
  2. Copy my upstart script from here (another good script example)
  3. Correct paths to node, zmmirror.js script, output log
  4. Save
  5. Check syntax  sudo init-checkconf /etc/init/zmmirror.conf
  6. Start service: sudo service zmmirror start
  7. Check log: cat ~/zmmirror.log
That's all. This script should be started each time on system boot.
Useful commands:
  • Start service: sudo service zmmirror start
  • Stop service: sudo service zmmirror stop 
  • Restart service: sudo service zmmirror restart

Deletion of old files 

For deletion old content from box.com I am also using node.js script. The script is located here.
Here is how to schedule this script running once a day:
  1. Edit cleanup script: sudo nano ~/zmwatcher/samples/zmmirror/cleanup.js
  2. Specify your actual path.
  3. Run cron: sudo crontab -e
  4. Add line (run cleanup every day at 5 am): 0 5 * * * nodejs /home/sergi/zmwatcher/samples/zmmirror/cleanup.js 
To run cleanup script manually:  sudo nodejs ~/zmwatcher/samples/zmmirror/cleanup.js

No comments: