1
1
forked from iarv/meshview

mvrun.py changes

This commit is contained in:
madeofstown
2025-03-09 21:20:55 -07:00
parent 83033a3a64
commit e262c6dff8
3 changed files with 55 additions and 8 deletions

View File

@@ -35,7 +35,7 @@ Copy `sample.config.ini` to `config.ini`:
``` bash
cp sample.config.ini config.ini
```
Edit `config.ini` and change the MQTT server, and Web server settings as necsessary.
Edit `config.ini` and change the MQTT server, and Web server settings.
```bash
nano config.ini
```
@@ -71,12 +71,18 @@ Start the web server.
``` bash
./env/bin/python main.py
```
> [!INFO]
> You can specify the path to your `config.ini` file with the run command argument `--config`
> ``` bash
>./env/bin/python startdb.py --config /path/to/config.ini
>./env/bin/python main.py --config /path/to/config.ini
>```
## Running Meshview with `mvrun.py`
- `mvrun.py` starts `startdb.py` and `main.py` in their own subprocess threads and combines their terminal output.
- `mvrun.py` accepts the `--config` run command.
Now you can hit http://localhost:8081/ ***(if you did not change the web server port )***
You can specify the path to your `config.ini` file with the run command argument `--config`
``` bash
./env/bin/python startdb.py --config /path/to/config.ini
./env/bin/python main.py --config /path/to/config.ini
./env/bin/python mvrun.py
```
Now you can hit http://localhost:8081/ ***(if you did not change the web server port )***

View File

@@ -1,7 +1,7 @@
<!doctype html>
<html lang="en" data-bs-theme="dark">
<head>
<title>MeshView - Bay Area Mesh - http://meshview.bayme.sh {% if node and node.short_name %}-- {{node.short_name}}{% endif %}</title>
<title>Meshview - {{ site_config["site"]["title"] }} {% if node and node.short_name %}-- {{node.short_name}}{% endif %}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/htmx.org@1.9.11" integrity="sha384-0gxUXCCR8yv9FM2b+U3FDbsKthCI66oH5IA9fHppQq9DDMHuMauqq1ZHBpJxQ0J0" crossorigin="anonymous"></script>

41
mvrun.py Normal file
View File

@@ -0,0 +1,41 @@
import argparse
import threading
import subprocess
# Run python in subprocess
def run_script(script_name, *args):
try:
# Path to the Python interpreter inside the virtual environment
python_executable = './env/bin/python'
# Combine the script name and arguments
command = [python_executable, script_name] + list(args)
# Run the subprocess and report errors
subprocess.run(command, check=True)
except Exception as e:
print(f"Error running {script_name}: {e}")
# Parse runtime argument (--config) and start subprocess threads
def main():
parser = argparse.ArgumentParser(description="Helper script to run the datbase and web frontend in separate threads.")
# Add --config runtime argument
parser.add_argument('--config', help="Path to the configuration file.", default='config.ini')
args = parser.parse_args()
# Database Thread
dbthrd = threading.Thread(target=run_script, args=('startdb.py', '--config', args.config))
# Web server thread
webthrd = threading.Thread(target=run_script, args=('main.py', '--config', args.config))
# Start Meshview subprocess threads
dbthrd.start()
webthrd.start()
dbthrd.join()
webthrd.join()
if __name__ == '__main__':
main()