Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ endif
RPMVERSION:=$(shell echo $(VERSION) | tr -- - _)

define PACKAGE_ARGS
--before-install init/systemd/before-install.sh \
--after-install init/systemd/after-install.sh \
--before-remove init/systemd/before-remove.sh \
--name unpackerr \
Expand Down Expand Up @@ -402,4 +403,4 @@ lint: generate
##################

docker:
init/docker/makedocker.sh
init/docker/makedocker.sh
42 changes: 26 additions & 16 deletions init/bsd/freebsd.rc.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,41 @@
# PROVIDE: unpackerr
# REQUIRE: networking syslog
# KEYWORD:
#
# Add the following line to /etc/rc.conf or use `sysrc` to enable unpackerr.
# ${unpackerr_enable="YES"}
# Optionally there are other parameters:
# ${unpackerr_user="unpackerr"}
# ${unpackerr_group="unpackerr"}
# ${unpackerr_config="/usr/local/etc/unpackerr/unpackerr.conf"}

. /etc/rc.subr

name="unpackerr"
real_name="unpackerr"
rcvar="unpackerr_enable"
unpackerr_command="/usr/local/bin/${real_name}"
unpackerr_user="unpackerr"
unpackerr_config="/usr/local/etc/${real_name}/unpackerr.conf"
pidfile="/var/run/${real_name}/pid"

# This runs `daemon` as the `unpackerr_user` user.
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -r -t ${real_name} -T ${real_name} -l daemon ${unpackerr_command} -c ${unpackerr_config}"
unpackerr_command="/usr/local/bin/${name}"
pidfile="/var/run/${name}/pid"
unpackerr_env="UN_LOG_FILE=/usr/local/var/log/${name}/${name}.log UN_WEBSERVER_LOG_FILE=/usr/local/var/log/${name}/http.log UN_QUIET=true"
# Suck in optional exported override variables. See: https://unpackerr.zip/docs/install/configuration
# ie. add something like the following to this file: export UN_DEBUG=true
unpackerr_env_file="/usr/local/etc/defaults/${name}"

load_rc_config ${name}
: ${unpackerr_enable:=no}
: ${unpackerr_enable:=NO}
: ${unpackerr_user:="unpackerr"}
: ${unpackerr_group:="unpackerr"}
: ${unpackerr_config:="/usr/local/etc/unpackerr/unpackerr.conf"}

# Make a place for the pid file.
mkdir -p $(dirname ${pidfile})
chown -R $unpackerr_user $(dirname ${pidfile})
# This runs `daemon` as the `unpackerr_user` user using `chroot`.
command="/usr/sbin/daemon"
command_args="-P ${pidfile} -r -t ${name} -T ${name} -l daemon ${unpackerr_command} -c ${unpackerr_config}"

# Suck in optional exported override variables.
# ie. add something like the following to this file: export UP_POLLER_DEBUG=true
[ -f "/usr/local/etc/defaults/${real_name}" ] && . "/usr/local/etc/defaults/${real_name}"
start_precmd=${name}_precmd
unpackerr_precmd() {
# Make a place for the pid file.
mkdir -p $(dirname ${pidfile})
chown -R $unpackerr_user $(dirname ${pidfile})
}

# Go!
run_rc_command "$1"
19 changes: 7 additions & 12 deletions init/systemd/after-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@

OS="$(uname -s)"

if [ "${OS}" = "Linux" ]; then
# Make a user and group for this app, but only if it does not already exist.
id unpackerr >/dev/null 2>&1 || \
useradd --system --user-group --no-create-home --home-dir /tmp --shell /bin/false unpackerr
elif [ "${OS}" = "OpenBSD" ]; then
id unpackerr >/dev/null 2>&1 || \
useradd -g =uid -d /tmp -s /bin/false unpackerr
elif [ "${OS}" = "FreeBSD" ]; then
id unpackerr >/dev/null 2>&1 || \
pw useradd unpackerr -d /tmp -w no -s /bin/false
else
echo "Unknown OS: ${OS}, please add system user unpackerr manually."
logdir='/var/log/unpackerr'
[[ "$(uname -s)" = "Linux" ]] || logdir='/usr/local/var/log/unpackerr'

if [ ! -d "${logdir}" ]; then
mkdir "${logdir}"
chown unpackerr: "${logdir}"
chmod 0755 "${logdir}"
fi

if [ -x "/bin/systemctl" ]; then
Expand Down
20 changes: 20 additions & 0 deletions init/systemd/before-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# This file is used by deb, rpm and BSD packages.
# FPM adds this as the before-install script.

OS="$(uname -s)"

if [ "${OS}" = "Linux" ]; then
# Make a user and group for this app, but only if it does not already exist.
id unpackerr >/dev/null 2>&1 || \
useradd --system --user-group --no-create-home --home-dir /tmp --shell /bin/false unpackerr
elif [ "${OS}" = "OpenBSD" ]; then
id unpackerr >/dev/null 2>&1 || \
useradd -g =uid -d /tmp -s /bin/false unpackerr
elif [ "${OS}" = "FreeBSD" ]; then
id unpackerr >/dev/null 2>&1 || \
pw useradd unpackerr -d /tmp -w no -s /bin/false
else
echo "Unknown OS: ${OS}, please add system user unpackerr manually."
fi