From 3c2fefa8cbc15876e58f95d78e9e65d4fb597995 Mon Sep 17 00:00:00 2001 From: Trek H Date: Wed, 13 May 2020 01:34:57 +0930 Subject: [PATCH 1/4] init: make a systemd unit service to launch rv updated makefile renamed script from rc.local to pi_run.sh since we wont use rc.local anymore --- init/Makefile | 19 +++++++++++-------- init/{rc.local => pi_run.sh} | 3 +-- init/rv.service | 10 ++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) rename init/{rc.local => pi_run.sh} (93%) create mode 100644 init/rv.service diff --git a/init/Makefile b/init/Makefile index 821d4ddf..ff78e4c9 100644 --- a/init/Makefile +++ b/init/Makefile @@ -41,11 +41,13 @@ make_dirs: fi soft_copy_files: - if [ -f /etc/rc.local ] ; then \ - echo "/etc/rc.local left unmodified" ; \ + if [ -f /etc/systemd/system/rv.service ] ; then \ + echo "/etc/systemd/system/rv.service left unmodified" ; \ else \ - cp rc.local /etc; \ + cp rv.service /etc/systemd/system; \ fi + systemctl enable rv.service + chmod +x pi_run.sh if [ -f /etc/netsender.conf ] ; then \ echo "/etc/netsender.conf left unmodified" ; \ else \ @@ -54,11 +56,12 @@ soft_copy_files: fi hard_copy_files: - if [ -f /etc/rc.local ] ; then \ - echo "Backed up rc.local to /etc/rc.local.bak" ; \ - cp /etc/rc.local /etc/rc.local.bak ; \ + if [ -f /etc/systemd/system/rv.service ] ; then \ + echo "/etc/systemd/system/rv.service overwritten" ; \ fi - cp -f rc.local /etc + cp -f cp rv.service /etc/systemd/system + systemctl enable rv.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 ; \ @@ -76,6 +79,6 @@ syncreboot: clean: as_root rm -rf /var/netsender rm -rf /var/log/netsender - rm -rf /etc/rc.local + rm -rf /etc/systemd/system/rv.service rm -rf /etc/netsender.conf @echo "Clean complete" diff --git a/init/rc.local b/init/pi_run.sh similarity index 93% rename from init/rc.local rename to init/pi_run.sh index 11aa983e..5c5198bc 100644 --- a/init/rc.local +++ b/init/pi_run.sh @@ -1,6 +1,5 @@ #!/bin/sh -e -# /etc/rc.local -# This script launches rv at boot time +# This script launches rv on a pi, intended to run at boot time. RVPATH=/home/pi/go/src/bitbucket.org/ausocean/av/cmd/rv diff --git a/init/rv.service b/init/rv.service new file mode 100644 index 00000000..818bcc86 --- /dev/null +++ b/init/rv.service @@ -0,0 +1,10 @@ +[Unit] +Description=Netsender Client for Media Collection and Forwarding + +[Service] +Type=simple +ExecStart=/home/pi/go/src/bitbucket.org/ausocean/av/init/pi_run.sh +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file From d859dcbf4e0d0bd871468c4be76b3b2aab23ef5c Mon Sep 17 00:00:00 2001 From: Trek H Date: Sat, 16 May 2020 23:48:11 +0930 Subject: [PATCH 2/4] init: unit service stays running --- init/pi_run.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/init/pi_run.sh b/init/pi_run.sh index 5c5198bc..fa04c1b9 100644 --- a/init/pi_run.sh +++ b/init/pi_run.sh @@ -33,6 +33,14 @@ HOME=/home/pi GOPATH=$HOME/go RVPATH=$GOPATH/src/bitbucket.org/ausocean/av/cmd/rv PATH=$PATH:/usr/local/go/bin:$RVPATH +echo $RVPATH cd $RVPATH -sudo -u pi HOME=$HOME GOPATH=$GOPATH PATH=$PATH ./rv & -exit 0 +sudo -u pi HOME=$HOME GOPATH=$GOPATH PATH=$PATH ./rv +if [ $? -eq 0 ] +then + echo "Successfully exited rv" + exit 0 +else + echo "rv exited with code: $?" >&2 + exit 1 +fi From c81fb90587d8932fcb27fed2311c3d7afa6bca8a Mon Sep 17 00:00:00 2001 From: Trek H Date: Sun, 17 May 2020 00:03:34 +0930 Subject: [PATCH 3/4] init: fix cp line in make --- init/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/Makefile b/init/Makefile index ff78e4c9..3b093cd1 100644 --- a/init/Makefile +++ b/init/Makefile @@ -59,7 +59,7 @@ hard_copy_files: if [ -f /etc/systemd/system/rv.service ] ; then \ echo "/etc/systemd/system/rv.service overwritten" ; \ fi - cp -f cp rv.service /etc/systemd/system + cp -f rv.service /etc/systemd/system systemctl enable rv.service chmod +x pi_run.sh if [ -f /etc/netsender.conf ] ; then \ From 8f6825c388a478b4b3d8105588626d256f32a8ed Mon Sep 17 00:00:00 2001 From: Trek Hopton Date: Tue, 19 May 2020 04:46:00 +0000 Subject: [PATCH 4/4] init: removed debug echo --- init/pi_run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/init/pi_run.sh b/init/pi_run.sh index fa04c1b9..22e69769 100644 --- a/init/pi_run.sh +++ b/init/pi_run.sh @@ -33,7 +33,6 @@ HOME=/home/pi GOPATH=$HOME/go RVPATH=$GOPATH/src/bitbucket.org/ausocean/av/cmd/rv PATH=$PATH:/usr/local/go/bin:$RVPATH -echo $RVPATH cd $RVPATH sudo -u pi HOME=$HOME GOPATH=$GOPATH PATH=$PATH ./rv if [ $? -eq 0 ]