Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Sep 12, 2024
1 parent 1e1056d commit 11026cf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ def update_app(
(f"sudo bash {tmp_rls_dir}/pre_update.sh", 2),
(f"sudo bash {tmp_rls_dir}/update.sh", 4),
(f"sudo bash {tmp_rls_dir}/post_update.sh", 20),
(f"mv {tmp_rls_dir}/pioreactorui_*.tar.gz {tmp_dir}/pioreactorui_archive", 98), # move ui folder to be accessed by a `pio update ui`
(f"rm -rf {tmp_rls_dir}", 99),
]
)
Expand All @@ -407,7 +408,6 @@ def update_app(
commands_and_priority.extend([
(f"sudo pip install --no-index --find-links={tmp_rls_dir}/wheels/ {tmp_rls_dir}/pioreactor-{version_installed}-py3-none-any.whl[leader,worker]", 3),
(f'sudo sqlite3 {config.config["storage"]["database"]} < {tmp_rls_dir}/update.sql', 10),
(f"mv {tmp_rls_dir}/pioreactorui_*.tar.gz {tmp_dir}/pioreactorui_archive", 98), # move ui folder to be accessed by a `pio update ui`
])
else:
commands_and_priority.extend([
Expand Down
Binary file removed update_scripts/upcoming/lighttpd_packages.zip
Binary file not shown.
67 changes: 46 additions & 21 deletions update_scripts/upcoming/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ set -xeu

export LC_ALL=C

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

UI_FOLDER=/var/www/pioreactorui
SYSTEMD_DIR=/lib/systemd/system/
UI_TAG="TODO"
UI_TAG="TODO" # TODO

HOSTNAME=$(hostname)

Expand All @@ -18,10 +19,12 @@ LEADER_HOSTNAME=$(crudini --get "$PIO_DIR"/config.ini cluster.topology leader_ho
if [ "$HOSTNAME" != "$LEADER_HOSTNAME" ]; then
# worker updates

# 1. install pioreactorui
mkdir /var/www
# install pioreactorui
rm -rf $UI_FOLDER
mkdir -p /var/www

tar -xzf pioreactorui.tar.gz # TODO: correct location

tar -xzf "$SCRIPT_DIR"/pioreactorui_"$UI_TAG".tar.gz
mv pioreactorui-"$UI_TAG" /var/www
mv /var/www/pioreactorui-"$UI_TAG" $UI_FOLDER

Expand All @@ -33,6 +36,7 @@ if [ "$HOSTNAME" != "$LEADER_HOSTNAME" ]; then
touch $UI_FOLDER/huey.db-shm
touch $UI_FOLDER/huey.db-wal


# make correct permissions in new www folders and files
# https://superuser.com/questions/19318/how-can-i-give-write-access-of-a-folder-to-all-users-in-linux
chown -R pioreactor:www-data /var/www
Expand All @@ -42,31 +46,52 @@ if [ "$HOSTNAME" != "$LEADER_HOSTNAME" ]; then
chmod +x $UI_FOLDER/main.fcgi

# install lighttp and set up mods
apt-get install lighttpd -y # TODO
unzip lighttpd_packages.zip -d lighttpd_packages
dpkg -i lighttpd_packages/*.deb

# install our own lighttpd service
sudo cp /files/system/systemd/lighttpd.service $SYSTEMD_DIR
sudo systemctl enable lighttpd.service

cp -u "$SCRIPT_DIR"/lighttpd.service $SYSTEMD_DIR

cp /files/system/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf
cp /files/system/lighttpd/50-pioreactorui.conf /etc/lighttpd/conf-available/50-pioreactorui.conf
cp /files/system/lighttpd/52-api-only.conf /etc/lighttpd/conf-available/52-api-only.conf
cp -u "$SCRIPT_DIR"/lighttpd.conf /etc/lighttpd/
cp -u "$SCRIPT_DIR"/50-pioreactorui.conf /etc/lighttpd/conf-available/
cp -u "$SCRIPT_DIR"/52-api-only.conf /etc/lighttpd/conf-available/

lighttpd-enable-mod fastcgi
lighttpd-enable-mod rewrite
lighttpd-enable-mod pioreactorui
/usr/sbin/lighttpd-enable-mod fastcgi
/usr/sbin/lighttpd-enable-mod rewrite
/usr/sbin/lighttpd-enable-mod pioreactorui
# workers only have an api, not served static files.
lighttpd-enable-mod api-only
/usr/sbin/lighttpd-enable-mod api-only


cp -u "$SCRIPT_DIR"/create_diskcache.sh /usr/local/bin/
cp -u "$SCRIPT_DIR"/update_ui.sh /usr/local/bin/

cp -u "$SCRIPT_DIR"/huey.service $SYSTEMD_DIR
cp -u "$SCRIPT_DIR"/create_diskcache.service $SYSTEMD_DIR

# 2. Add necessary files and services
# TODO: add update_ui.sh
# TODO: add create_diskcache.sh
# TODO: add huey.service
# TODO: add create_diskcache.service
systemctl enable huey.service
systemctl enable create_diskcache.service
systemctl enable lighttpd.service


# don't need to start these services, as we do a pio update ui which should handle this.
else

CONFIG_FILE=/etc/lighttpd/conf-available/50-pioreactorui.conf
# add new unit_api to rewrite
# Check if the unit_api rule is already present
if grep -q 'unit_api' "$CONFIG_FILE"; then
echo "unit_api rewrite rule already exists."
else
# Add the new rewrite rule for /unit_api
sed -i '/^url.rewrite-once = (/a\ "^(/unit_api/.*)$" => "/main.fcgi$1",' "$CONFIG_FILE"
fi

fi

# TODO add updated pioreactorui lighttpd conf


# test services
huey_consumer -h
lighttpd -h
flask --help

0 comments on commit 11026cf

Please sign in to comment.