Commit 60930033 authored by Sebastian Böhm's avatar Sebastian Böhm
Browse files

fix argparser

parent 8ca02a05
......@@ -248,16 +248,16 @@ NOTE:
* Install necessary packages: `sudo apt-get install python3-flask python3-venv python3-wheel`
* Clone/Pull this repository: `git clone https://gitlab.rz.uni-bamberg.de/sebastian.boehm/edge-iot-simulator`
* Go into the root directory of the repository, switch then to (`cd edge_iot_simulator`)
* Create the env file `.env` with the contents above and change the values according to your needs
* Create the env file `.env` with the contents above and change the values according to your needs. Alternatively, you can copy the `.env-example` with `cp .env-example .env`. DO NOT FORGET TO ALTER THE SENSITIVE VARIABLES!!!
* Go back to the root directory of the repository: `cd ..`
* Create a virtual environment: `python3 -m venv venv`
* Change to the virtual environment: `source venv/bin/activate`
* Update pip: `pip3 install --upgrade pip`
* Install the necessary dependencies: `pip3 install -r requirements.txt`
* Change the working directory: `cd edge_iot_simulator`
* Run:`python3 main.py`
* Run: `python3 main.py` (all services will start).
NOTE: If you want disable the `TemperatureService` (not burdening your broker with a lot messages), start the application with the following command: `python3 main.py --services cpu_load_svc`.
NOTE: If you want disable the `TemperatureService` (not burdening your broker with a lot messages), start the application with the following command: `python3 main.py --service cpu_load_svc`.
Then, the `TemperatureService` is effectively disabled.
You should see the following output:
......
......@@ -22,12 +22,10 @@ if __name__=="__main__":
parser = argparse.ArgumentParser(description='Edge-IoT Simulator')
parser.add_argument('--services', metavar='S', type=str, nargs='+', default='temperature_svc cpu_load_svc', help='add the services you would like to start')
parser.add_argument('--service', metavar='S', choices=('temperature_svc', 'cpu_load_svc', 'all'), default='all', type=str, nargs='?', help='State the service you would like to start...')
args = parser.parse_args()
services = []
for item in [args.services]:
services += item
print(vars(args)['service'])
publisher_queue = queue.Queue()
consumer_queue = queue.Queue()
......@@ -41,9 +39,9 @@ if __name__=="__main__":
try:
logging.info('Start Edge-IoT Simulator...')
publisher.start()
if "temperature_svc" in services:
if vars(args)['service'] == "temperature_svc" or vars(args)['service'] == "all":
temperature_svc.start()
if "cpu_load_svc" in services:
if vars(args)['service'] == "cpu_load_service" or vars(args)['service'] == "all":
cpu_load_svc.start()
web_app.start()
message_broker.start()
......@@ -57,9 +55,9 @@ if __name__=="__main__":
logging.error("Unknown error occurred: " + str(e))
finally:
publisher.stop()
if "temperature_svc" in services:
if vars(args)['service'] == "temperature_svc" or vars(args)['service'] == "all":
temperature_svc.stop()
if "cpu_load_svc" in services:
if vars(args)['service'] == "cpu_load_service" or vars(args)['service'] == "all":
cpu_load_svc.stop()
web_app.stop()
message_broker.stop()
......@@ -67,9 +65,9 @@ if __name__=="__main__":
logging.info('Wait for graceful termination...')
publisher.join()
if "temperature_svc" in services:
if vars(args)['service'] == "temperature_svc" or vars(args)['service'] == "all":
temperature_svc.join()
if "cpu_load_svc" in services:
if vars(args)['service'] == "cpu_load_service" or vars(args)['service'] == "all":
cpu_load_svc.join()
web_app.join()
message_broker.join()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment