-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathxcserver.sh
More file actions
74 lines (67 loc) · 2.53 KB
/
xcserver.sh
File metadata and controls
74 lines (67 loc) · 2.53 KB
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
#!/bin/bash
set -e
# Run as root to install cronitor and set permissions
if [ "$(id -u)" = "0" ]; then
# Set the uid and gid based on environment variables PUID/PGID
if [ -n "${PUID}" ] && [ -n "${PGID}" ]; then
echo "Setting iptvboss user and group id to ${PUID} and ${PGID}..."
groupmod -o -g "${PGID}" iptvboss
usermod -o -u "${PUID}" iptvboss
usermod -aG audio iptvboss
chown -R ${PUID}:${PGID} /headless
else
echo "PUID or PGID not set. Using default values."
fi
# Install cronitor
if [ -n "$CRONITOR_API_KEY" ]; then
echo "Installing cronitor..."
curl -s https://cronitor.io/install-linux?sudo=1 -H "API-KEY: $CRONITOR_API_KEY" | sh > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Cronitor installed successfully."
else
echo "Error: Cronitor installation failed." >&2
fi
else
echo "CRONITOR_API_KEY not set. Skipping cronitor installation."
fi
# Start cron daemon as root
echo "Starting the cron daemon"
cron
echo "The cron daemon started successfully."
# Give execution rights on the cron job
crontab -u iptvboss /headless/iptvboss-cron && \
chmod u+s /usr/sbin/cron && \
touch /var/log/cron.log && \
chown iptvboss:iptvboss /var/log/cron.log
# Change to iptvboss user for user-level commands
exec gosu iptvboss "$BASH_SOURCE" "$@"
fi
# The following will run as iptvboss user due to gosu command above
if [ -n "$CRON_SCHEDULE" ]; then
echo "Configuring Cron schedule for iptvboss user..."
CRON_LINE="$CRON_SCHEDULE /usr/lib/iptvboss/bin/iptvboss -nogui >> /var/log/cron.log 2>&1"
if grep -q 'iptvboss -nogui' /headless/iptvboss-cron 2>/dev/null; then
sed -i -e "s|.*iptvboss -nogui.*|$CRON_LINE|" /headless/iptvboss-cron
else
echo "$CRON_LINE" >> /headless/iptvboss-cron
fi
crontab /headless/iptvboss-cron
echo "CRON_SCHEDULE set for $CRON_SCHEDULE. Updated the cron job schedule."
else
echo "CRON_SCHEDULE not set. No cron job configured for iptvboss."
fi
# Configure cronitor if API key is provided
if [ -n "$CRONITOR_API_KEY" ]; then
configure_cronitor() {
python3 /headless/scripts/cronitor.py --name "$CRONITOR_SCHEDULE_NAME"
}
configure_cronitor
fi
# Start the iptvboss service
echo "Starting iptvboss XC server"
/usr/bin/iptvboss -xcserver
if [ $? -eq 0 ]; then
echo "Debug: /usr/bin/iptvboss -xcserver started successfully."
else
echo "Error: Failed to start /usr/bin/iptvboss -xcserver." >&2
fi