mirror of https://bitbucket.org/ausocean/av.git
Merged in looper-systemd (pull request #435)
cmd/looper: added build & run utilities including .service file for robust execution Approved-by: Trek Hopton
This commit is contained in:
commit
93d5eb1638
|
@ -1,52 +1,84 @@
|
||||||
# Install rc.local file
|
# Install files and directories required by NetSender clients (such as gpio-netsender, rv, etc.)
|
||||||
|
# and create a dhcpcd.enter-hook for setting the MAC address.
|
||||||
|
# MA and DK can be optionally passed to Make, e.g, for a hard (first-time) installation:
|
||||||
|
# sudo MA=mac DK=dk install_hard
|
||||||
|
# NB: The default (soft) install does not override conf files.
|
||||||
USER := $(shell whoami)
|
USER := $(shell whoami)
|
||||||
PATH := /usr/local/go/bin:$(PATH)
|
PATH := /usr/local/go/bin:$(PATH)
|
||||||
|
ifeq ($(MA),)
|
||||||
|
MA := "00:E0:4C:00:00:01"
|
||||||
|
endif
|
||||||
|
ifeq ($(DK),)
|
||||||
|
DK := 0
|
||||||
|
endif
|
||||||
|
|
||||||
.SILENT:copy_files
|
.SILENT:make_dirs
|
||||||
|
.SILENT:soft_copy_files
|
||||||
.SILENT:hard_copy_files
|
.SILENT:hard_copy_files
|
||||||
.SILENT:build
|
.SILENT:set_mac
|
||||||
|
.SILENT:syncreboot
|
||||||
.SILENT:clean
|
.SILENT:clean
|
||||||
|
|
||||||
install: as_root copy_files build
|
install: as_root make_dirs soft_copy_files
|
||||||
@echo "Install complete"
|
@echo "Install complete"
|
||||||
|
|
||||||
install_hard: as_root hard_copy_files build
|
install_hard: as_root make_dirs hard_copy_files set_mac syncreboot
|
||||||
@echo "Install complete"
|
@echo "Hard install complete"
|
||||||
|
|
||||||
as_root:
|
as_root:
|
||||||
ifneq ($(USER),root)
|
ifneq ($(USER),root)
|
||||||
$(error Must run as superuser!)
|
$(error Must run as superuser!)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
copy_files:
|
make_dirs:
|
||||||
if [ -f /etc/rc.local ] ; then \
|
if [ ! -d /var/netsender ] ; then \
|
||||||
echo "/etc/rc.local left unmodified" ; \
|
mkdir /var/netsender; \
|
||||||
else \
|
chmod guo+rwx /var/netsender; \
|
||||||
cp rc.local /etc; \
|
|
||||||
fi
|
fi
|
||||||
|
if [ ! -d /var/log/netsender ] ; then \
|
||||||
|
mkdir /var/log/netsender; \
|
||||||
|
chmod guo+rwx /var/log/netsender; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
soft_copy_files:
|
||||||
|
if [ -f /etc/systemd/system/looper.service ] ; then \
|
||||||
|
echo "/etc/systemd/system/looper.service left unmodified" ; \
|
||||||
|
else \
|
||||||
|
cp looper.service /etc/systemd/system; \
|
||||||
|
fi
|
||||||
|
systemctl enable looper.service
|
||||||
|
chmod +x pi_run.sh
|
||||||
if [ -f /etc/netsender.conf ] ; then \
|
if [ -f /etc/netsender.conf ] ; then \
|
||||||
echo "/etc/netsender.conf left unmodified" ; \
|
echo "/etc/netsender.conf left unmodified" ; \
|
||||||
else \
|
else \
|
||||||
cp netsender.conf /etc; \
|
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf; \
|
||||||
|
chown pi /etc/netsender.conf; \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
hard_copy_files:
|
hard_copy_files:
|
||||||
if [ -f /etc/rc.local ] ; then \
|
if [ -f /etc/systemd/system/looper.service ] ; then \
|
||||||
echo "Backed up rc.local to /etc/rc.local.bak" ; \
|
echo "/etc/systemd/system/looper.service overwritten" ; \
|
||||||
cp /etc/rc.local /etc/rc.local.bak ; \
|
|
||||||
fi
|
fi
|
||||||
cp -f rc.local /etc
|
cp -f looper.service /etc/systemd/system
|
||||||
|
systemctl enable looper.service
|
||||||
|
chmod +x pi_run.sh
|
||||||
if [ -f /etc/netsender.conf ] ; then \
|
if [ -f /etc/netsender.conf ] ; then \
|
||||||
echo "Backed up netsender.conf to /etc/netsender.conf.bak" ; \
|
echo "Backed up netsender.conf to /etc/netsender.conf.bak"; \
|
||||||
cp /etc/netsender.conf /etc/netsender.conf.bak ; \
|
cp /etc/netsender.conf /etc/netsender.conf.bak ; \
|
||||||
fi
|
fi
|
||||||
cp -f netsender.conf /etc
|
printf "ma $(MA)\ndk $(DK)\n" > /etc/netsender.conf
|
||||||
|
chown pi /etc/netsender.conf
|
||||||
|
|
||||||
build:
|
set_mac:
|
||||||
if grep -q 'Raspberry Pi 3' '/proc/device-tree/model'; then \
|
printf "ip link set eth0 address $(MA)\n" > /etc/dhcpcd.enter-hook
|
||||||
echo "Compiling for Raspberry pi 3";\
|
chmod guo+x /etc/dhcpcd.enter-hook
|
||||||
go build -tags pi3;\
|
|
||||||
else \
|
syncreboot:
|
||||||
echo "Compiling for Raspberry pi 0";\
|
cd ../../utils/cmd/syncreboot; make; make install
|
||||||
go build -tags pi0;\
|
|
||||||
fi
|
clean: as_root
|
||||||
|
rm -rf /var/netsender
|
||||||
|
rm -rf /var/log/netsender
|
||||||
|
rm -rf /etc/systemd/system/looper.service
|
||||||
|
rm -rf /etc/netsender.conf
|
||||||
|
@echo "Clean complete"
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
[Unit]
|
||||||
|
Description=looper is a utility to robustly loop a sound file from a raspberry pi.
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/looper/pi_run.sh
|
||||||
|
Restart=on-failure
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
# This script launches looper on a pi, intended to run at boot time.
|
||||||
|
|
||||||
|
LOOPER_PATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/looper
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# Start gpio stuff.
|
||||||
|
sudo systemctl start pigpiod
|
||||||
|
|
||||||
|
|
||||||
|
# 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 looper as pi user
|
||||||
|
HOME=/home/pi
|
||||||
|
GOPATH=$HOME/go
|
||||||
|
LOOPER_PATH=$GOPATH/src/bitbucket.org/ausocean/av/cmd/looper
|
||||||
|
PATH=$PATH:/usr/local/go/bin:$LOOPER_PATH
|
||||||
|
cd $LOOPER_PATH
|
||||||
|
sudo HOME=$HOME GOPATH=$GOPATH PATH=$PATH ./looper
|
||||||
|
if [ $? -eq 0 ]
|
||||||
|
then
|
||||||
|
echo "Successfully exited looper"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "looper exited with code: $?" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
Reference in New Issue