2013-02-21 06:55:49 +00:00
|
|
|
#!/bin/sh
|
2015-04-28 17:35:15 +00:00
|
|
|
SERVICES="pandora pandora-tasks pandora-encoding pandora-cron pandora-websocketd"
|
2013-04-21 15:59:18 +00:00
|
|
|
if [ -z "$1" ]; then
|
2020-05-30 11:01:44 +00:00
|
|
|
echo "Usage: $0 (start|stop|restart|reload|status)"
|
2013-04-28 02:24:19 +00:00
|
|
|
exit 1
|
2013-04-21 15:59:18 +00:00
|
|
|
else
|
|
|
|
action="$1"
|
|
|
|
fi
|
2020-05-30 11:01:44 +00:00
|
|
|
self=`readlink "$0"`
|
|
|
|
if [ -z $self ]; then
|
|
|
|
self="$0"
|
|
|
|
fi
|
2020-05-31 10:22:00 +00:00
|
|
|
|
2016-02-20 07:49:06 +00:00
|
|
|
if [ "$action" = "init" ]; then
|
2020-05-30 11:01:44 +00:00
|
|
|
cd "`dirname "$self"`"
|
2016-02-20 07:49:06 +00:00
|
|
|
BASE=`pwd`
|
2019-12-20 14:08:22 +00:00
|
|
|
SUDO=""
|
|
|
|
PANDORA_USER=`ls -l update.py | cut -f3 -d" "`
|
|
|
|
if [ `whoami` != $PANDORA_USER ]; then
|
2020-09-27 15:53:37 +00:00
|
|
|
SUDO="sudo -E -H -u $PANDORA_USER"
|
2019-12-20 14:08:22 +00:00
|
|
|
fi
|
|
|
|
$SUDO python3 -m venv --system-site-packages .
|
2019-04-30 10:42:28 +00:00
|
|
|
branch=`cat .git/HEAD | sed 's@/@\n@g' | tail -n1`
|
|
|
|
|
2017-11-07 18:44:47 +00:00
|
|
|
# Work around broken venv module in Ubuntu 16.04 / Debian 9
|
|
|
|
if [ ! -e bin/pip ]; then
|
2019-12-20 14:08:22 +00:00
|
|
|
$SUDO bin/python3 -m pip install -U --ignore-installed "pip<9"
|
2017-11-07 18:44:47 +00:00
|
|
|
fi
|
2016-02-20 07:49:06 +00:00
|
|
|
if [ ! -d static/oxjs ]; then
|
2024-06-01 09:37:27 +00:00
|
|
|
$SUDO git clone -b $branch https://code.0x2620.org/0x2620/oxjs.git static/oxjs
|
2016-02-20 07:49:06 +00:00
|
|
|
fi
|
2019-12-20 14:08:22 +00:00
|
|
|
$SUDO mkdir -p src
|
2016-02-20 07:49:06 +00:00
|
|
|
if [ ! -d src/oxtimelines ]; then
|
2024-06-01 09:37:27 +00:00
|
|
|
$SUDO git clone -b $branch https://code.0x2620.org/0x2620/oxtimelines.git src/oxtimelines
|
2016-02-20 07:49:06 +00:00
|
|
|
fi
|
|
|
|
for package in oxtimelines python-ox; do
|
|
|
|
cd ${BASE}
|
|
|
|
if [ ! -d src/${package} ]; then
|
2024-06-01 09:37:27 +00:00
|
|
|
$SUDO git clone -b $branch https://code.0x2620.org/0x2620/${package}.git src/${package}
|
2016-02-20 07:49:06 +00:00
|
|
|
fi
|
|
|
|
cd ${BASE}/src/${package}
|
2023-11-18 15:31:12 +00:00
|
|
|
|
|
|
|
$SUDO ${BASE}/bin/pip install -e .
|
|
|
|
|
2016-02-20 07:49:06 +00:00
|
|
|
done
|
|
|
|
cd ${BASE}
|
2019-12-20 14:08:22 +00:00
|
|
|
$SUDO ./bin/pip install -r requirements.txt
|
2021-11-15 11:49:19 +00:00
|
|
|
for template in gunicorn_config.py encoding.conf tasks.conf; do
|
|
|
|
if [ ! -e pandora/$template ]; then
|
|
|
|
$SUDO cp pandora/${template}.in pandora/$template
|
|
|
|
fi
|
|
|
|
done
|
2016-02-20 07:49:06 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2023-11-18 15:38:20 +00:00
|
|
|
if [ "$action" = "version" ]; then
|
|
|
|
git rev-list HEAD --count
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-05-31 10:22:00 +00:00
|
|
|
|
2020-05-30 11:01:44 +00:00
|
|
|
if [ "$action" = "manage" ]; then
|
2020-05-31 10:22:00 +00:00
|
|
|
cmd="pandora/manage.py"
|
|
|
|
fi
|
|
|
|
if [ "$action" = "update" ]; then
|
|
|
|
cmd="update.py"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z $cmd ]; then
|
2020-05-30 11:01:44 +00:00
|
|
|
cd "`dirname "$self"`"
|
2020-05-30 15:44:49 +00:00
|
|
|
BASE=`pwd`
|
|
|
|
SUDO=""
|
|
|
|
PANDORA_USER=`ls -l update.py | cut -f3 -d" "`
|
|
|
|
if [ `whoami` != $PANDORA_USER ]; then
|
2020-09-27 15:53:37 +00:00
|
|
|
SUDO="sudo -E -H -u $PANDORA_USER"
|
2020-05-30 11:01:44 +00:00
|
|
|
fi
|
|
|
|
shift
|
2020-09-27 15:53:37 +00:00
|
|
|
exec $SUDO "$BASE/$cmd" $@
|
2020-05-30 11:01:44 +00:00
|
|
|
fi
|
2020-05-31 10:22:00 +00:00
|
|
|
|
2013-04-28 02:24:19 +00:00
|
|
|
if [ `whoami` != 'root' ]; then
|
|
|
|
echo you have to be root or run $0 with sudo
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-01-19 17:40:32 +00:00
|
|
|
if [ "$action" = "install" ]; then
|
2021-11-15 11:52:48 +00:00
|
|
|
cd "`dirname "$self"`"
|
2015-01-19 17:40:32 +00:00
|
|
|
BASE=`pwd`
|
|
|
|
if [ -x /bin/systemctl ]; then
|
2016-06-09 10:38:13 +00:00
|
|
|
if [ -d /etc/systemd/system/ ]; then
|
2021-11-15 11:49:19 +00:00
|
|
|
for template in gunicorn_config.py encoding.conf tasks.conf; do
|
|
|
|
if [ ! -e pandora/$template ]; then
|
|
|
|
$SUDO cp pandora/${template}.in pandora/$template
|
|
|
|
fi
|
|
|
|
done
|
2016-06-13 09:28:57 +00:00
|
|
|
for service in $SERVICES; do
|
|
|
|
if [ -e /lib/systemd/system/${service}.service ]; then
|
|
|
|
rm -f /lib/systemd/system/${service}.service \
|
|
|
|
/etc/systemd/system/multi-user.target.wants/${service}.service
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-06-09 10:50:34 +00:00
|
|
|
cp $BASE/etc/systemd/system/*.service /etc/systemd/system/
|
2016-06-09 10:38:13 +00:00
|
|
|
cp $BASE/etc/tmpfiles.d/pandora.conf /etc/tmpfiles.d/
|
|
|
|
systemd-tmpfiles --create /etc/tmpfiles.d/pandora.conf >/dev/null || true
|
2016-03-07 08:55:24 +00:00
|
|
|
systemctl daemon-reload
|
2015-04-28 17:35:15 +00:00
|
|
|
for service in $SERVICES; do
|
2015-01-19 17:40:32 +00:00
|
|
|
systemctl enable ${service}.service
|
|
|
|
done
|
|
|
|
fi
|
2020-05-30 15:44:49 +00:00
|
|
|
test -e /usr/local/bin/pandoractl || ln -s /srv/pandora/ctl /usr/local/bin/pandoractl
|
2015-01-19 17:40:32 +00:00
|
|
|
else
|
|
|
|
if [ -d /etc/init ]; then
|
|
|
|
cp $BASE/etc/init/* /etc/init/
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-05-30 11:01:44 +00:00
|
|
|
if [ "status" = "$action" ]; then
|
|
|
|
export SYSTEMD_PAGER=
|
|
|
|
fi
|
2015-04-28 17:35:15 +00:00
|
|
|
for service in $SERVICES; do
|
2020-05-30 11:01:44 +00:00
|
|
|
if [ -x /bin/systemctl ]; then
|
|
|
|
/bin/systemctl $action $service
|
|
|
|
else
|
|
|
|
service $service $action
|
|
|
|
fi
|
2013-02-21 06:55:49 +00:00
|
|
|
done
|