Running ot-recorder (OwnTracks) from systemd

# editor /lib/systemd/system/ot-recorder.service

[Unit]
Description=OwnTracks-Recorder
After=network.target

[Service]
EnvironmentFile=/etc/mosquitto/environment
ExecStart=/usr/local/sbin/ot-recorder -H localhost -p 8883 –norec –http-host <localip> –clientid <username> “owntracks/#”
Restart=always
KillMode=process

[Install]
WantedBy=multi-user.target

# editor /etc/mosquitto/environment

OTR_CAFILE=”/etc/ca.crt”
OTR_PASS=”<Password>”

Zabbix 3.0 under Debian Jessie, with nginx

I wanted to try Zabbix, after reading some posts about it being good – I’m starting to get tired of Nagios, and I really dont like that they dont have native Debian packages – not even from own repo.

… However, Zabbix is not very well documented to install, and especially not with nginx!
This post is now updated with instructions for Zabbix 3.0.

 

Here goes, my first draft:
https://www.zabbix.com/documentation/3.0/manual/installation/install_from_packages#debianubuntu

Copy link for Jessie, then do:

# wget <paste>

# dpkg -i zabbix-release*.deb

# apt-get install zabbix-frontend-php nginx-light php5-fpm zabbix-server-mysql php5-mysql

# mysql_secure_installation

#  mysql -u root -p
Create database, then setup user and passwords:
CREATE DATABASE zabbix character set utf8 collate utf8_bin;
CREATE USER ‘zabbix’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON zabbix.* TO ‘zabbix’@’localhost’ IDENTIFIED BY ‘password’;
QUIT;

Create tables and stuff in sql.
# zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

Nginx-config:
# cp /etc/nginx/sites-available/default /etc/nginx/sites-available/orig.default
# echo “” > /etc/nginx/sites-enabled/default
# editor /etc/nginx/sites-enabled/default
“upstream php-handler {
server unix:/var/run/php5-fpm.sock;
}

server {
location / {
root /usr/share/zabbix;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /usr/share/zabbix;
fastcgi_pass php-handler;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name;
include fastcgi_params;
}
}

# editor /etc/php5/fpm/php.ini
Search and replace prompted values (from webpage), then restart php
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Europe/Copenhagen
always_populate_raw_post_data = -1

# systemctl restart php5-fpm
# systemctl restart nginx

Open up tcp/10051 and tcp/80, and connect to tcp/80 using a standard web-browser.
Default username/password is Admin/zabbix.
(that’s a capital A.)

Enjoy and stuff.

Using systemd with Domoticz

I wanted to switch from old sysvinit to systemd, I’m starting to like systemd more and more, and I had some issues with Domoticz segfault’ing on me. (I’m always running latest git, so I can hardly blame them.)

What I had to do follows:

Remove the old sysvinit-scripts:
:~# update-rc.d domoticz remove

Move the old init-script away, just in case.
:~# mv /etc/init.d/domoticz ./domoticzinit

Create the new systemd.service, adjust as needed.

:~# editor /lib/systemd/system/domoticz.service

[Unit]
Description=Domoticz Home Automation
After=network.target

[Service]
ExecStart=/home/domo/domoticz/domoticz -daemon -www 8080 -sslwww 443
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target

Enable the new service

:~# systemctl enable domoticz.service

Reboot to verify, or do what makes you confident that this works as intended.

:~# systemctl status domoticz.service

Rejoice, and delete the old init-script.

:~# rm ./domoticzinit

Domoticz, RFXCom and transmit signals

For a long time, I had major issues with sending commands via RFXtrx433 under Domoticz (I think I had the problem with my brief encounter with OpenHAB also.)

I was unable to figure out why, save for the fact that it worked when I first got the RFXtrx433 and tried Domoticz – I therefore assumed the error was “in software”, either with adding the device or a bug in Domoticz.

I recently did some searching on a somewhat-similar issue, and I found a hint on a Homeseer-forum, that if the wrong firmware is loaded, transmit won’t work.

I went straight to www.rfxcom.com and downloaded what I assumed was the correct firmware, making sure it was the type 1 since that was one of the caveats the blogpost noted, and flashed that via Domoticz.
(note, triple-check if that’s what you also need, read the included .txt-file in the firmware-zip.)

After the flash, suddenly it just worked.
I guess I did a bad flash or used the wrong firmware once.

The only error I ever got was: “wrong command received from application” in Domoticz.
If you got that one, searched around and found nothing – you might just need a new firmware.

LVM, LUKS and separate /home (or other) during install of (x)Ubuntu 15.10

In general I’m not a huge fan of linux desktops, but XFCE4 is just decent enough that I tend to stick with it.

I had to reinstall my laptop with Xubuntu 15.10 due to a service repair on it, I used to have a custom install with a separate /home, all encrypted with LUKS.

This requires me to either use a keyfile, or input the encryption password twice/trice (once for root, swap and home).
Needless to say, I didn’t want this again.

Apparently there is no documented way to do this using the official installer, but I found some hints around. These are my notes, but first – my sources:
https://askubuntu.com/questions/663332/what-is-the-proper-way-to-install-ubuntu-15-04-with-lvm-luks-and-manual-partit
https://askubuntu.com/questions/654638/how-to-increase-boot-partition-size-when-installing-ubuntu-14-04-using-the-use/678074#678074
http://ftp.dc.volia.com/pub/debian/preseed/partman-auto-recipe.txt

So, apparently what you can do is open partman’s auto-recipe for the installation, edit that around, and suddenly a default LVM with LUKS-install includes a separate /home with some pre-defined sizes.

From the liveCD-environment, before starting the installer, open a terminal.

sudo nano /lib/partman/recipes/30atomic

Find the block that contains “mountpoint{ / }” and in the beginning replace the third value with the max size for your root partition.
Examples, turn this:

500 10000 1000000 ext4
	$primary{ }
	$bootable{ }
	method{ format }
	format{ }
	use_filesystem{ }
	filesystem{ ext4 }
	mountpoint{ / } .

Into this:
500 10000 50000 ext4
        $primary{ }
        $bootable{ }
        method{ format }
        format{ }
        use_filesystem{ }
        filesystem{ ext4 }
        mountpoint{ / } .

Notice that it's the third value that's important, this changes the max-allowed size from "so big it equals max" and down to "50gb".

And then add something like this at the end:
100 10000 1000000000 ext4
        method{ format }
        format{ }
        use_filesystem{ }
        filesystem{ ext4 }
        mountpoint{ /home } .

This will instruct partman to create a separate /home, with "at least" 100mb, and at most "1000000000" (back to the "so big it equals max"-value again) and it makes it so that your root partition wont fill up the drive, or have to split it with your /home.

Save the file, and then start the installer.

Select the default option for doing LVM and LUKS (encrypt my stuff, partition with LVM, or something like that.)

Good luck.

MotionPie Cam in Domoticz with Motion detection

I wanted to try setting up my Raspberry Pi-camera, and I wanted to integrate it with Domoticz.

I did some manual labor for setting up a dedicated IP-cam from scratch, but after searching around I found MotionPie ( https://github.com/ccrisan/motionPie ).
No point re-inventing the wheel, so I loaded it up according to the installation manual, and got it up network-wise.

The following is needed to be configured in order for Domoticz to work:
IP Address: <ipaddress>
Port:<default-is-80>
Username:<blank>
Password:<blank>
ImageURL:picture/1/current/

If you create a dummy switch in Domoticz, you can have motionpie activate that switch using Motion Notifications:
Enable running of commands, and insert the following command:
curl ‘http://<IP-to-domoticz&gt;:8080/json.htm?type=command&param=switchlight&idx=<IDX>&switchcmd=On’
Where <IP-to-domoticz> is self-explanatory, and <IDX> is the ID-number for the switch.
Don’t forget to edit the switch so it’s a motion sensor, and set a custom off-delay.
MotionPie won’t trigger it “off” for you.

Restore MySQLdump –all-databases to other Debian-install

A backup using fex:

:~# /usr/bin/mysqldump –defaults-file=/etc/mysql/debian.cnf –events –all-databases > all.sql

(It’s supposed to be two -‘es before defaults-file, events and all-databases)

Can be restored easily on a new install using this commands:

:~# scp all.sql user@newserver: # To copy the backup to the new server.

On the new server:
:~# mysql -u root -p < all.sql

Exim4 LAN-relay on Debian Jessie with external smarthost

As part of a restructure at home I wanted to setup my router to be able to send email for all the servers on my LAN.
I tested it using Fastmail, but I know this will also work with Gmail. (I used the same setup when I had a gmail-account)

I did it like so:
:~# apt-get install exim4

:~# dpkg-reconfigure exim4-config

“Mail sent by smarthost; no local mail”

“System mail name: Home.Local”

IP-Address to listen on: Type in the LAN-IP of your router, or 0.0.0.0 if it’s entirely on a private/trusted LAN. (for example a standalone raspberry PI.)

“Other destinations for which mail is accepted: <leave blank>”

“Visible Domain name for local users: Home.Local”

IP-address or host name of the outgoing smarthost: This one depends on YOUR smarthost. Fastmail uses “mail.messagingengine.com::587”.

If you are lucky, you will get a prompt for, “Domains to relay mail for:” here, if that’s the case – Enter “*” and continue, otherwise we have to do something more.

Number-of-DNS-queries minimal, No.

Split configuration into small files, No.

If you were lucky, skip to configuring passwd.client, otherwise:

:~# editor /etc/exim4/update-exim4.conf.con
Fint and edit dc_relay_domains=” and add a *, so that it reads “dc_relay_domains=’*'”.
(Don’t just copy/paste that, quotes etc.)
Save the file, and re-run config to verify, then go ahead.

:~# editor /etc/exim4/passwd.client

And input using the following variables:
<servername>:<username>:<password>

For fastmail this equalls:
mail.messagingengine.com:leetuser@fastmail.com:leethax0rpassword
Save and restart exim using:

:~# systemctl restart exim4.service

Send a test-mail using:

:~# echo “testmail!” | mailx testmail@example.com

It should arrive!

Now for the clients in your LAN, the following should be done:

:~# apt-get install exim4

:~# dpkg-reconfigure exim4-config

“Mail sent by smarthost; no local mail”

“System mail name:” Leave as-is, should contain hostname+domain.

“IP-addresses to listen on for incoming SMTP connections:” Leave to something loopback-ish. (127.0.0.1, ::1)

“Other destinations for which mail is accepted:” Leave as-is.

“Visible domain name for local users:” Leave as-is.

“IP address or host name of the outgoing smarthost:” Enter the hostname/IP of the host created during the first part.

Number-of-DNS-queries minimal, No.

Split configuration into small files, No.

And then send a test-mail using the following command:

:~# echo “Testing mail via relay at <clock>” | mailx receiver@example.com

It can also be a good idea to update the mail-alias on the client.

:~# editor /etc/aliases

Replace the entry after root with a valid (and monitored) email, for example:
root: user+fileserver@example.com

Save the file, and you’re done.