Skip to content

Commit

Permalink
new firstboot files
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Aug 21, 2024
1 parent 1f71af7 commit 5b898cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion workspace/scripts/06-install-pioreactor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ common:
EOT

sudo chown pioreactor:pioreactor $PIO_DIR/experiment_profiles/demo_logging_example.yaml
sudo -u $USERNAME touch $PIO_DIR/unit_config.ini


if [ "$LEADER" == "1" ]; then
Expand All @@ -102,7 +104,6 @@ fi


if [ "$WORKER" == "1" ]; then
sudo -u $USERNAME touch $PIO_DIR/unit_config.ini
sudo apt-get install -y python3-numpy

if [ "$PIO_VERSION" == "develop" ]; then
Expand Down
15 changes: 8 additions & 7 deletions workspace/scripts/files/bash/firstboot_leader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ USERNAME=pioreactor
PIO_DIR=/home/$USERNAME/.pioreactor
SSH_DIR=/home/$USERNAME/.ssh
DB_LOC=$(crudini --get $PIO_DIR/config.ini storage database)
HOSTNAME=$(hostname)

# clean up if this needs to run again.
sudo -u $USERNAME rm -f $SSH_DIR/{authorized_keys,known_hosts,id_rsa,id_rsa.pub}
Expand All @@ -18,11 +19,11 @@ sudo -u $USERNAME touch $SSH_DIR/known_hosts

sudo -u $USERNAME ssh-keygen -q -t rsa -N '' -f $SSH_DIR/id_rsa
sudo -u $USERNAME cat $SSH_DIR/id_rsa.pub > $SSH_DIR/authorized_keys
sudo -u $USERNAME ssh-keyscan "$(hostname)".local >> $SSH_DIR/known_hosts
sudo -u $USERNAME ssh-keyscan "$HOSTNAME".local >> $SSH_DIR/known_hosts

crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_hostname "$(hostname)"
crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_address "$(hostname)".local
crudini --ini-options=nospace --set $PIO_DIR/config.ini mqtt broker_address "$(hostname)".local
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_hostname "$HOSTNAME"
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_address "$HOSTNAME".local
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config.ini mqtt broker_address "$HOSTNAME".local

sqlite3 $DB_LOC "INSERT OR IGNORE INTO experiments (created_at, experiment, description) VALUES (STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW'), 'Demo experiment', 'This is a demo experiment. Feel free to click around. When you are ready, create a new experiment in the dropdown to the left.');"

Expand All @@ -31,7 +32,7 @@ sqlite3 $DB_LOC "INSERT OR IGNORE INTO experiments (created_at, experiment, desc
sudo -u $USERNAME touch "$PIO_DIR/config_$HOSTNAME.ini" # set with the correct read/write permissions
printf '# Any settings here are specific to %s, the leader, and override the settings in config.ini\n\n' "$HOSTNAME" >> "$PIO_DIR/config_$HOSTNAME.ini"

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

cp "$PIO_DIR/config_$HOSTNAME.ini" "$PIO_DIR/unit_config.ini"
cp -a "$PIO_DIR/config_$HOSTNAME.ini" "$PIO_DIR/unit_config.ini"
16 changes: 8 additions & 8 deletions workspace/scripts/files/bash/firstboot_leader_and_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ sudo -u $USERNAME ssh-keygen -q -t rsa -N '' -f $SSH_DIR/id_rsa
sudo -u $USERNAME cat $SSH_DIR/id_rsa.pub > $SSH_DIR/authorized_keys
sudo -u $USERNAME ssh-keyscan "$HOSTNAME".local >> $SSH_DIR/known_hosts

crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_hostname "$HOSTNAME"
crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_address "$HOSTNAME".local
crudini --ini-options=nospace --set $PIO_DIR/config.ini mqtt broker_address "$HOSTNAME".local
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_hostname "$HOSTNAME"
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config.ini cluster.topology leader_address "$HOSTNAME".local
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config.ini mqtt broker_address "$HOSTNAME".local

sqlite3 "$DB_LOC" "INSERT OR IGNORE INTO experiments (created_at, experiment, description) VALUES (STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW'), 'Demo experiment', 'This is a demo experiment. Feel free to click around. When you are ready, create a new experiment in the dropdown to the left.');"
sqlite3 "$DB_LOC" "INSERT OR IGNORE INTO workers (pioreactor_unit, added_at, is_active) VALUES ('$HOSTNAME', STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW'), 1);"
Expand All @@ -33,9 +33,9 @@ sqlite3 "$DB_LOC" "INSERT OR IGNORE INTO experiment_worker_assignments (pioreact
sudo -u $USERNAME touch $PIO_DIR/config_"$HOSTNAME".ini # set with the correct read/write permissions
printf '# Any settings here are specific to %s, the leader, and override the settings in config.ini\n\n' "$HOSTNAME" >> $PIO_DIR/config_"$HOSTNAME".ini

crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini cluster.topology leader_address 127.0.0.1
crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini mqtt broker_address 127.0.0.1
crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini pioreactor model pioreactor_20ml
crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini pioreactor version 1.1
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini cluster.topology leader_address 127.0.0.1
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini mqtt broker_address 127.0.0.1
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini pioreactor model pioreactor_20ml
sudo -u $USERNAME crudini --ini-options=nospace --set $PIO_DIR/config_"$HOSTNAME".ini pioreactor version 1.1

cp "$PIO_DIR/config_$HOSTNAME.ini" "$PIO_DIR/unit_config.ini"
cp -a "$PIO_DIR/config_$HOSTNAME.ini" "$PIO_DIR/unit_config.ini"

0 comments on commit 5b898cc

Please sign in to comment.