Coder Social home page Coder Social logo

Need a instruction how to start the script with a newstart of the raspberry pi and after an com. failure of the script. about bmspace HOT 3 CLOSED

torstenjaeckel avatar torstenjaeckel commented on August 23, 2024
Need a instruction how to start the script with a newstart of the raspberry pi and after an com. failure of the script.

from bmspace.

Comments (3)

Tertiush avatar Tertiush commented on August 23, 2024 1

Glad you got it working. Back in the day I ran my scripts as system services using systemd. It also would restart the script if ever failed.

from bmspace.

jpmeijers avatar jpmeijers commented on August 23, 2024

To address the second part of this issue I am running bms.py in screen, in a while-true loop. This restarts the script whenever the mqtt server disappears, which makes the script crash.

~/bmspace $ while true; do python bms.py; sleep 10; done;

I believe the correct way to start and restart the script would be via systemd, but otherwise a docker container (docker compose script) with the restart unless stopped flag should work too.

from bmspace.

jpmeijers avatar jpmeijers commented on August 23, 2024

I changed my script to run in Docker.

Installed Docker on RaspberryPi

https://docs.docker.com/engine/install/debian/#install-using-the-convenience-script

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

https://docs.docker.com/engine/install/linux-postinstall/
sudo usermod -aG docker ${USER}
log out, log in
docker run hello-world
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

https://docs.docker.com/config/containers/logging/json-file/

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

sudo reboot

Build image and run container

docker compose build
docker compose up -d

Dockerfile

FROM python:3.9-alpine

ENV WORK_DIR=workdir \
  HASSIO_DATA_PATH=/data

RUN mkdir -p ${WORK_DIR}
WORKDIR /${WORK_DIR}
COPY requirements.txt .

# install python libraries
RUN pip3 install -r requirements.txt

# Copy code
COPY bms.py constants.py run.sh ./
RUN chmod a+x run.sh

CMD [ "sh", "./run.sh" ]

docker-compose.yaml

version: '3'
services:
  bmspace:
    build:
      context: .
    restart: unless-stopped
    privileged: true
    volumes:
      - ./config.yaml:/workdir/config.yaml
      - /dev:/dev

from bmspace.

Related Issues (20)

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.