Server configuration

Startup script

In the DomotiGaServer section of the wiki there's a System V script for stopping and starting the DomotiGaServer. Distributions however are moving towards the Ubuntu Upstart mechanism as it's a fastly improved way of stopping and starting services in newer releases of their distribution. For this reason a Upstart script for DomotiGaServer was created.

Location and permissions

RDNZL advises you to run domotiga under your username and place domotiga in your homedirectory.
Some people however tend to feel more comfortable deviating from that advise and run domotiga from /opt. In most cases people run DomotiGaServer under their own username, some however create a separate user for the DomotiGaServer service.

Assumptions

script name: domotiga.conf
script location: /etc/init
username: domo (needs to be changed to the username you're running DomotiGa with) NEVER USE ROOT!
domotiga location: /home/domo/domotiga (needs to be changed to the location of DomotiGa)
mysql: this scripts wait for mysql daemon. If it not hosted on the same machine, please comment out the line about mysql

This script will not start unless the networkcard is running AND mysql AND the current runlevel is 2,3,4 or 5. This has been done on purpose as with Upstart it will start services in parallel unless you give it a clear direction to wait until certain other services are started.

Install

copy the script from /home/domo/domotiga/tools/domotiga.conf to /etc/init/
change /etc/init/domotiga.conf to your needs.
restart your server

Usage

$ sudo service domotiga start
[sudo] password for <user>:
domotiga start/running, process *****

$ sudo service domotiga stop
[sudo] password for <user>:
domotiga stop/waiting

Logging to Console

This script will make sure there will be no output to console. All console output is piped to /dev/null. DomotiGaServer housekeeping will make sure the log gets written to file as well in the regular logfile directory.

Monitor DomotiGa & Autostart using 'Monit'

In a case where your DomotiGaServer or SSHD crashed and you might want to use Monit to automatically restart your Domotica system.
This can be achieved using a program called 'Monit' and some configuration files.
Monit can even send you e-mails when it performs specific tasks.

Installation.

Installation can be done easily:

$ sudo apt-get update
$ sudo apt-get install monit

Configuration.

Exact configuration can be found here:
http://www.the-hawkes.de/monitor-your-raspberrypi-with-monit.html
and
http://bogdanioanliviu.no-ip.org/monitoring-raspberry-pi/

Domotiga Specific monitoring.

Within the /etc/monit/conf.d create 1 or several conf. files.

DomotiGaServer.conf

check process DomotigaServer with pidfile /var/run/DomotiGaServer3.gambas.pid
start program = "/etc/init.d/domotigaserver3 start" 
stop program = "/etc/init.d/domotigaserver3 stop" 
alert youremail@here.nl

Lighthttp.conf

check process lighthttp with pidfile /var/run/lighttpd.pid
start program = "/etc/init.d/lighttpd start" 
stop program = "/etc/init.d/lighttpd stop" 
if failed host <IP OF HOST HERE> port 80
protocol http then restart
if 5 restarts within 5 cycles then timeout
alert youremail@here.nl

MySql.conf

check process mysqld with pidfile /var/run/mysqld/mysqld.pid
group mysql
start program = "/etc/init.d/mysql start" 
stop program = "/etc/init.d/mysql stop" 
if failed host <IP OF HOST HERE> port 3306 then restart
if 5 restarts within 5 cycles then timeout
alert youremail@here.nl

SSH.conf

check process sshd with pidfile /var/run/sshd.pid
start program "/etc/init.d/ssh start" 
stop program "/etc/init.d/ssh stop" 
if failed host <IP OF HOST HERE> port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
alert youremail@here.nl

These files will keep your DomotiGa at a higher availability without user interruption.
Watch out if you are creating backups and your script stops DomotiGa! Monit will restart it.

Modify your backup script

# First stop Monit
  sudo /etc/init.d/monit stop

# First stop Domotiga
  sudo /etc/init.d/domotigaserver3 stop

# Create MySQL DUMP and .zip it
  mysqldump -u <root_user> -p<sql_password> domotiga | gzip -c > ~/domotiga/Backup-DB/domotiga-$(date +%Y-%m-%d-%H.%M.%S).sql.zip

# Move my log files and rename them
  for f in /mnt/logs/*.log; do mv -- "$f" "${f%.log}(-$(date +%Y-%m-%d-%H.%M.%S)).log"; done
  mv /mnt/logs/*.log /mnt/logs/backup

# First start Domotiga
  sudo /etc/init.d/domotigaserver3 start

# Then start Monit again
  sudo /etc/init.d/monit start

logrotate

DomotiGa will produce logfiles which grow, and grow, and grow. If left unchecked you can easily fill a disk with a large collection of logfiles especially when you enabled debug logging.

The most common method of keeping logfile growth in check is to use logrotate, and many packages are setup to work with this by default.
logrotate is (typically) executed once per day and rotates and compresses these logfiles, see Creating logfile archives with logrotate for more background.

Domotiga has a template logrotate configuration file that you can find as tools/logrotate.d.domotiga.

$ sudo mkdir /var/log/domotiga
$ sudo chown root:adm /var/log/domotiga
$ sudo chmod a+w /var/log/domotiga/
$ cd ~/domotiga
$ mv logs/* /var/log/domotiga
$ rmdir logs
$ ln -s /var/log/domotiga/ logs

$ sudo mv domotiga.d /etc/logrotate.d/domotiga
$ sudo chown root:root /etc/logrotate.d/domotiga

Backup and restore

Backup

During an upgrade, Domotiga will ask you to backup the database before the upgrade, but it is a good idea to make a backup more often. That can be done using the following command:

$ mysqldump -u root -p domotiga >~/domotiga.<date>/domotiga-backup.sql

To automate things you can create a domotigabackup.sh script:

echo domotiga-$(date +%Y-%m-%d-%H.%M.%S)-startcron >> /var/log/backup.txt
mysqldump -u root -p<yourpasswordhere> domotiga | gzip -c > /var/log/domotiga-$(date +%Y-%m-%d-%H.%M.%S).sql.zip
echo domotiga-$(date +%Y-%m-%d-%H.%M.%S)-mysqldump >> /var/log/backup.txt
mv /var/log/*.zip /mnt/<mounted_backup_location_here/Domotiga
echo domotiga-$(date +%Y-%m-%d-%H.%M.%S)-filecopie >> /var/log/backup.txt

This script creates a backup of my database in gzip format on /var/log and moves it to an external backup location (/mnt/<mounted_backup_location_here/Domotiga)
It also writes an entry into a file backup.txt so I can check if the backup completed (if necessary).

Next create a cronjob that will execute this script at for example 05:00 in the morning.
With this you will have a daily backup of your database.

Restore

Steps to restore a database using a database dump:

  1. Maybe DomotiGa is already running, so stop it
    ps -aux | grep gbr3 
    sudo kill <pid gbr3>
    
  2. Remove the old database:
    sudo mysql -u root -p
    SHOW DATABASES;
    DROP DATABASE databasenamegoeshere; (DROP DATABASE domotiga;)
    COMMIT;
    
  3. Restart Domotiga
    • Allow it to create an empty Database
    • Stop Domotiga
  4. Import your data
    sudo mysql -u root -p
    mysql -u root -p[root_password] [database_name] < dumpfilename.sql
    
  5. Restart Domotiga

Also available in: PDF HTML TXT