From c1ce8471b1af8d93f9270f9a468b59aea3926c7a Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:25:26 +0100 Subject: [PATCH 01/11] Create mmdvmhost.service MMDVMHost Unit File This is what systemd uses to start / stop the service. All of the heavy lifting is done in /usr/local/sbin/mmdvmhost_service --- linux/systemd/mmdvmhost.service | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 linux/systemd/mmdvmhost.service diff --git a/linux/systemd/mmdvmhost.service b/linux/systemd/mmdvmhost.service new file mode 100644 index 0000000..a4de9f3 --- /dev/null +++ b/linux/systemd/mmdvmhost.service @@ -0,0 +1,12 @@ +[Unit] +Description=MMDVMHost Radio Servce +After=syslog.target network.target + +[Service] +Type=forking +ExecStart=/usr/local/sbin/mmdvmhost_service start +ExecStop=/usr/local/sbin/mmdvmhost_service stop +ExecReload=/usr/local/sbin/mmdvmhost_service restart + +[Install] +WantedBy=multi-user.target From 3ce060e7bc022aa8a6d288d4dfe6465ece0c25ca Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:26:20 +0100 Subject: [PATCH 02/11] Create mmdvmhost.timer This is used to delay the boot time start of MMDVMHost This enables the network / DNS / everything else important to start up before MMVMHost starts --- linux/systemd/mmdvmhost.timer | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 linux/systemd/mmdvmhost.timer diff --git a/linux/systemd/mmdvmhost.timer b/linux/systemd/mmdvmhost.timer new file mode 100644 index 0000000..35781a8 --- /dev/null +++ b/linux/systemd/mmdvmhost.timer @@ -0,0 +1,5 @@ +[Timer] +OnStartupSec=45 + +[Install] +WantedBy=multi-user.target From bba48fcbc6a17f9742155840f7a87de9b7243a12 Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:30:23 +0100 Subject: [PATCH 03/11] Create README.md Information / How-To This should work on all systemd Linux's - tested / confirmed working on Raspbian Jessie-Lite --- linux/systemd/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 linux/systemd/README.md diff --git a/linux/systemd/README.md b/linux/systemd/README.md new file mode 100644 index 0000000..8edcbde --- /dev/null +++ b/linux/systemd/README.md @@ -0,0 +1,10 @@ + + + + +Copy mmdvmhost.service to /lib/systemd/system +Copy mmdvmhost.timer to /lib/systemd/system +Edit the timeout in mmdvmhost.timer to suit - 45 secs is a reasonable starting point. +Reload systemctl with: "systemctl daemon-reload" +Add the timer serice to the boot with: "systemctl enable mmdvmhost.timer" +**NOTE - There is no need / desire to enable mmdvmhost.service! From 969522c997889b25b8f729fd1b049a29d2a1e8ad Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:32:24 +0100 Subject: [PATCH 04/11] Create mmdvmhost_service This is a service handler for MMDVMHost. This does all the heavy lifting for service management. --- linux/systemd/mmdvmhost_service | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 linux/systemd/mmdvmhost_service diff --git a/linux/systemd/mmdvmhost_service b/linux/systemd/mmdvmhost_service new file mode 100644 index 0000000..6e9ac13 --- /dev/null +++ b/linux/systemd/mmdvmhost_service @@ -0,0 +1,85 @@ +#!/bin/bash +######################################################### +# # +# MMDVMHost Service Handler # +# # +# Written for Pi-Star (http://www.mw0mwz.co.uk/pi-star) # +# By Andy Taylor (MW0MWZ) # +# # +# Version 1.1 # +# # +######################################################### + +# Service Config +DAEMON=MMDVMHost +DAEMON_PATH=/usr/local/bin/ +CONFIG=/etc/mmdvmhost +DAEMON_OPTS=$CONFIG +PGREP=/usr/bin/pgrep +KILL=/bin/kill +SLEEP=/bin/sleep +USER=mmdvm +GROUP=mmdvm +LOGDIR=/var/log/pi-star + +# Pre-flight checks... +test -x ${DAEMON_PATH}${DAEMON} || exit 1 +test -r $CONFIG || exit 1 + +# Verify the logging directory exists, if not create it and setup the ownership / permissions +if [ ! -d $LOGDIR ]; then + mkdir -p $LOGDIR + chown root:$GROUP $LOGDIR + chmod 775 $LOGDIR +fi + +case "$1" in + start) + if [ `${PGREP} ${DAEMON}` ]; then + echo -e "$DAEMON is already running as PID "`$PGREP $DAEMON` + exit 1; + else + runuser -l $USER -c "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}" + echo -e "$DAEMON started as PID "`$PGREP $DAEMON` + exit 0; + fi + ;; + stop) + if [ `${PGREP} ${DAEMON}` ]; then + echo -e "Killing $DAEMON PID "`$PGREP $DAEMON` + $KILL `${PGREP} ${DAEMON}` + exit 0; + else + echo -e "$DAEMON is not running" + exit 1; + fi + ;; + + restart) + if [ `$PGREP $DAEMON` ]; then + echo -e "Killing $DAEMON PID "`$PGREP $DAEMON` + $KILL `${PGREP} ${DAEMON}` + $SLEEP 3 + runuser -l $USER -c "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}" + echo -e "$DAEMON re-started as PID "`${PGREP} ${DAEMON}` + exit 0; + else + echo -e "$DAEMON is not running" + ${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS} + echo -e "$DAEMON started as PID "`${PGREP} ${DAEMON}` + exit 0; + fi + ;; + + status) + if [ `${PGREP} ${DAEMON}` ]; then + echo -e "$DAEMON is running as PID "`${PGREP} ${DAEMON}` + else + echo -e "$DAEMON is not running" + fi + ;; + + *) + echo $"Usage: $0 {start|stop|restart|status}" + exit 1 +esac From bbf82121d1cb5cc535a64e30aae71d8dd9d1cd14 Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:37:30 +0100 Subject: [PATCH 05/11] Update README.md --- linux/systemd/README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/linux/systemd/README.md b/linux/systemd/README.md index 8edcbde..83de243 100644 --- a/linux/systemd/README.md +++ b/linux/systemd/README.md @@ -1,10 +1,18 @@ +MMDVMHost Systemd setup +======================= +Install Instructions +-------------------- + 1. Copy mmdvmhost_service to /usr/local/sbin + 2. Change the permisions of /usr/local/sbin/mmdvmhost_service to 500 (root executable) + 3. Change the variables in /usr/local/sbin/mmdvmhost_service to match your setup + (MMDVMHost.ini location, log location, user and daemon location) + 4. Copy mmdvmhost.service to /lib/systemd/system + 5. Copy mmdvmhost.timer to /lib/systemd/system + 6. Edit the timeout in mmdvmhost.timer to suit - 45 secs is a reasonable starting point. + 7. Reload systemctl with: "systemctl daemon-reload" + 8. Add the timer serice to the boot with: "systemctl enable mmdvmhost.timer" + **NOTE - There is no need / desire to enable mmdvmhost.service! -Copy mmdvmhost.service to /lib/systemd/system -Copy mmdvmhost.timer to /lib/systemd/system -Edit the timeout in mmdvmhost.timer to suit - 45 secs is a reasonable starting point. -Reload systemctl with: "systemctl daemon-reload" -Add the timer serice to the boot with: "systemctl enable mmdvmhost.timer" -**NOTE - There is no need / desire to enable mmdvmhost.service! From de3bab33c03916ae246abdf8645ce20db6d9a2a7 Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:38:36 +0100 Subject: [PATCH 06/11] Update README.md --- linux/systemd/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/systemd/README.md b/linux/systemd/README.md index 83de243..a38a445 100644 --- a/linux/systemd/README.md +++ b/linux/systemd/README.md @@ -7,12 +7,12 @@ Install Instructions 1. Copy mmdvmhost_service to /usr/local/sbin 2. Change the permisions of /usr/local/sbin/mmdvmhost_service to 500 (root executable) - 3. Change the variables in /usr/local/sbin/mmdvmhost_service to match your setup + 3. Change the variables in /usr/local/sbin/mmdvmhost_service to match your setup (MMDVMHost.ini location, log location, user and daemon location) 4. Copy mmdvmhost.service to /lib/systemd/system 5. Copy mmdvmhost.timer to /lib/systemd/system 6. Edit the timeout in mmdvmhost.timer to suit - 45 secs is a reasonable starting point. 7. Reload systemctl with: "systemctl daemon-reload" - 8. Add the timer serice to the boot with: "systemctl enable mmdvmhost.timer" + 8. Add the timer serice to the boot with: "systemctl enable mmdvmhost.timer" **NOTE - There is no need / desire to enable mmdvmhost.service! From ee50dcb060b277a461851f849a8ebc143faae823 Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:42:03 +0100 Subject: [PATCH 07/11] Update README.md Instructions etc --- linux/systemd/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/linux/systemd/README.md b/linux/systemd/README.md index a38a445..85730ee 100644 --- a/linux/systemd/README.md +++ b/linux/systemd/README.md @@ -1,6 +1,19 @@ MMDVMHost Systemd setup ======================= +Preface +------- + +Since moving to Systemd many admins are struggling with the differences, in an effort to take the work +out of installing MMDVMHost on your linux host, I have written a service handler and the related systemd +unit files. + +I hope these help you get going quickly. +Written on / tested on / confirmed working on Raspbian Jessie-lite but should work just fine on any +system using systemd. + +Enjoy, 73 de MW0MWZ + Install Instructions -------------------- From 4d038b0ae1c4aac05d108ab14ea138ead8d66eb4 Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 09:57:04 +0100 Subject: [PATCH 08/11] Create README.md --- linux/init/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 linux/init/README.md diff --git a/linux/init/README.md b/linux/init/README.md new file mode 100644 index 0000000..10b045f --- /dev/null +++ b/linux/init/README.md @@ -0,0 +1 @@ +holder From 5dcf0a46aa5380a2ac2782d9e52ae930b77cfbfc Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 10:02:17 +0100 Subject: [PATCH 09/11] Create mmdvmhost MMDVMHost Init Script --- linux/init/mmdvmhost | 98 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 linux/init/mmdvmhost diff --git a/linux/init/mmdvmhost b/linux/init/mmdvmhost new file mode 100644 index 0000000..1ec924b --- /dev/null +++ b/linux/init/mmdvmhost @@ -0,0 +1,98 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: mmdvmhost +# Required-Start: $local_fs $remote_fs $network $syslog +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts the mmdvmhost server +# Description: starts mmdvmhost using start-stop-daemon +### END INIT INFO + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/local/bin/MMDVMHost +CONFIG=/etc/mmdvmhost +NAME=mmdvmhost +DESC=MMDVMHost +USER=mmdvm +GROUP=mmdvm +LOGDIR=/var/log/mmdvmhost +ipVar=`hostname -I | cut -d' ' -f1` + +test -x $DAEMON || exit 0 +test -r $CONFIG || exit 0 + +# Verify the logging directory exists, if not create it and setup the ownership / permissions +if [ ! -d $LOGDIR ]; then + mkdir -p $LOGDIR + chown root:$GROUP $LOGDIR + chmod 775 $LOGDIR +fi + +set -e + +. /lib/lsb/init-functions + +case "$1" in + start) + # Wait for an IP address + until [ $ipVar != " " ]; do + sleep 10 + ipVar=`hostname -I` + done + + if ! pgrep "MMDVMHost" > /dev/null 2>&1; then + log_daemon_msg "Starting Repeater Services" "$NAME" || true + if start-stop-daemon --start --quiet --background --oknodo --pidfile /var/run/$NAME.pid \ + --exec $DAEMON $CONFIG -- $DAEMON_OPTS; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + if pgrep "MMDVMHost" > /dev/null 2>&1; then + pgrep "MMDVMHost" > /var/run/$NAME.pid + fi + + fi + ;; + + + stop) + log_daemon_msg "Stopping Repeater services" "$NAME" || true + if start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/$NAME.pid \ + --exec $DAEMON $CONFIG; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + ;; + + restart|force-reload|reload) + log_daemon_msg "Restarting Repeater services" "$NAME" || true + start-stop-daemon --stop --quiet --oknodo --pidfile \ + /var/run/$NAME.pid --exec $DAEMON $CONFIG + sleep 1 + if start-stop-daemon --start --quiet --background --oknodo --pidfile \ + /var/run/$NAME.pid --exec $DAEMON $CONFIG -- $DAEMON_OPTS; then + log_end_msg 0 || true + else + log_end_msg 1 || true + fi + + if pgrep "MMDVMHost" > /dev/null 2>&1; then + pgrep "MMDVMHost" > /var/run/$NAME.pid + fi + + ;; + + status) + status_of_proc -p /var/run/$NAME.pid "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + *) + echo "Usage: $NAME {start|stop|restart|reload|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 From 255924d4b2e08cbd983606e73cb7ecd8f3915881 Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 10:05:57 +0100 Subject: [PATCH 10/11] Update README.md Initial instructions --- linux/init/README.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/linux/init/README.md b/linux/init/README.md index 10b045f..91ff3ee 100644 --- a/linux/init/README.md +++ b/linux/init/README.md @@ -1 +1,24 @@ -holder +MMDVMHost Init setup +======================= + +Preface +------- + +Init script setup for Linux systems using the older Init setup (not Systemd) + +I hope this helps you get going quickly. +Written on / tested on / confirmed working on Raspbian Wheezy but should work just fine on any +system using init scripts. + +Enjoy, 73 de MW0MWZ + + +Install Instructions +-------------------- + + 1. Copy mmdvmhost to /etc/init.d + 2. Change the permisions of /etc/init.d/mmdvmhost to 550 (root executable) + 3. Change the variables in /etc/init.d/mmdvmhost to match your setup + (MMDVMHost.ini location, log location, user and daemon location) + 4. Enable the service "update-rc.d mmdvmhost defaults" on Rasbian Wheezy + From fa8bae21046e83e546798326984e08aaac62ff7a Mon Sep 17 00:00:00 2001 From: AndyTaylorTweet Date: Mon, 15 Aug 2016 10:09:04 +0100 Subject: [PATCH 11/11] Create README.md Initial README commit --- linux/README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 linux/README.md diff --git a/linux/README.md b/linux/README.md new file mode 100644 index 0000000..7ebbc3c --- /dev/null +++ b/linux/README.md @@ -0,0 +1,14 @@ +Linux Daemon Startup Scripts +============================ + +In the subfolders here you will find start scripts for running MMDVMHost as a daemon on Linux systems using either +systemd or init for their boot. + +In both cases the scripts are fully functional providing the usual start / stop / status etc. + +These have been writting specifically for Raspbian Wheezy (init) and Rasbian Jessie (systemd) although there is +no reason that they shouldnt work on many other distributions. + + +Andy Taylor +Have fun, 73 de MW0MWZ.