Skip to main content

NB: systemd-nspawn, MMDVMHost and Dashboard on ArchLinux

Some side notes for MMDVMHost on Archlinux.  

Preparation and installation:

LC_ALL=C
# I prefer ZFS
# add anything u need like recordsize, compression, noatime, etc
radioid=2500546 # got one/yours from radioid.net, this is public information
vm_name=vms-mmdvm-dmr-hotspot-${radioid}01 # put last two digits by your own
vm_dataset=storarray/local/vms/container/${vm_name}
sudo zfs create $vm_dataset
vm_mountpoint=$(zfs list -H -o mountpoint $vm_dataset)
LC_ALL=C sudo pacstrap -GMc \
    $vm_mountpoint \
    base php7 php7-cgi php7-sqlite lighttpd
# make few changes in useradd - remove --user-group, add --gid mmdvm
LC_ALL=C trizen  -S mmdvmhost-git --root="$vm_mountpoint"
sudo ln -fs $vm_mountpoint /var/lib/machines/

As desired - no root nor user access externally, just nothing to do inside container.

On host side:

# sudo systemctl edit systemd-nspawn@${vm_name}.service
[Service]
DeviceAllow=char-ttyACM rw

ExecStart=
ExecStart=systemd-nspawn --quiet --keep-unit --boot \
        --link-journal=try-guest --settings=override --machine=%i \
        --network-bridge=home-br0 \
        --bind=/dev/ttyACM0

On VM side:

# ${vm_mountpoint}/etc/systemd/network/host.network 
[Match]
Name=host*

[Network]
DHCP=ipv4
# cat ${vm_mountpoint}/etc/systemd/system/mmdvmhost.service
[Unit]
Description=MMDVMHost Radio Service
After=syslog.target network.target

[Service]
User=mmdvm
Type=simple
ExecStart=/usr/bin/MMDVMHost
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

Download MMDVMHost Dashboard, place in container directory ${vm_mountpoint}/srv/http.

Enable few extension in ${vm_mountpoint}/etc/php7/php.ini:
extension=gettext
extension=sqlite3

Add php support in lighttpd:

sudo mkdir ${vm_mountpoint}/etc/lighttpd/conf.d/
cat << EOF | sudo tee ${vm_mountpoint}/etc/lighttpd/conf.d/fastcgi.conf
server.modules += ( "mod_fastcgi" )
index-file.names += ("index.php")
fastcgi.server = ( ".php" =>
  ((
    "socket" => "/tmp/php.socket",
    "bin-path" => "/usr/bin/php-cgi7",
    "bin-environment" => (
      "PHP_FCGI_CHILDREN" => "16",
      "PHP_FCGI_MAX_REQUESTS" => "10000"
    ),
    "min-procs" => 1,
    "max-procs" => 1,
    "idle-timeout" => 20
  ))
)
EOF
echo 'include "conf.d/fastcgi.conf"' | sudo tee --append ${vm_mountpoint}/etc/lighttpd/lighttpd.conf

Monitor MMDVMHost activity in VM:

sudo journalctl -ef --machine ${vm_name} -u mmdvmhost
sudo machinectl shell vms-mmdvm-dmr-hotspot-250054601
sudo machinectl shell mmdvm@vms-mmdvm-dmr-hotspot-250054601 # no access

Check your MMDMV.ini

cf=${vm_mountpoint}/etc/MMDVM.ini
grep ^\\[ $cf | while read -r line ;
do  
    section_name="\[${line:1:${#line}-2}\]"
    IFS=$'\n' section=( $(cat $cf | grep -v ^# | sed -n '0,/'"$section_name"'/d;/\[/,$d;/^$/d;p') )
    grep -qoiv "enable=" <<< "${section[@]}" && ( echo $line ; printf "%s\n" "${section[@]}" )
    grep -qoi "enable=1" <<< "${section[@]}" && ( echo $line ; printf "%s\n" "${section[@]}" )
    echo
done | uniq | \
    sed -r 's/^Password=[^ ]*/Password=your password here/g'| \
    sed -r 's/^Id=[^ ]*/Id=your id here/g'