Improve FreeBSD rc script
authorMark Felder <feld@FreeBSD.org>
Tue, 18 Aug 2020 15:24:34 +0000 (10:24 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 18 Aug 2020 15:24:34 +0000 (10:24 -0500)
Passes rclint now, $HOME is dynamic, and properly matches process name for signalling shutdown.

installation/freebsd/rc.d/pleroma

index 1e41e57e6b5cfe188020f02cc199361e268417c3..f62aef18dc3e9d911cf33efc2ac1715407840cd9 100755 (executable)
@@ -1,28 +1,27 @@
 #!/bin/sh
-# REQUIRE: DAEMON postgresql
+# $FreeBSD$
 # PROVIDE: pleroma
+# REQUIRE: DAEMON postgresql
+# KEYWORD: shutdown
 
 # sudo -u pleroma MIX_ENV=prod elixir --erl \"-detached\" -S mix phx.server
 
 . /etc/rc.subr
 
-name="pleroma"
+name=pleroma
+rcvar=pleroma_enable
+
 desc="Pleroma Social Media Platform"
-rcvar=${name}_enable
-command="/usr/local/bin/elixir"
-command_args="--erl \"-detached\" -S /usr/local/bin/mix phx.server"
-pidfile="/dev/null"
 
-pleroma_user="pleroma"
-pleroma_home="/home/pleroma"
-pleroma_chdir="${pleroma_home}/pleroma"
-pleroma_env="HOME=${pleroma_home} MIX_ENV=prod"
+load_rc_config ${name}
 
-check_pidfile()
-{
-       pid=$(pgrep beam.smp$)
-       echo -n "${pid}"
-}
+: ${pleroma_user:=pleroma}
+: ${pleroma_home:=$(getent passwd ${pleroma_user} | awk -F: '{print $6}')}
+: ${pleroma_chdir:="${pleroma_home}/pleroma"}
+: ${pleroma_env:="HOME=${pleroma_home} MIX_ENV=prod"}
+
+command=/usr/local/bin/elixir
+command_args="--erl \"-detached\" -S /usr/local/bin/mix phx.server"
+procname="*beam.smp"
 
-load_rc_config ${name}
 run_rc_command "$1"