diff --git a/cmd/treatment/main.go b/cmd/treatment/main.go index d716c7d8..793aed5b 100644 --- a/cmd/treatment/main.go +++ b/cmd/treatment/main.go @@ -89,7 +89,7 @@ func main() { mts.Meta = meta.NewWith([][2]string{{metaPreambleKey, metaPreambleData}}) // Set up the player command with audio file path. - filePtr := flag.String("path", "", "Path to sound file we wish to play.") + filePtr := flag.String("path", "~/audio.wav", "Path to sound file we wish to play.") flag.Parse() // Create lumberjack logger to handle logging to file. diff --git a/init/Makefile b/init/Makefile index 3b093cd1..68170df2 100644 --- a/init/Makefile +++ b/init/Makefile @@ -25,6 +25,9 @@ install: as_root make_dirs soft_copy_files install_hard: as_root make_dirs hard_copy_files set_mac syncreboot @echo "Hard install complete" +install_hard_treat: as_root make_dirs hard_copy_files_treat set_mac syncreboot + @echo "Hard install complete" + as_root: ifneq ($(USER),root) $(error Must run as superuser!) @@ -69,6 +72,20 @@ hard_copy_files: printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf chown pi /etc/netsender.conf +hard_copy_files_treat: + if [ -f /etc/systemd/system/treatment.service ] ; then \ + echo "/etc/systemd/system/treatment.service overwritten" ; \ + fi + cp -f treatment.service /etc/systemd/system + systemctl enable treatment.service + chmod +x pi_run.sh + if [ -f /etc/netsender.conf ] ; then \ + echo "Backed up netsender.conf to /etc/netsender.conf.bak"; \ + cp /etc/netsender.conf /etc/netsender.conf.bak ; \ + fi + printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf + chown pi /etc/netsender.conf + set_mac: printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook chmod guo+x /etc/dhcpcd.enter-hook diff --git a/init/treatment.service b/init/treatment.service new file mode 100644 index 00000000..6e7f376d --- /dev/null +++ b/init/treatment.service @@ -0,0 +1,10 @@ +[Unit] +Description=Netsender Client for Playing and Recording Sound + +[Service] +Type=simple +ExecStart=/home/pi/go/src/bitbucket.org/ausocean/av/init/treatment_run.sh +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/init/treatment_run.sh b/init/treatment_run.sh new file mode 100644 index 00000000..15b752ad --- /dev/null +++ b/init/treatment_run.sh @@ -0,0 +1,45 @@ +#!/bin/sh -e +# This script launches treatment on a pi, intended to run at boot time. + +TREATPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/rv + +echo Set kernel parameters: +# kernel settings to improve performance on Raspberry Pi +# tell Linux to fork optimistically +sudo sysctl -w vm.overcommit_memory=1 +# minimize swapping, without disabling it completely +sudo sysctl -w vm.swappiness=1 + +# the following required directories _should_ already exist +if [ ! -d /var/log/netsender ]; then + sudo mkdir /var/log/netsender + chmod guo+rwx /var/log/netsender +fi +if [ ! -d /var/netsender ]; then + sudo mkdir /var/netsender + chmod guo+rwx /var/netsender +fi + +# show IP addresses +echo Our IP addresses: +sudo ip addr show | grep inet + +# capture stdout and stderr to a secondary log file (just in case) +exec 2> /var/log/netsender/stream.log +exec 1>&2 + +# set env, working dir and run rv as pi user +HOME=/home/pi +GOPATH=$HOME/go +TREATPATH=$GOPATH/src/bitbucket.org/ausocean/av/cmd/treatment +PATH=$PATH:/usr/local/go/bin:$TREATPATH +cd $TREATPATH +sudo -u pi HOME=$HOME GOPATH=$GOPATH PATH=$PATH ./treatment +if [ $? -eq 0 ] +then + echo "Successfully exited treatment" + exit 0 +else + echo "treatment exited with code: $?" >&2 + exit 1 +fi