Skip to content

Commit

Permalink
adding 127.0.0.1 to leader's config in update; adding color to pio mqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Aug 16, 2024
1 parent 3b5ad23 commit 1c8033c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 29 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
- more resilience to "UI state" diverging from "bioreactor state". Often, this occurred when two jobs stared almost immediately (often a networking issue), and the last job would halt since it couldn't get the required resources, however any MQTT data would be overwritten by the last job. Now, multiple places in the request pipeline will reduce duplication and prevent two jobs from starting too close to each other.
- improved stirring clean up when stopped in quick succession after starting.
- if a network isn't found, the `monitor` job will not stall, but warn and continue.
- fixed HAT warning for HAT-less leaders.

#### Breaking changes

- removed `psutil` and `zeroconf` packages from new images. We replaced their functionality with built-in routines.
- the web server now writes its logs to the same location as the app: `/var/log/pioreactor.log`. Those wishing to keep the old location can use a new configuration parameter `ui_log_file` to `[logging]` section and set it to `/var/log/pioreactorui.log`.
- removed `psutil` and `zeroconf` Python packages from new images. We replaced their functionality with built-in routines.
- in config.ini, the section `od_config` renamed to `od_reading.config`, and `stirring` is `stirring.config`. When you update, a script will run to automatically update these names in your config.inis.

### 24.7.18
Expand Down
54 changes: 29 additions & 25 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,33 +230,33 @@ def check_for_network(self) -> None:
self.ipv4 = "127.0.0.1"
self.wlan_mac_address = "d8:3a:dd:61:01:59"
self.eth_mac_address = "d8:3a:dd:61:01:60"
else:
return

def did_find_network() -> bool:
ipv4 = get_ip()
def did_find_network() -> bool:
ipv4 = get_ip()

if ipv4 == "127.0.0.1" or ipv4 == "":
# no connection? Sound the alarm.
self.logger.warning("Unable to find a network...")
self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION)
return False
else:
return True
if ipv4 == "127.0.0.1" or ipv4 == "":
# no connection? Sound the alarm.
self.logger.warning("Unable to find a network...")
self.flicker_led_with_error_code(error_codes.NO_NETWORK_CONNECTION)
return False
else:
return True

utils.boolean_retry(did_find_network, retries=3, sleep_for=2)
self.ipv4 = get_ip()
utils.boolean_retry(did_find_network, retries=3, sleep_for=2)
self.ipv4 = get_ip()

try:
with open("/sys/class/net/wlan0/address", "r") as f:
self.wlan_mac_address = f.read().strip()
except FileNotFoundError:
self.wlan_mac_address = "Not available"
try:
with open("/sys/class/net/wlan0/address", "r") as f:
self.wlan_mac_address = f.read().strip()
except FileNotFoundError:
self.wlan_mac_address = "Not available"

try:
with open("/sys/class/net/eth0/address", "r") as f:
self.eth_mac_address = f.read().strip()
except FileNotFoundError:
self.eth_mac_address = "Not available"
try:
with open("/sys/class/net/eth0/address", "r") as f:
self.eth_mac_address = f.read().strip()
except FileNotFoundError:
self.eth_mac_address = "Not available"

self.logger.debug(f"IPv4 address: {self.ipv4}")
self.logger.debug(f"WLAN MAC address: {self.wlan_mac_address}")
Expand All @@ -266,9 +266,6 @@ def self_checks(self) -> None:
# check active network connection
self.check_for_network()

# watch for undervoltage problems
self.check_for_power_problems()

# report on CPU usage, memory, disk space
self.check_and_publish_self_statistics()

Expand All @@ -280,6 +277,9 @@ def self_checks(self) -> None:
self.check_for_required_jobs_running()

if whoami.am_I_a_worker():
# watch for undervoltage problems
self.check_for_power_problems()
# workers need a HAT
self.check_for_HAT()
# check the PCB temperature
self.check_heater_pcb_temperature()
Expand Down Expand Up @@ -543,6 +543,10 @@ def rpi_is_having_power_problems(self) -> tuple[bool, float]:
return False, voltage_read

def check_for_power_problems(self) -> None:
# don't bother checking if hat isn't present
if not is_HAT_present():
return

is_rpi_having_power_probems, voltage = self.rpi_is_having_power_problems()
self.logger.debug(f"PWM power supply at ~{voltage:.2f}V.")
self.voltage_on_pwm_rail = Voltage(voltage=round(voltage, 2), timestamp=current_utc_datetime())
Expand Down
13 changes: 10 additions & 3 deletions pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def logs(n: int) -> None:
) as process:
assert process.stdout is not None
for line in process.stdout:
print(line.decode("utf8").rstrip("\n"))
click.echo(line.decode("utf8").rstrip("\n"))


@pio.command(name="log", short_help="logs a message from the CLI")
Expand Down Expand Up @@ -605,7 +605,7 @@ def mqtt(topic: str) -> None:
"-t",
"#",
"-F",
"%19.19I | %t %p",
"%19.19I||%t||%p",
"-u",
"pioreactor",
"-P",
Expand All @@ -616,7 +616,14 @@ def mqtt(topic: str) -> None:
) as process:
assert process.stdout is not None
for line in process.stdout:
print(line.decode("utf8").rstrip("\n"))
timestamp, topic, value = line.decode("utf8").rstrip("\n").split("||")
click.echo(
click.style(timestamp, fg="cyan")
+ " | "
+ click.style(topic, fg="bright_green")
+ " | "
+ click.style(value, fg="bright_yellow")
)

@update.command(name="ui")
@click.option("-b", "--branch", help="install from a branch on github")
Expand Down
10 changes: 10 additions & 0 deletions update_scripts/upcoming/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ LEADER_HOSTNAME=$(crudini --get $PIO_DIR/config.ini cluster.topology leader_host
if [ "$HOSTNAME" = "$LEADER_HOSTNAME" ]; then
touch "$PIO_DIR/config_$HOSTNAME.ini" # create if it doesn't exist.

crudini --ini-options=nospace --set "$PIO_DIR/config_$HOSTNAME.ini" cluster.topology leader_address 127.0.0.1 \
--set "$PIO_DIR/config_$HOSTNAME.ini" mqtt broker_address 127.0.0.1


# stirring -> stirring.config
# Iterate over each ini file in the directory
for ini_file in "$PIO_DIR"/config*.ini; do
Expand Down Expand Up @@ -79,3 +83,9 @@ if [ "$HOSTNAME" = "$LEADER_HOSTNAME" ]; then

sudo -u pioreactor pios sync-configs
fi


# change the permissions in the log file, and logrotate file

sudo chmod 666 /var/log/pioreactor.log
sudo sed -i 's/create 0660 pioreactor pioreactor/create 0666 pioreactor pioreactor/' /var/log/pioreactor.log

0 comments on commit 1c8033c

Please sign in to comment.