Skip to content

Commit

Permalink
Change base docker image (#3)
Browse files Browse the repository at this point in the history
* Change base docker image
* Rename variables and add logging
* Add missing docker image to docker run example

---------

Co-authored-by: Aitor Iturrioz <[email protected]>
  • Loading branch information
aitorcas23 and bodiroga authored Mar 16, 2024
1 parent e1a074e commit 7dde5ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9.2-slim
FROM python:3.9-slim-bullseye
WORKDIR /app
COPY requirements.txt ./
RUN apt-get update && apt-get install build-essential -y
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For example:

After building the image, execute it with docker run.

`docker run --name ${CONTAINER_NAME} --privileged --rm -d -v /run/systemd/system:/run/systemd/system -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket -v /bin/systemctl:/bin/systemctl -p 5558:5558 -e LOG_LEVEL=DEBUG`
`docker run --name ${CONTAINER_NAME} --privileged --rm -d -v /run/systemd/system:/run/systemd/system -v /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket -v /bin/systemctl:/bin/systemctl -p 5558:5558 -e LOG_LEVEL=DEBUG iombian-shutdown-service:latest`

- **--name** is used to define the name of the created container.

Expand Down
7 changes: 4 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from shutdown_commands import ShutdownCommands

LOG_LEVEL = os.environ.get("LOG_LEVEL", logging.INFO)
SHUTDOWN_EVENTS_HOST = "0.0.0.0"
SHUTDOWN_EVENTS_PORT = int(os.environ.get("SHUTDOWN_EVENTS_PORT", 5558))
SHUTDOWN_SERVICE_PORT = int(os.environ.get("SHUTDOWN_PORT", 5558))

SHUTDOWN_SERVICE_HOST = "0.0.0.0"

logging.basicConfig(format="%(asctime)s %(levelname)-8s - %(name)-16s - %(message)s", level=LOG_LEVEL)
logger = logging.getLogger(__name__)
Expand All @@ -29,7 +30,7 @@ def signal_handler(sig, frame):

shutdown_commands = ShutdownCommands()

server = CommunicationServer(shutdown_commands, host=SHUTDOWN_EVENTS_HOST, port=SHUTDOWN_EVENTS_PORT)
server = CommunicationServer(shutdown_commands, host=SHUTDOWN_SERVICE_HOST, port=SHUTDOWN_SERVICE_PORT)
server.start()

signal.signal(signal.SIGINT, signal_handler)
Expand Down
4 changes: 4 additions & 0 deletions src/shutdown_commands.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import logging
import os

logger = logging.getLogger(__name__)

class ShutdownCommands:
def __init__(self):
pass

def shutdown(self):
logging.debug("Shutting down the device.")
os.system("systemctl poweroff")

def reboot(self):
logging.debug("Rebooting the device.")
os.system("systemctl reboot")

0 comments on commit 7dde5ee

Please sign in to comment.