Skip to content

Commit 1c850df

Browse files
committed
1 parent 07975ab commit 1c850df

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ RUN apk update && \
1111
musl-dev && \
1212
python -m venv /venv
1313

14+
SHELL ["/bin/bash", "-c"]
15+
1416
ENV PATH="/venv/bin:$PATH"
1517

1618
WORKDIR /tmp
@@ -38,6 +40,8 @@ RUN apk update && \
3840
ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime && \
3941
mkdir /app
4042

43+
SHELL ["/bin/bash", "-c"]
44+
4145
ENV PATH="/venv/bin:$PATH"
4246
ENV TZ=Europe/Paris
4347

@@ -52,4 +56,4 @@ RUN git clone -b v7 --single-branch https://github.com/EDM115/unzip-bot.git /app
5256

5357
COPY .env /app/.env
5458

55-
CMD ["/bin/bash", "start.sh"]
59+
ENTRYPOINT ["/bin/bash", "/app/start.sh"]

start.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ else
1313
source .env
1414
fi
1515
export TZ="Europe/Paris"
16-
python3 -m unzipbot
16+
exec python -m unzipbot

unzipbot/__main__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2022 - 2024 EDM115
2+
import asyncio
23
import os
34
import signal
45
import time
@@ -31,17 +32,16 @@ def handler_stop_signals(signum, frame):
3132
signal.signal(signal.SIGINT, handler_stop_signals)
3233
signal.signal(signal.SIGTERM, handler_stop_signals)
3334

34-
35-
def shutdown_bot():
35+
async def async_shutdown_bot():
3636
stoptime = time.strftime("%Y/%m/%d - %H:%M:%S")
3737
LOGGER.info(Messages.STOP_TXT.format(stoptime))
3838
try:
39-
unzipbot_client.send_message(
39+
await unzipbot_client.send_message(
4040
chat_id=Config.LOGS_CHANNEL, text=Messages.STOP_TXT.format(stoptime)
4141
)
4242
with open("unzip-bot.log", "rb") as doc_f:
4343
try:
44-
unzipbot_client.send_document(
44+
await unzipbot_client.send_document(
4545
chat_id=Config.LOGS_CHANNEL,
4646
document=doc_f,
4747
file_name=doc_f.name,
@@ -52,7 +52,11 @@ def shutdown_bot():
5252
LOGGER.error("Error sending shutdown message : %s", e)
5353
finally:
5454
LOGGER.info("Bot stopped 😪")
55-
unzipbot_client.stop(block=False)
55+
await unzipbot_client.stop(block=False)
56+
57+
58+
def shutdown_bot():
59+
asyncio.get_event_loop().run_until_complete(async_shutdown_bot())
5660

5761

5862
if __name__ == "__main__":

0 commit comments

Comments
 (0)