Changeset View
Changeset View
Standalone View
Standalone View
www/tt-rss/files/ttrssd.in
Show All 16 Lines | |||||
name="ttrssd" | name="ttrssd" | ||||
rcvar=ttrssd_enable | rcvar=ttrssd_enable | ||||
# read settings, set default values | # read settings, set default values | ||||
load_rc_config "${name}" | load_rc_config "${name}" | ||||
: ${ttrssd_enable="NO"} | : ${ttrssd_enable="NO"} | ||||
: ${ttrssd_local_db:="YES"} | : ${ttrssd_local_db:="YES"} | ||||
initdb_php="%%WWWDIR%%/update.php" | |||||
required_files="%%WWWDIR%%/config.php" | required_files="%%WWWDIR%%/config.php" | ||||
pidfile="/var/run/${name}.pid" | pidfile="/var/run/${name}.pid" | ||||
ppidfile="/var/run/${name}_parent.pid" | |||||
phpcli="%%LOCALBASE%%/bin/php" | phpcli="%%LOCALBASE%%/bin/php" | ||||
command_interpreter=$phpcli | command_interpreter=$phpcli | ||||
long_name="Tiny Tiny RSS updating feeds daemon." | long_name="Tiny Tiny RSS updating feeds daemon." | ||||
phpupd="update_daemon2.php" | phpupd="%%WWWDIR%%/update_daemon2.php" | ||||
ttrssd_log="/var/log/${name}.log" | ttrssd_log="/var/log/${name}.log" | ||||
ttrssd_user="%%WWWOWN%%" | ttrssd_user="%%WWWOWN%%" | ||||
start_precmd=${name}_prestart | start_precmd=${name}_prestart | ||||
start_cmd=${name}_start | start_cmd=${name}_start | ||||
stop_cmd=${name}_stop | stop_cmd=${name}_stop | ||||
%%MYSQL%%CHECK_CMD="%%LOCALBASE%%/bin/mysqladmin -u mysqld ping" | %%MYSQL%%CHECK_CMD="%%LOCALBASE%%/bin/mysqladmin -u mysqld ping" | ||||
%%MYSQL%%CHECK_MSG="${name}: mysqladmin command failed; mysql not ready?" | %%MYSQL%%CHECK_MSG="${name}: mysqladmin command failed; mysql not ready?" | ||||
# Waiting for pg_isready when 9.3 is the default | %%PGSQL%%CHECK_CMD="%%LOCALBASE%%/bin/pg_isready" | ||||
%%PGSQL%%CHECK_CMD="%%LOCALBASE%%/etc/rc.d/postgresql status" | |||||
%%PGSQL%%CHECK_MSG="${name}: postgresql status failed; postgresql not ready?" | %%PGSQL%%CHECK_MSG="${name}: postgresql status failed; postgresql not ready?" | ||||
ttrssd_start() { | ttrssd_start() { | ||||
[ -x $phpcli ] || (echo "$phpcli not found"; exit 1) | if ! [ -x $phpcli ]; then | ||||
[ -f $pidfile ] && (echo "$name already running?"; exit 2) | echo "$phpcli not found" | ||||
exit 1 | |||||
fi | |||||
if [ -f $pidfile ]; then | |||||
echo "$name already running?" | |||||
exit 2 | |||||
fi | |||||
echo "Starting $long_name" | echo "Starting $long_name" | ||||
(cd %%WWWDIR%% && su -fm $ttrssd_user -c "./$phpupd" > $ttrssd_log &) && \ | daemon -P "$ppidfile" -p "$pidfile" -u "$ttrssd_user" -o "$ttrssd_log" \ | ||||
echo $$ > $pidfile | sh -c "${initdb_php} --update-schema=force-yes; $phpupd" | ||||
} | } | ||||
ttrssd_stop() { | ttrssd_stop() { | ||||
[ -f $pidfile ] || (echo "$name not running?"; exit 1) | if ! [ -f $pidfile ]; then | ||||
echo "$name not running?" | |||||
exit 1 | |||||
fi | |||||
echo "Stopping $long_name" | echo "Stopping $long_name" | ||||
kill `ps ax | grep $phpupd | grep -v grep | awk '{print $1}'` | pkill -CHLD -F "$pidfile" | ||||
rm -f $pidfile | pkill -F "$pidfile" | ||||
pwait "$(cat $ppidfile)" | |||||
} | } | ||||
ttrssd_prestart() { | ttrssd_prestart() { | ||||
if checkyesno ttrssd_local_db; then | if checkyesno ttrssd_local_db; then | ||||
# Wait for the local database to be started | # Wait for the local database to be started | ||||
local _count=0 | |||||
while : ; do | for n in $(seq 1 10); do | ||||
$CHECK_CMD > /dev/null 2>&1 && return | if $CHECK_CMD > /dev/null 2>&1; then | ||||
_count=$(( $_count + 1 )) | return | ||||
if [ $_count -gt 10 ]; then | |||||
err 1 $CHECK_MSG | |||||
fi | fi | ||||
sleep 1 | sleep 1 | ||||
done | done | ||||
err 1 $CHECK_MSG | |||||
fi | fi | ||||
} | } | ||||
run_rc_command "$1" | run_rc_command "$1" |