Compare commits

..

No commits in common. "7cc249aac69b7124c51e4bf6ff8cd5443e04b67b" and "9bfd299f68bc60d3ed29b9613632822a05de4d22" have entirely different histories.

9 changed files with 59 additions and 92 deletions

5
.gitignore vendored
View File

@ -1,7 +1,4 @@
config.ini ./config.ini
!install/config.ini
docker-compose.yml
compose.yml
*.pot *.pot
*.mo *.mo
dist dist

View File

@ -11,7 +11,7 @@ HDRS = $(wildcard include/*.h)
CFLAGS = -O3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection CFLAGS = -O3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection
LIBS = -linih -lmp LIBS = -linih -lmp
VERSION = 24.03 VERSION = 24.00
all: dist dist/pooler $(PO_OUTS) all: dist dist/pooler $(PO_OUTS)
@ -43,8 +43,8 @@ locale/pooler.pot: $(SRCS)
install: install:
install -d -m700 $(DESTDIR)/etc/pooler install -d -m700 $(DESTDIR)/etc/pooler
install -Dm755 dist/pooler $(DESTDIR)/$(PREFIX)/bin/pooler install -m755 dist/pooler $(DESTDIR)/$(PREFIX)/bin/pooler
install -Dm600 install/config.ini $(DESTDIR)/etc/pooler/config.ini install -m600 install/config.ini $(DESTDIR)/etc/pooler/config.ini
@for po in $(PO_DIRS) ; do \ @for po in $(PO_DIRS) ; do \
echo "installing locale: $$po/pooler.mo" ; \ echo "installing locale: $$po/pooler.mo" ; \
mkdir -pv $(DESTDIR)/$(PREFIX)/share/$$po ; \ mkdir -pv $(DESTDIR)/$(PREFIX)/share/$$po ; \

View File

@ -34,22 +34,8 @@ You can also build the program using docker:
docker build --tag pooler . docker build --tag pooler .
``` ```
And for deployment you can use docker-compose, here is an example configuration: And for deployment you can use docker-compose, just make sure you read the compose file
```yaml and place the configuration file and the pools to the right place:
version: "3"
services:
pooler:
image: pooler
build:
context: ./
ports:
- "5858:5858/tcp"
volumes:
- "./config.ini:/etc/pooler/config.ini"
```
Just make sure you read the compose file and place the configuration file and the pools
to the right place:
```bash ```bash
docker-compose up -d docker-compose up -d
``` ```

10
docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
version: "3"
services:
pooler:
build:
context: ./
ports:
- "5858:5858/udp"
volumes:
- "./config.ini:/etc/pooler/config.ini"

View File

@ -4,7 +4,6 @@
addr = 0.0.0.0:5858 addr = 0.0.0.0:5858
threads = 10 threads = 10
# [pool-config] # [pool-name]
# name = pool-name
# host = pool.example.com # host = pool.example.com
# dir = /srv/pools/pool-name # dir = /srv/pools/pool-name

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-08-25 14:08+0300\n" "POT-Creation-Date: 2024-08-07 01:48+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,27 +17,27 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n" "Content-Transfer-Encoding: 8bit\n"
#: src/config.c:135 #: src/config.c:125
#, c-format #, c-format
msgid "Unknown configuration option: %s" msgid "Unknown configuration option: %s"
msgstr "" msgstr ""
#: src/config.c:137 #: src/config.c:127
#, c-format #, c-format
msgid "Unknown configuration option: %s/%s" msgid "Unknown configuration option: %s/%s"
msgstr "" msgstr ""
#: src/config.c:145 #: src/config.c:135
#, fuzzy, c-format #, fuzzy, c-format
msgid "Failed to access the configuration file: %s" msgid "Failed to access the configuration file: %s"
msgstr "Kayıt dosyasını açmak başarısız oldu: %s" msgstr "Kayıt dosyasını açmak başarısız oldu: %s"
#: src/config.c:150 #: src/config.c:140
#, fuzzy #, fuzzy
msgid "Failed to parse the configuration" msgid "Failed to parse the configuration"
msgstr "Kayıt dosyasını açmak başarısız oldu: %s" msgstr "Kayıt dosyasını açmak başarısız oldu: %s"
#: src/config.c:160 #: src/config.c:147
#, fuzzy, c-format #, fuzzy, c-format
msgid "Hostname not specified for the pool: %s" msgid "Hostname not specified for the pool: %s"
msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s" msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s"
@ -82,77 +82,77 @@ msgstr ""
msgid "Request from %s: PULL (%s)" msgid "Request from %s: PULL (%s)"
msgstr "" msgstr ""
#. disable buffering so docker-compose logs works correctly #: src/main.c:109
#: src/main.c:110
#, fuzzy, c-format #, fuzzy, c-format
msgid "Starting pooler %s (libmp %s)" msgid "Starting pooler %s (libmp %s)"
msgstr "%lu tane havuz %s adresinde sunuluyor" msgstr "%lu tane havuz %s adresinde sunuluyor"
#: src/main.c:113 #: src/main.c:112
msgid "Configuration file not specified" msgid "Configuration file not specified"
msgstr "Konfigürasyon dosyası belirtilmedi" msgstr "Konfigürasyon dosyası belirtilmedi"
#: src/main.c:126 #: src/main.c:125
msgid "Loaded the configuration" msgid "Loaded the configuration"
msgstr "" msgstr ""
#: src/main.c:129 #: src/main.c:128
#, fuzzy #, fuzzy
msgid "Failed to get the temp directory configuration option (tmpdir)" msgid "Failed to get the temp directory configuration option (tmpdir)"
msgstr "Kayıt dosyasını açmak başarısız oldu: %s" msgstr "Kayıt dosyasını açmak başarısız oldu: %s"
#: src/main.c:137 #: src/main.c:136
msgid "Please specify a valid thread count (1-1000)" msgid "Please specify a valid thread count (1-1000)"
msgstr "Lütfen geçerli bir işlem sayısı belirtin (1-1000)" msgstr "Lütfen geçerli bir işlem sayısı belirtin (1-1000)"
#: src/main.c:142 #: src/main.c:141
msgid "Please specify at least one pool in the configuration" msgid "Please specify at least one pool in the configuration"
msgstr "Lütfen konfigürasyonda en az bir havuz belirtin" msgstr "Lütfen konfigürasyonda en az bir havuz belirtin"
#: src/main.c:148 #: src/main.c:146
#, fuzzy, c-format
msgid "%s: loading the pool"
msgstr "%s: havuz bilgisi başarıyla yüklendi"
#: src/main.c:149
#, fuzzy, c-format #, fuzzy, c-format
msgid "%s: hostname not specified for pool, skipping" msgid "%s: hostname not specified for pool, skipping"
msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s" msgstr "Ana makine adı havuz konfigürasyonunda belirtilmedi, geçiliyor: %s"
#: src/main.c:162 #: src/main.c:157
#, fuzzy, c-format #, fuzzy, c-format
msgid "%s: failed access the pool directory (%s)" msgid "%s: failed access the pool directory (%s)"
msgstr "Havuz dizinine erişilemiyor: %s" msgstr "Havuz dizinine erişilemiyor: %s"
#: src/main.c:167 #: src/main.c:162
#, fuzzy, c-format #, fuzzy, c-format
msgid "%s: failed to add pool to the list (%s)" msgid "%s: failed to add pool to the list (%s)"
msgstr "Havuzu listeye eklemek başarısız oldu: %s" msgstr "Havuzu listeye eklemek başarısız oldu: %s"
#: src/main.c:175 #: src/main.c:170
#, fuzzy #, c-format
msgid "Failed to sync the pools, please see the errors above" msgid "Failed to sync the pools: %s"
msgstr "Havuzları sekronize etmek başarısız oldu: %s" msgstr "Havuzları sekronize etmek başarısız oldu: %s"
#: src/main.c:180 #: src/main.c:175
#, fuzzy #, fuzzy
msgid "None of the pools is available for serving" msgid "None of the pools is available for serving"
msgstr "Havuzların hiçbiri sunmak için müsait değil" msgstr "Havuzların hiçbiri sunmak için müsait değil"
#: src/main.c:184 #: src/main.c:179
#, c-format #, c-format
msgid "Serving %lu pool on %s" msgid "Serving %lu pool on %s"
msgstr "%lu tane havuz %s adresinde sunuluyor" msgstr "%lu tane havuz %s adresinde sunuluyor"
#: src/main.c:184 #: src/main.c:179
#, c-format #, c-format
msgid "Serving %lu pools on %s" msgid "Serving %lu pools on %s"
msgstr "%lu tane havuz %s adresinde sunuluyor" msgstr "%lu tane havuz %s adresinde sunuluyor"
#: src/main.c:187 #: src/main.c:182
#, c-format #, c-format
msgid "Failed to start the server: %s" msgid "Failed to start the server: %s"
msgstr "Sunucuyu başlatmak başarısız oldu: %s" msgstr "Sunucuyu başlatmak başarısız oldu: %s"
#, fuzzy, c-format
#~ msgid "%s: loading the pool"
#~ msgstr "%s: havuz bilgisi başarıyla yüklendi"
#, fuzzy, c-format #, fuzzy, c-format
#~ msgid "%s: loaded the pool" #~ msgid "%s: loaded the pool"
#~ msgstr "%s: havuz bilgisi başarıyla yüklendi" #~ msgstr "%s: havuz bilgisi başarıyla yüklendi"

View File

@ -21,21 +21,21 @@ config_t config = {
.pools = NULL, .pools = NULL,
}; };
pool_config_t *config_pool_add(char *section) { pool_config_t *config_pool_add(char *name) {
pool_config_t *pool = malloc(sizeof(pool_config_t)); pool_config_t *pool = malloc(sizeof(pool_config_t));
bzero(pool, sizeof(pool_config_t)); bzero(pool, sizeof(pool_config_t));
pool->section = strdup(section); pool->name = strdup(name);
pool->next = config.pools; pool->next = config.pools;
config.pools = pool; config.pools = pool;
return pool; return pool;
} }
bool config_pool_contains(char *section) { bool config_pool_contains(char *name) {
pool_config_t *cur = config.pools; pool_config_t *cur = config.pools;
while (NULL != cur) { while (NULL != cur) {
if (eq(cur->section, section)) if (eq(cur->name, name))
return true; return true;
cur = cur->next; cur = cur->next;
} }
@ -105,21 +105,11 @@ int config_load_handler(void *data, const char *_section, const char *_key, cons
if (!config_pool_contains(section)) if (!config_pool_contains(section))
config_pool_add(section); config_pool_add(section);
if (eq(key, "name")) { if (eq(key, "host")) {
free(config.pools->name);
config.pools->name = strdup(value);
}
else if (eq(key, "host")) {
free(config.pools->host); free(config.pools->host);
config.pools->host = strdup(value); config.pools->host = strdup(value);
} }
else if (eq(key, "path")) {
free(config.pools->path);
config.pools->path = strdup(value);
}
else if (eq(key, "dir")) { else if (eq(key, "dir")) {
free(config.pools->dir); free(config.pools->dir);
config.pools->dir = strdup(value); config.pools->dir = strdup(value);
@ -153,14 +143,10 @@ bool config_load(char *file) {
pool_config_t *pool = config.pools; pool_config_t *pool = config.pools;
while (NULL != pool) { while (NULL != pool) {
if (NULL == pool->name)
pool->name = pool->section;
if (NULL == pool->host) { if (NULL == pool->host) {
error(_("Hostname not specified for the pool: %s"), pool->name); error(_("Hostname not specified for the pool: %s"), pool->name);
return false; return false;
} }
pool = pool->next; pool = pool->next;
} }
@ -176,12 +162,8 @@ void config_free() {
old = cur; old = cur;
cur = cur->next; cur = cur->next;
free(old->section);
if (old->section != old->name)
free(old->name);
free(old->host); free(old->host);
free(old->path); free(old->name);
free(old->dir);
free(old); free(old);
} }
} }

View File

@ -21,10 +21,8 @@ typedef struct config_option {
typedef struct pool_config { typedef struct pool_config {
struct pool_config *next; struct pool_config *next;
char *section;
char *name; char *name;
char *host; char *host;
char *path;
char *dir; char *dir;
} pool_config_t; } pool_config_t;

View File

@ -106,7 +106,6 @@ bool serve_callback(lm_pool_t *pool, lm_mptp_t *packet, struct sockaddr *addr, v
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
setbuf(stdout, NULL); // disable buffering so docker-compose logs works correctly
info(_("Starting pooler %s (libmp %s)"), VERSION, LM_VERSION); info(_("Starting pooler %s (libmp %s)"), VERSION, LM_VERSION);
if (argc != 2) { if (argc != 2) {
@ -117,7 +116,7 @@ int main(int argc, char *argv[]) {
char *addr = NULL, *logfile = NULL, *tmpdir = NULL; char *addr = NULL, *logfile = NULL, *tmpdir = NULL;
int ret = EXIT_FAILURE; int ret = EXIT_FAILURE;
pool_config_t *pool = NULL; pool_config_t *pool = NULL;
ssize_t pool_count = 0; size_t pool_count = 0;
lm_ctx_t ctx; lm_ctx_t ctx;
if (!config_load(argv[1])) if (!config_load(argv[1]))
@ -144,19 +143,15 @@ int main(int argc, char *argv[]) {
} }
while (NULL != pool) { while (NULL != pool) {
info(_("%s: loading the pool"), pool->name);
if (NULL == pool->host) { if (NULL == pool->host) {
error(_("%s: hostname not specified for pool, skipping"), pool->name); error(_("%s: hostname not specified for pool, skipping"), pool->name);
goto end_ctx; goto end_ctx;
} }
char url[strlen(pool->host) + 20 + (pool->path == NULL ? 0 : strlen(pool->path))]; char url[strlen(pool->host) + 20];
sprintf(url, "mptp://%s", pool->host);
if (NULL == pool->path)
sprintf(url, "mptp://%s/", pool->host);
else if (pool->path[0] == '/')
sprintf(url, "mptp://%s%s", pool->host, pool->path);
else
sprintf(url, "mptp://%s/%s", pool->host, pool->path);
if (!file_canread(pool->dir)) { if (!file_canread(pool->dir)) {
error(_("%s: failed access the pool directory (%s)"), pool->name, pool->dir); error(_("%s: failed access the pool directory (%s)"), pool->name, pool->dir);
@ -172,7 +167,7 @@ int main(int argc, char *argv[]) {
} }
if ((pool_count = lm_ctx_sync(&ctx, false, sync_callback, NULL)) < 0) { if ((pool_count = lm_ctx_sync(&ctx, false, sync_callback, NULL)) < 0) {
error(_("Failed to sync the pools, please see the errors above")); error(_("Failed to sync the pools: %s"), lm_strerror());
goto end_ctx; goto end_ctx;
} }
@ -183,7 +178,7 @@ int main(int argc, char *argv[]) {
info(pool_count == 1 ? _("Serving %lu pool on %s") : _("Serving %lu pools on %s"), pool_count, addr); info(pool_count == 1 ? _("Serving %lu pool on %s") : _("Serving %lu pools on %s"), pool_count, addr);
if (!lm_ctx_serve(&ctx, addr, config_get_integer("threads"), NULL, serve_callback, NULL)) { if (!lm_ctx_serve(&ctx, addr, config_get_integer("threads"), serve_callback, NULL)) {
error(_("Failed to start the server: %s"), lm_strerror()); error(_("Failed to start the server: %s"), lm_strerror());
goto end_ctx; goto end_ctx;
} }