From 986aebafe777fef5c129bccb01d161ab0884973c Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Mon, 16 Jan 2023 11:55:53 +0100 Subject: [PATCH] Feat: upgrade docker entrypoint logic --- Dockerfile | 2 +- README.md | 16 +++++++++------- bin/docker-exec.sh | 3 --- bin/docker-logs.sh | 3 --- docker-compose.yml | 2 ++ entrypoint.sh | 4 ++++ 6 files changed, 16 insertions(+), 14 deletions(-) delete mode 100755 bin/docker-exec.sh delete mode 100755 bin/docker-logs.sh create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 5f4274e..7144b06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,4 +28,4 @@ RUN apt-get update && apt-get upgrade -y \ EXPOSE 9503 -ENTRYPOINT docker-compose-wait && nice -n 20 php server.php -e=.env.docker --docker -s=* \ No newline at end of file +ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index d6eff7f..d905c8c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Fast, simple, async php telegram api server: ### Manual: 1. Requirements: * ssh / cli - * php 7.4 or php 8 + * php 8.1+ * composer * git * Mysql/MariaDB (optional) @@ -50,9 +50,7 @@ Fast, simple, async php telegram api server: 1. Fill app_id and app_hash in `.env.docker` or `.env`. 1. Start TelegramApiServer in cli: * docker: - 1. Start: `docker-compose up` - 1. Start new shell and connect to docker container: `bash bin/docker-exec.sh` - 1. Start another instance with different port inside new shell: `php server.php -p=9500 -s=session --docker -e=.env.docker` + 1. Start container interactively: `docker-compose run --rm telegram-api-server` * manual: 1. `php server.php --session=session` 1. Authorize your session: @@ -92,7 +90,7 @@ Fast, simple, async php telegram api server: 1. Access Telegram API with simple GET/POST requests. Regular and application/json POST supported. - Its recommended to use http_build_query, when using GET requests. + It's recommended to use http_build_query, when using GET requests. **Rules:** * All methods from MadelineProto supported: [Methods List](https://docs.madelineproto.xyz/API_docs/methods/) @@ -229,6 +227,9 @@ curl --location --request POST '127.0.0.1:9503/api/downloadToResponse' \ Also see: https://docs.madelineproto.xyz/docs/FILES.html#downloading-files ### Multiple sessions support +**WARNING: running multiple sessions in one instance is unstable.** +Crash/error in one session will crash all of them. +Correct way: override docker-compose.yml and add containers with different ports and session names for each session. When running multiple sessions, need to define which session to use for request. Each session stored in `sessions/{$session}.madeline`. Nested folders supported. @@ -273,7 +274,7 @@ Each session stored in `sessions/{$session}.madeline`. Nested folders supported. These settings will be saved into json file and will apply after the restart. ### Session management - + **Examples:** * Session list: `http://127.0.0.1:9503/system/getSessionList` * Adding session: `http://127.0.0.1:9503/system/addSession?session=users/xtrime` @@ -285,7 +286,8 @@ Each session stored in `sessions/{$session}.madeline`. Nested folders supported. Full list of system methods available in [SystemApiExtensions class](https://github.com/xtrime-ru/TelegramApiServer/blob/master/src/MadelineProtoExtensions/SystemApiExtensions.php) -### Authorizing session remotely +### Authorizing session remotely +WARNING: it is recomended to use interactive mode to authorize sessions! If there is no authorization in session, or session file is blank, authorization required: User: diff --git a/bin/docker-exec.sh b/bin/docker-exec.sh deleted file mode 100755 index 94360ff..0000000 --- a/bin/docker-exec.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker exec -it telegram-api-server /bin/bash \ No newline at end of file diff --git a/bin/docker-logs.sh b/bin/docker-logs.sh deleted file mode 100755 index af897f8..0000000 --- a/bin/docker-logs.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -docker logs telegram-api-server --follow \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7de4d5a..4deb0aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,8 @@ services: options: max-size: "1024k" max-file: "2" + command: + - "-s=session" mysql: image: mariadb:10.8 container_name: telegram-api-server-mysql diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..60fc295 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +docker-compose-wait \ +&& nice -n 20 php server.php -e=.env.docker --docker "$@" \ No newline at end of file