SwordArMor-gentoo-overlay/www-apps/tt-rss/files/ttrssd.initd-r4

120 lines
2.8 KiB
Plaintext

#!/sbin/openrc-run
# Copyright 1999-2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
command="/usr/bin/php"
depend() {
need net
after postgresql mysql
}
PID_DIR="/run/ttrssd"
LOG_DIR=${LOG_DIR:-"/var/log/ttrssd"}
TTRSSD_USER=${TTRSSD_USER:-"ttrssd"}
list_instance_dirs() {
if [ -z "${INSTANCE_DIRS}" ]; then
cut -d" " -f4 /var/db/webapps/tt-rss/*/installs 2>/dev/null
else
printf "%s\n" ${INSTANCE_DIRS}
fi
}
instance_dir_to_name() {
local name
name=${1#/}
printf %s "${name}" | awk '{
gsub("/", "--");
print $0;
}'
}
start_pre() {
mkdir -p "${PID_DIR}" "${LOG_DIR}" || return 1
chown "${TTRSSD_USER}":ttrssd "${LOG_DIR}" || return 1
}
start() {
local instance_dir instance_name ret=1
IFS="
"
for instance_dir in $(list_instance_dirs); do
if [ -d "${instance_dir}" ]; then
if [ ! -f "${instance_dir}"/update_daemon2.php ]; then
ewarn "TT-RSS instance in ${instance_dir} has no update_daemon2.php script"
elif [ ! -f "${instance_dir}"/config.php ]; then
eerror "TT-RSS instance in ${instance_dir} is not configured"
else
instance_name=$(instance_dir_to_name "${instance_dir}")
ebegin "Starting TT-RSS update daemon in ${instance_dir}"
start-stop-daemon --start --user "${TTRSSD_USER}":ttrssd \
--background --wait 2000 \
--stdout "${LOG_DIR}/${instance_name}.log" \
--stderr "${LOG_DIR}/${instance_name}.log" \
--make-pidfile --pidfile "${PID_DIR}/${instance_name}.pid" \
--exec /usr/bin/php -- -f "${instance_dir}"/update_daemon2.php \
-- ${TTRSSD_OPTS}
eend $? && ret=0
fi
else
eerror "TT-RSS instance in ${instance_dir} is missing"
fi
done
unset IFS
# Succeed if at least one started.
return ${ret}
}
stop() {
local instance_dir instance_name
IFS="
"
for instance_dir in $(list_instance_dirs); do
instance_name=$(instance_dir_to_name "${instance_dir}")
[ -f "${PID_DIR}/${instance_name}.pid" ] ||
[ -f "${instance_dir}"/update_daemon2.php ] ||
continue
ebegin "Stopping TT-RSS update daemon in ${instance_dir}"
start-stop-daemon --stop --retry 5 --pidfile "${PID_DIR}/${instance_name}.pid" \
--exec /usr/bin/php -- -f "${instance_dir}"/update_daemon2.php \
-- ${TTRSSD_OPTS}
eend $?
rm -f "${instance_dir}"/lock/*.lock
done
unset IFS
# Always succeed.
return 0
}
status() {
local instance_dir instance_name pid
IFS="
"
for instance_dir in $(list_instance_dirs); do
instance_name=$(instance_dir_to_name "${instance_dir}")
[ -f "${PID_DIR}/${instance_name}.pid" ] ||
[ -f "${instance_dir}"/update_daemon2.php ] ||
continue
if start-stop-daemon --signal 0 --pidfile "${PID_DIR}/${instance_name}.pid"; then
# At least one instance is running
return 0
fi
done
unset IFS
# No instances are running
return 3
}