mirror of https://bitbucket.org/ausocean/av.git
Merged in treat-start (pull request #430)
Install and run treatment at startup Approved-by: Saxon Milton
This commit is contained in:
commit
e4e03b4ed1
|
@ -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", "/home/pi/audio.wav", "Path to sound file we wish to play.")
|
||||
flag.Parse()
|
||||
|
||||
// Create lumberjack logger to handle logging to file.
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module bitbucket.org/ausocean/av
|
|||
go 1.13
|
||||
|
||||
require (
|
||||
bitbucket.org/ausocean/iot v1.2.17
|
||||
bitbucket.org/ausocean/iot v1.3.0
|
||||
bitbucket.org/ausocean/utils v1.2.14
|
||||
github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7
|
||||
github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
|||
bitbucket.org/ausocean/iot v1.2.17 h1:9QDtrB0iSeOC60aSaiyfXf59S4boLaADDrpYm1Cdt4A=
|
||||
bitbucket.org/ausocean/iot v1.2.17/go.mod h1:rRcWt6SoM/jgIZpP1zrpnKb5BhxIMulAJ+q1xTvLh94=
|
||||
bitbucket.org/ausocean/iot v1.3.0 h1:s8UcAiR+nZZilo80NGyp3cqfWsFeDz+q4VdQAPmz9Cg=
|
||||
bitbucket.org/ausocean/iot v1.3.0/go.mod h1:rRcWt6SoM/jgIZpP1zrpnKb5BhxIMulAJ+q1xTvLh94=
|
||||
bitbucket.org/ausocean/utils v1.2.11 h1:zA0FOaPjN960ryp8PKCkV5y50uWBYrIxCVnXjwbvPqg=
|
||||
bitbucket.org/ausocean/utils v1.2.11/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8=
|
||||
bitbucket.org/ausocean/utils v1.2.14 h1:v5eBYavkEqKOBCppR6P451eT9UT/CQReMsOZZBUPX3Q=
|
||||
|
|
|
@ -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 treatment_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
|
||||
|
|
|
@ -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
|
|
@ -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/treatment
|
||||
|
||||
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 treatment 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 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
|
Loading…
Reference in New Issue