blob: 82bfdd00461ebf2e0c088c45c29bb6ed9844caee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#!/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
}
|