kopia lustrzana https://github.com/mate-dev/mmrelaynode
commit
4552b1738b
22
README.md
22
README.md
|
@ -20,17 +20,25 @@ docker compose -f "docker-compose.yaml" up -d --build
|
|||
docker compose restart
|
||||
```
|
||||
|
||||
If modifying the scripts, use these commands to rebuild the containers from scratch:
|
||||
*Note: It is important to restart the containers after the first run so the virtual Meshtastic node can be rebooted after the `MESHTATIC_COMMAND_X:` commands that are definied in your `docker-compose.yaml` are issued.*
|
||||
|
||||
```
|
||||
docker compose down --volumes
|
||||
docker compose build --no-cache
|
||||
docker compose up -d --force-recreate
|
||||
```
|
||||
|
||||
Use the following command to see the output of command_wrapper.py & the MESHTASTIC_COMMAND_X commands:
|
||||
```
|
||||
docker exec -it mmrelaynode-app cat /home/mesh/app/command_output.txt
|
||||
```
|
||||
|
||||
Note: If you have several commands, it may take a few minutes to finish them all.
|
||||
The commands will only be executed the first time the container is started. To re-run the commands, delete the file flag file and restart the container.
|
||||
|
||||
To delete the flag file:
|
||||
```
|
||||
docker exec -it mmrelaynode-app rm /home/mesh/app/.commands_executed
|
||||
```
|
||||
|
||||
If modifying the scripts, use these commands to rebuild the containers from scratch:
|
||||
|
||||
```
|
||||
docker compose down --volumes
|
||||
docker compose build --no-cache
|
||||
docker compose up -d --force-recreate
|
||||
```
|
|
@ -2,8 +2,15 @@ import os
|
|||
import subprocess
|
||||
import time
|
||||
|
||||
output_file = '/home/mesh/app/command_output.txt'
|
||||
flag_file = '/home/mesh/app/.commands_executed'
|
||||
|
||||
# Remove the output file if it exists
|
||||
if os.path.exists(output_file):
|
||||
os.remove(output_file)
|
||||
|
||||
def log_to_file(message):
|
||||
with open('/home/mesh/app/command_output.txt', 'a') as f:
|
||||
with open(output_file, 'a') as f:
|
||||
f.write(message + "\n")
|
||||
|
||||
def execute_meshtastic_command(options):
|
||||
|
@ -15,17 +22,23 @@ def execute_meshtastic_command(options):
|
|||
log_to_file("Standard Error:\n" + result.stderr)
|
||||
time.sleep(1) # Pause for 1 second between commands
|
||||
|
||||
# Print all environment variables at the start
|
||||
log_to_file("All environment variables:\n" + str(os.environ))
|
||||
if os.path.exists(flag_file):
|
||||
log_to_file("Commands have already been executed previously. Skipping.")
|
||||
else:
|
||||
# Print all environment variables at the start
|
||||
log_to_file("All environment variables:\n" + str(os.environ))
|
||||
|
||||
# Loop through environment variables in sequence
|
||||
index = 1
|
||||
while True:
|
||||
command = os.environ.get(f'MESHTASTIC_COMMAND_{index}')
|
||||
if command:
|
||||
log_to_file(f"Found command variable: MESHTASTIC_COMMAND_{index} with value: {command}")
|
||||
execute_meshtastic_command(command)
|
||||
index += 1
|
||||
else:
|
||||
log_to_file(f"No more MESHTASTIC_COMMAND variables found, ending at index {index-1}.")
|
||||
break
|
||||
# Loop through environment variables in sequence
|
||||
index = 1
|
||||
while True:
|
||||
command = os.environ.get(f'MESHTASTIC_COMMAND_{index}')
|
||||
if command:
|
||||
log_to_file(f"Found command variable: MESHTASTIC_COMMAND_{index} with value: {command}")
|
||||
execute_meshtastic_command(command)
|
||||
index += 1
|
||||
else:
|
||||
log_to_file(f"No more MESHTASTIC_COMMAND variables found, ending at index {index-1}.")
|
||||
# Create the flag file to indicate that all commands have been executed.
|
||||
with open(flag_file, 'w') as f:
|
||||
f.write("Commands executed on: " + time.ctime())
|
||||
break
|
Ładowanie…
Reference in New Issue