From 9d3eda1959197974ad7586a720cabf93b4d4ea0d Mon Sep 17 00:00:00 2001 From: scarlett Date: Sun, 16 Dec 2018 12:33:50 +0000 Subject: [PATCH 1/2] Add an rc.d script for NetBSD. --- installation/netbsd/rc.d/pleroma | 66 ++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 installation/netbsd/rc.d/pleroma diff --git a/installation/netbsd/rc.d/pleroma b/installation/netbsd/rc.d/pleroma new file mode 100755 index 000000000..34b818270 --- /dev/null +++ b/installation/netbsd/rc.d/pleroma @@ -0,0 +1,66 @@ +#!/bin/sh +# PROVIDE: pleroma +# REQUIRE: DAEMON pgsql + +if [ -f /etc/rc.subr ]; then + . /etc/rc.subr +fi + +name="pleroma" +rcvar=${name} +command="/usr/pkg/bin/elixir" +command_args="/usr/pkg/bin/mix phx.server &" +start_cmd=pleroma_start +start_precmd="ulimit -n unlimited" +pidfile="${pleroma_home}/pleroma/pid" + +pleroma_chdir="${pleroma_home}/pleroma" +pleroma_env="HOME=${pleroma_home} MIX_ENV=prod" +pleroma_user="pleroma" + +pleroma_start() +{ + echo "Starting ${name}." + ${start_precmd} + su -m ${pleroma_user} -c "cd ${pleroma_chdir} && \ + ${pleroma_env} ${command} ${command_args}" + echo $! > ${pidfile} +} + +check_pidfile() +{ + read _pid _junk < ${pidfile} + echo -n "$(ps -axo pid | grep ${_pid})" +} + +if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then # newer NetBSD + load_rc_config ${name} + run_rc_command "$1" +else # ancient NetBSD, Solaris and illumos, Linux, etc... + cmd=${1:-start} + + case ${cmd} in + start) + echo "Starting ${name}." + ${start_cmd} + ;; + + stop) + echo "Stopping ${name}." + kill `cat ${pidfile}` + rm ${pidfile} + ;; + + restart) + ( $0 stop ) + sleep 5 + $0 start + ;; + + *) + echo 1>&2 "Usage: $0 [start|stop|restart]" + exit 1 + ;; + esac + exit 0 +fi From 4b40e4188c9d9ccbe1c5908fc4bead09ad2c08f2 Mon Sep 17 00:00:00 2001 From: scarlett Date: Sun, 16 Dec 2018 13:11:17 +0000 Subject: [PATCH 2/2] Simplify the NetBSD rc script. --- installation/netbsd/rc.d/pleroma | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/installation/netbsd/rc.d/pleroma b/installation/netbsd/rc.d/pleroma index 34b818270..1114668ee 100755 --- a/installation/netbsd/rc.d/pleroma +++ b/installation/netbsd/rc.d/pleroma @@ -9,34 +9,25 @@ fi name="pleroma" rcvar=${name} command="/usr/pkg/bin/elixir" -command_args="/usr/pkg/bin/mix phx.server &" -start_cmd=pleroma_start +command_args="--detached -S /usr/pkg/bin/mix phx.server" start_precmd="ulimit -n unlimited" -pidfile="${pleroma_home}/pleroma/pid" +pidfile="/dev/null" pleroma_chdir="${pleroma_home}/pleroma" pleroma_env="HOME=${pleroma_home} MIX_ENV=prod" -pleroma_user="pleroma" - -pleroma_start() -{ - echo "Starting ${name}." - ${start_precmd} - su -m ${pleroma_user} -c "cd ${pleroma_chdir} && \ - ${pleroma_env} ${command} ${command_args}" - echo $! > ${pidfile} -} check_pidfile() { - read _pid _junk < ${pidfile} - echo -n "$(ps -axo pid | grep ${_pid})" + pid=$(pgrep -U "${pleroma_user}" /bin/beam.smp$) + echo -n "${pid}" } -if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then # newer NetBSD +if [ -f /etc/rc.subr -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]; then + # newer NetBSD load_rc_config ${name} run_rc_command "$1" -else # ancient NetBSD, Solaris and illumos, Linux, etc... +else + # ancient NetBSD, Solaris and illumos, Linux, etc... cmd=${1:-start} case ${cmd} in @@ -47,8 +38,8 @@ else # ancient NetBSD, Solaris and illumos, Linux, etc... stop) echo "Stopping ${name}." - kill `cat ${pidfile}` - rm ${pidfile} + check_pidfile + ! [ -n ${pid} ] && kill ${pid} ;; restart)