Skip to content

Commit

Permalink
only run on leader
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Apr 3, 2024
1 parent 933b003 commit b4d8473
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
9 changes: 8 additions & 1 deletion pioreactor/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,14 @@ def _get_jobs(self, all_jobs: bool = False, **query) -> list[tuple[str, int]]:
where_clause = " AND ".join([f"{key} = :{key}" for key in query.keys() if query[key] is not None])

# Construct the SELECT query
select_query = f"SELECT name, pid FROM pio_job_metadata WHERE {where_clause} AND is_running=1;"
select_query = f"""
SELECT
name, pid
FROM pio_job_metadata
WHERE is_running=1
AND name NOT IN {self.LONG_RUNNING_JOBS}
AND {where_clause};
"""

# Execute the query and fetch the results
self.cursor.execute(select_query, query)
Expand Down
53 changes: 29 additions & 24 deletions update_scripts/upcoming/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ else
fi
# Write the information to a file in key-value format
echo "HOSTNAME=$(hostname)" >> /boot/firmware/network_info
echo "IP=$IP" > /boot/firmware/network_info
echo "WLAN_MAC=$WLAN_MAC" >> /boot/firmware/network_info
echo "ETH_MAC=$ETH_MAC" >> /boot/firmware/network_info
# Check if the IP variable is empty and log an error if necessary
if [ -z "$IP" ]; then
echo "Error: No IP address found." >> /boot/firmware/network_info
fi
echo "HOSTNAME=$(hostname)" >> /boot/firmware/network_info.txt
echo "IP=$IP" > /boot/firmware/network_info.txt
echo "WLAN_MAC=$WLAN_MAC" >> /boot/firmware/network_info.txt
echo "ETH_MAC=$ETH_MAC" >> /boot/firmware/network_info.txt
EOF
)

Expand All @@ -54,29 +50,38 @@ sudo chmod +x /usr/local/bin/write_ip.sh



#### LEADER only!

PIO_DIR=/home/pioreactor/.pioreactor
# Get the hostname
HOSTNAME=$(hostname)

#### LEADER only!
# Get the leader address
LEADER_ADDRESS=$(crudini --get $PIO_DIR/config.ini cluster.topology leader_address)

#### Fix issue with `pio log` commands in systemd services failing
if [ "$HOSTNAME.local" = "$LEADER_ADDRESS" ]; then

# List of systemd files
systemd_files=("/lib/systemd/system/avahi_aliases.service" "/lib/systemd/system/load_rp2040.service")

# Loop through each file and add 'User=pioreactor' and 'EnvironmentFile=/etc/environment' under '[Service]' if they don't already exist
for file in "${systemd_files[@]}"; do
sudo crudini --ini-options=nospace --set "$file" Service User pioreactor \
--set "$file" Service EnvironmentFile "/etc/environment"
done
#### Fix issue with `pio log` commands in systemd services failing

sudo systemctl daemon-reload
# List of systemd files
systemd_files=("/lib/systemd/system/avahi_aliases.service" "/lib/systemd/system/load_rp2040.service")

sudo systemctl restart avahi_aliases.service
sudo systemctl restart load_rp2040.service
# Loop through each file and add 'User=pioreactor' and 'EnvironmentFile=/etc/environment' under '[Service]' if they don't already exist
for file in "${systemd_files[@]}"; do
sudo crudini --ini-options=nospace --set "$file" Service User pioreactor \
--set "$file" Service EnvironmentFile "/etc/environment"
done

sudo systemctl daemon-reload

sudo systemctl restart avahi_aliases.service
sudo systemctl restart load_rp2040.service

### update add_new_pioreactor_worker_from_leader to use pio workers discover

FILE_PATH="/usr/local/bin/add_new_pioreactor_worker_from_leader.sh"
sudo sed -i 's/pio discover-workers/pio workers discover/g' "$FILE_PATH"

### update add_new_pioreactor_worker_from_leader to use pio workers discover

FILE_PATH="/usr/local/bin/add_new_pioreactor_worker_from_leader.sh"
sudo sed -i 's/pio discover-workers/pio workers discover/g' "$FILE_PATH"
fi

0 comments on commit b4d8473

Please sign in to comment.