Installation on FreeNAS 11.2
FreeNAS is a free and open-source network-attached storage (NAS) software based on FreeBSD and the OpenZFS file system. It is licensed under the terms of the BSD License and runs on commodity x86-64 hardware.
This has been tested on FreeNAS 11.2 and should also work on FreeBSD 11.x as well. These instructions assume you already have a running and accessible jail. For more information on creating a jail read the official FreeNAS User Guide regarding Jails. Once you have the jail available, follow the steps below. Directories used follow standard BSD conventions but can be adjusted as you wish.
Enter the Open Peer Power jail. If you don’t know which name you have given the jail, you can use the iocage list
command to check.
# If the jail is called 'OpenPeerPower'
iocage exec OpenPeerPower
Install the suggested packages:
pkg update
pkg upgrade
pkg install -y autoconf bash ca_root_nss gmake pkgconf python37 py37-sqlite3
Create the user and group that Open Peer Power will run as. The user/group ID of 8123
can be replaced if this is already in use in your environment.
pw groupadd -n openpeerpower -g 8123
echo 'openpeerpower:8123:8123::::::/usr/local/bin/bash:' | adduser -f -
Create the installation directory:
mkdir -p /usr/local/share/openpeerpower
chown -R openpeerpower:openpeerpower /usr/local/share/openpeerpower
Create the virtualenv and install Open Peer Power itself:
su openpeerpower
cd /usr/local/share/openpeerpower
python3.7 -m venv .
source ./bin/activate
pip3 install --upgrade pip
pip3 install openpeerpower
While still in the venv
, start Open Peer Power to populate the configuration directory.
opp --open-ui
Wait until you see:
(MainThread) [openpeerpower.core] Starting Open Peer Power
Then escape and exit the venv
.
deactivate
exit
Create the directory and the rc.d
script for the system-level service that enables Open Peer Power to start when the jail starts.
mkdir /usr/local/etc/rc.d/
Then create a file at /usr/local/etc/rc.d/openpeerpower
and insert the content below:
vi /usr/local/etc/rc.d/openpeerpower
#!/bin/sh
#
# Based upon work by tprelog at https://github.com/tprelog/iocage-openpeerpower/blob/11.3-RELEASE/overlay/usr/local/etc/rc.d/openpeerpower
#
# PROVIDE: openpeerpower
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# openpeerpower_user: The user account used to run the openpeerpower daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run as root.
# Default: openpeerpower
# openpeerpower_group: The group account used to run the openpeerpower daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run with group wheel.
# Default: openpeerpower
#
# openpeerpower_venv: Directory where openpeerpower virtualenv is installed.
# Default: "/usr/local/share/openpeerpower"
# Change: `sysrc openpeerpower_venv="/srv/openpeerpower"`
# UnChange: `sysrc -x openpeerpower_venv`
#
# openpeerpower_config_dir: Directory where openpeerpower config is located.
# Default: "/home/openpeerpower/.openpeerpower"
# Change: `sysrc openpeerpower_config_dir="/home/opp/openpeerpower"`
# UnChange: `sysrc -x openpeerpower_config_dir`
# -------------------------------------------------------
# Copy this file to '/usr/local/etc/rc.d/openpeerpower'
# `chmod +x /usr/local/etc/rc.d/openpeerpower`
# `sysrc openpeerpower_enable=yes`
# `service openpeerpower start`
# -------------------------------------------------------
. /etc/rc.subr
name=openpeerpower
rcvar=${name}_enable
pidfile_child="/var/run/${name}.pid"
pidfile="/var/run/${name}_daemon.pid"
logfile="/var/log/${name}.log"
load_rc_config ${name}
: ${openpeerpower_enable:="NO"}
: ${openpeerpower_user:="openpeerpower"}
: ${openpeerpower_group:="openpeerpower"}
: ${openpeerpower_config_dir:="/home/openpeerpower/.openpeerpower"}
: ${openpeerpower_venv:="/usr/local/share/openpeerpower"}
command="/usr/sbin/daemon"
extra_commands="check_config restart test upgrade"
start_precmd=${name}_precmd
openpeerpower_precmd() {
rc_flags="-f -o ${logfile} -P ${pidfile} -p ${pidfile_child} ${openpeerpower_venv}/bin/opp --config ${openpeerpower_config_dir} ${rc_flags}"
[ ! -e "${pidfile_child}" ] && install -g ${openpeerpower_group} -o ${openpeerpower_user} -- /dev/null "${pidfile_child}"
[ ! -e "${pidfile}" ] && install -g ${openpeerpower_group} -o ${openpeerpower_user} -- /dev/null "${pidfile}"
[ -e "${logfile}" ] && rm -f -- "${logfile}"
install -g ${openpeerpower_group} -o ${openpeerpower_user} -- /dev/null "${logfile}"
if [ ! -d "${openpeerpower_config_dir}" ]; then
install -d -g ${openpeerpower_group} -o ${openpeerpower_user} -m 775 -- "${openpeerpower_config_dir}"
fi
}
stop_postcmd=${name}_postcmd
openpeerpower_postcmd() {
rm -f -- "${pidfile}"
rm -f -- "${pidfile_child}"
}
upgrade_cmd="${name}_upgrade"
openpeerpower_upgrade() {
service ${name} stop
su ${openpeerpower_user} -c '
source ${@}/bin/activate || exit 1
pip3 install --upgrade openpeerpower
deactivate
' _ ${openpeerpower_venv} || exit 1
[ $? == 0 ] && openpeerpower_check_config && service ${name} start
}
check_config_cmd="${name}_check_config"
openpeerpower_check_config() {
[ ! -e "${openpeerpower_config_dir}/configuration.yaml" ] && return 0
echo "Performing check on Open Peer Power configuration:"
#eval "${openpeerpower_venv}/bin/opp --config ${openpeerpower_config_dir} --script check_config"
su ${openpeerpower_user} -c '
source ${1}/bin/activate || exit 2
opp --config ${2} --script check_config || exit 3
deactivate
' _ ${openpeerpower_venv} ${openpeerpower_config_dir}
}
restart_cmd="${name}_restart"
openpeerpower_restart() {
openpeerpower_check_config || exit 1
echo "Restarting Open Peer Power"
service ${name} stop
service ${name} start
}
test_cmd="${name}_test"
openpeerpower_test() {
echo -e "\nTesting virtualenv...\n"
[ ! -d "${openpeerpower_venv}" ] && echo -e " NO DIRECTORY: ${openpeerpower_venv}\n" && exit
[ ! -f "${openpeerpower_venv}/bin/activate" ] && echo -e " NO FILE: ${openpeerpower_venv}/bin/activate\n" && exit
## switch users / activate virtualenv / get version
su "${openpeerpower_user}" -c '
source ${1}/bin/activate || exit 2
echo " $(python --version)" || exit 3
echo " Open Peer Power $(pip3 show openpeerpower | grep Version | cut -d" " -f2)" || exit 4
deactivate
' _ ${openpeerpower_venv}
[ $? != 0 ] && echo "exit $?"
}
load_rc_config ${name}
run_rc_command "$1"
Make the rc.d
script executable:
chmod +x /usr/local/etc/rc.d/openpeerpower
Configure the service to start on boot and start the Open Peer Power service:
sysrc openpeerpower_enable="YES"
service openpeerpower start
You can also restart the jail to ensure that Open Peer Power starts on boot.
Adding support for Z-Wave stick
The following two packages need to be installed in the jail
pkg install gmake
pkg install libudev-devd
Then you can install the Z-Wave package
su openpeerpower
cd /usr/local/share/openpeerpower
source ./bin/activate.csh
pip3 install openpeerpower-pyozw==0.1.7
deactivate
exit
Stop the Open Peer Power Jail
sudo iocage stop OpenPeerPower
Edit the devfs rules on the FreenNAS Host
vi /etc/devfs.rules
Add the following lines
[devfsrules_jail_allow_usb=7]
add path 'cu\*' mode 0660 group 8123 unhide
Reload devfs
sudo service devfs restart
Edit the ruleset used by the jail in the FreeNAS GUI by going to Jails -> opp
-> Edit -> Jail Properties -> devfs_ruleset
Set it to 7
Start the Open Peer Power jail
sudo iocage start OpenPeerPower
Connect to the Open Peer Power jail and verify that you see the modem devices
sudo iocage console OpenPeerPower
ls /dev/cu*
This should output the following
/dev/cuau0 /dev/cuaU0
Add the Z-Wave configuration to your configuration.yaml
and restart Open Peer Power
vi /home/openpeerpower/.openpeerpower/configuration.yaml
zwave:
usb_path: /dev/cuaU0
polling_interval: 10000
service openpeerpower restart
Updating
Before updating, read the changelog to see what has changed and how it affects your Open Peer Power instance. Enter the jail using iocage exec <jailname>
. Stop the Open Peer Power service:
service openpeerpower stop
Then, enter the venv
:
su openpeerpower
cd /usr/local/share/openpeerpower
source ./bin/activate
Upgrade Open Peer Power:
pip3 install openpeerpower --upgrade
Log out of the openpeerpower
user and start Open Peer Power:
exit
service openpeerpower start