GithubHelp home page GithubHelp logo

govee_kafka_producer's Introduction

Govee Kafka Producer

Lee archivos generados por GoveeBTTempLogger y los manda a un servidor de kafka. Principalmente diseñado para realizar pruebas de carga en un servidor Kafka en una Raspberry pi 4.

Setup:

  1. Set ENV variable

      sudo nano /etc/environment
    
      GOVEE_KAFKA_PRODUCER_ENV=production
    
  2. Set Up a Virtual Environment on the Raspberry Pi:

    cd /home/pi/projects/govee_kafka_producer/
    
    python3 -m venv venv
    
  3. Activate the Virtual Environment:

    source venv/bin/activate
    
  4. Install Dependencies:

    pip install -r requirements.txt
    
  5. Running Application:

    /home/pi/projects/govee_kafka_producer/venv/bin/python /home/pi/projects/govee_kafka_producer/main.py
    

Running as a Service

Creating a systemd service one of the most robust and common ways to ensure a Python script runs at boot and restarts on failure.

Creating a systemd Service Unit File

  1. Create a Unit File:

    Create a unit file for the service:

    sudo nano /etc/systemd/system/govee_kafka_producer.service
  2. Define the Service:

    Add the following configuration to the file. Adjust paths according to the Python script and virtual environment:

    [Unit]
    Description=Govee Kafka Producer Service
    After=network.target
    
    [Service]
    Environment="GOVEE_KAFKA_PRODUCER_ENV=production"
    User=pi
    WorkingDirectory=/home/pi/path/to/your/script
    ExecStart=/home/pi/path/to/your/venv/bin/python path/to/your/script/main.py kafka
    Restart=always
    RestartSec=30
    
    [Install]
    WantedBy=multi-user.target
    
    • Description is a meaningful description of your service.
    • After=network.target ensures the network is available before starting your service.
    • User is the user under which the script should run.
    • WorkingDirectory where the Python script is located.
    • ExecStart full path to the Python executable in the virtual environment and the path to the script.
    • Restart=always restart the service if it fails.
    • RestartSec=30 restart after 30 seconds if it fails.
  3. Enable and Start the Service:

    • Reload systemd to read the new unit file:

      sudo systemctl daemon-reload
      
    • Enable the service to start on boot:

      sudo systemctl enable govee_kafka_producer.service
      
    • Start the service immediately:

      sudo systemctl start govee_kafka_producer.service
      
  4. Additional Commands:

    • Check status, to verify the service is running correctly:

      sudo systemctl status govee_kafka_producer.service
      
    • Stop the service immediately:

      sudo systemctl stop govee_kafka_producer.service
      
    • Restart: Stop and immediately start the service again:

      sudo systemctl restart  govee_kafka_producer.service
      
    • Disable: Prevent the service from starting automatically at boot, use:

      sudo systemctl disable  govee_kafka_producer.service
      
  5. Viewing Logs

    To troubleshoot or check the output of the script:

    journalctl -u govee_kafka_producer.service

    Use the -e option, which takes you to the end of the journal:

    journalctl -u govee_kafka_producer.service -e

Running as Cron @reboot Job

Use cron's @reboot feature to run scripts at startup. This method is simpler than creating a systemd service but lacks some of the advanced management features like automatic restarts on failure.

How to Set Up:

  1. Open the crontab file for editing: crontab -e.
  2. Add a line for your script using the @reboot directive: @reboot /path/to/your/env/bin/python /path/to/your/script.py.
  3. Save and close the editor.

govee_kafka_producer's People

Contributors

camilofernandez73 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.