From c08ddb8dc8820c33dbe860c49cbab0f8bd888777 Mon Sep 17 00:00:00 2001 From: Leaflet Date: Thu, 8 Jan 2026 22:22:13 +0800 Subject: [PATCH 1/4] Refine handling of cmdline arguments --- src/main.c | 65 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/src/main.c b/src/main.c index 60ef24c..5972d94 100644 --- a/src/main.c +++ b/src/main.c @@ -72,9 +72,9 @@ static void arg_foreground(void) daemon_service = 0; } -static void arg_help(void) +static void arg_usage(void) { - fprintf(stderr, "Usage: bbsd [-fhv] [...]\n\n"); + fprintf(stderr, "Usage: bbsd [-fhvC] [...]\n\n"); for (int i = 0; i < arg_options_count; i++) { @@ -89,10 +89,19 @@ static void arg_help(void) fprintf(stderr, "\n If meet any bug, please report to \n\n"); } +static void arg_help(void) +{ + arg_usage(); + + exit(0); +} + static void arg_version(void) { - printf("%s\n", APP_INFO); - printf("%s\n", COPYRIGHT_INFO); + fprintf(stderr, "%s\n", APP_INFO); + fprintf(stderr, "%s\n", COPYRIGHT_INFO); + + exit(0); } static void arg_display_log(void) @@ -107,51 +116,55 @@ static void arg_display_error_log(void) static void arg_compile_info(void) { - printf("%s\n" - "--enable-shared\t\t[%s]\n" - "--enable-systemd\t[%s]\n" - "--with-debug\t\t[%s]\n" - "--with-epoll\t\t[%s]\n" - "--with-mariadb\t\t[%s]\n" - "--with-sysv\t\t[%s]\n", - APP_INFO, + fprintf(stderr, "%s\n" + "--enable-shared\t\t[%s]\n" + "--enable-systemd\t[%s]\n" + "--with-debug\t\t[%s]\n" + "--with-epoll\t\t[%s]\n" + "--with-mariadb\t\t[%s]\n" + "--with-sysv\t\t[%s]\n", + APP_INFO, #ifdef _ENABLE_SHARED - "yes", + "yes", #else - "no", + "no", #endif #ifdef HAVE_SYSTEMD_SD_DAEMON_H - "yes", + "yes", #else - "no", + "no", #endif #ifdef _DEBUG - "yes", + "yes", #else - "no", + "no", #endif #ifdef HAVE_SYS_EPOLL_H - "yes", + "yes", #else - "no", + "no", #endif #ifdef HAVE_MARIADB_CLIENT - "yes", + "yes", #else - "no", + "no", #endif #ifdef HAVE_SYSTEM_V - "yes" + "yes" #else - "no" + "no" #endif ); + + exit(0); } static void arg_error(void) { fprintf(stderr, "Invalid arguments\n"); - arg_help(); + arg_usage(); + + exit(1); } int main(int argc, char *argv[]) @@ -216,6 +229,8 @@ int main(int argc, char *argv[]) return -1; } + fprintf(stderr, "%s\n", APP_INFO); + // Initialize log if (log_begin(LOG_FILE_INFO, LOG_FILE_ERROR) < 0) { From f249b77610adfb7ce4037ff4fc2e289b828c5c18 Mon Sep 17 00:00:00 2001 From: Leaflet Date: Fri, 9 Jan 2026 18:17:36 +0800 Subject: [PATCH 2/4] Display building arch in version info --- src/common.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index 8b6f386..75ac03c 100644 --- a/src/common.c +++ b/src/common.c @@ -13,7 +13,16 @@ #include "common.h" // Version -const char APP_INFO[] = PACKAGE_STRING " build on " __DATE__ " " __TIME__; +#ifdef __x86_64__ +const char APP_INFO[] = PACKAGE_STRING " build (x86_64) on " __DATE__ " " __TIME__; +#else +#ifdef __aarch64__ +const char APP_INFO[] = PACKAGE_STRING " build (aarch64) on " __DATE__ " " __TIME__; +#else +const char APP_INFO[] = PACKAGE_STRING " build (i386) on " __DATE__ " " __TIME__; +#endif +#endif + const char COPYRIGHT_INFO[] = "Copyright (C) 2004-2026 Leaflet \n" "This program comes with ABSOLUTELY NO WARRANTY.\n" "This is free software, and you are welcome to redistribute it \n" From 73daac4189a231fcd335a9e581931be7dfee5d28 Mon Sep 17 00:00:00 2001 From: Leaflet Date: Sat, 10 Jan 2026 11:40:29 +0800 Subject: [PATCH 3/4] Add multi-platform image build and publish --- .github/workflows/docker-image.yml | 20 +++++++++++++++++++- .github/workflows/docker-publish.yml | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 4b4a75e..6510d9d 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,6 +6,10 @@ on: pull_request: branches: [ "main" ] +env: + DOCKERHUB_PLATFORMS: linux/amd64,linux/arm64 + BBSD_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/lbbs-bbsd + jobs: build: @@ -15,5 +19,19 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build the Docker image - run: docker compose build + id: build-bbsd + uses: docker/build-push-action@v5 + with: + platforms: ${{ env.DOCKERHUB_PLATFORMS }} + context: . + file: Dockerfile/dockerfile.bbsd + tags: | + ${{ env.BBSD_IMAGE }}:dev + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 8a96be7..5ac377b 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -14,6 +14,7 @@ on: types: [published] env: + DOCKERHUB_PLATFORMS: linux/amd64,linux/arm64 BBSD_IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/lbbs-bbsd jobs: @@ -39,6 +40,7 @@ jobs: id: push-bbsd uses: docker/build-push-action@v5 with: + platforms: ${{ env.DOCKERHUB_PLATFORMS }} context: . file: ./Dockerfile/dockerfile.bbsd push: true From 88db0f72367e5361aca897944ed7e8b3799b4dfd Mon Sep 17 00:00:00 2001 From: Leaflet Date: Sat, 10 Jan 2026 11:50:12 +0800 Subject: [PATCH 4/4] Update INSTALL.md --- INSTALL.md | 79 ++++++++++++++++++++++++++++++++++++++++-------- INSTALL.zh_CN.md | 79 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 134 insertions(+), 24 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index add9a19..76b6dce 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,6 +1,6 @@ # Installation -The Chinese version of this changelog is available at [INSTALL.zh_CN.md](INSTALL.zh_CN.md). +The Chinese version of this installation guide is available at [INSTALL.zh_CN.md](INSTALL.zh_CN.md). To install LBBS on Linux (e.g., Debian 13, CentOS Stream 10), please perform the following steps: @@ -79,12 +79,31 @@ chown -R bbs:bbs $LBBS_HOME_DIR ## 6. Modify Configuration Files -Default configuration files are saved as `*.default`. Rename them first: +Default configuration files are saved as `*.default`. Copy and rename them first: -- `$LBBS_HOME_DIR/conf/bbsd.conf` -- `$LBBS_HOME_DIR/conf/bbsnet.conf` -- `$LBBS_HOME_DIR/conf/badwords.conf` -- `$LBBS_HOME_DIR/utils/conf/db_conn.conf.php` +```bash +cd $LBBS_HOME_DIR +cp conf/bbsd.conf.default conf/bbsd.conf +cp conf/bbsnet.conf.default conf/bbsnet.conf +cp conf/badwords.conf.default conf/badwords.conf +cp utils/conf/db_conn.conf.php.default utils/conf/db_conn.conf.php +``` + +Then edit each file to match your environment: + +### bbsd.conf +Key settings to adjust: +- `db_host`, `db_username`, `db_password`, `db_database`: MySQL connection details +- `bbs_server`, `bbs_port`, `bbs_ssh_port`: Network settings +- `bbs_name`: Your BBS name +- `bbs_max_client`: Maximum concurrent connections (adjust based on server capacity) + +### db_conn.conf.php +Set the database connection parameters: +- `$DB_hostname`, `$DB_username`, `$DB_password`, `$DB_database` + +### bbsnet.conf & badwords.conf +Review and customize as needed for your BBS policies. ## 7. Copy MySQL CA Certificate @@ -102,6 +121,8 @@ sudo -u bbs php $LBBS_HOME_DIR/utils/bin/gen_top.php ## 9. Create SSH2 Certificates +Generate SSH host keys for the SSH server component. The `-N ""` flag sets an empty passphrase for the keys (required for automated service startup). + ```bash ssh-keygen -t rsa -C "Your Server Name" -N "" -f $LBBS_HOME_DIR/conf/ssh_host_rsa_key ssh-keygen -t ed25519 -C "Your Server Name" -N "" -f $LBBS_HOME_DIR/conf/ssh_host_ed25519_key @@ -130,26 +151,60 @@ Restart the logrotate service. In case of unexpected failure or improper operation resulting in abnormal termination of the LBBS process, manual cleanup of shared memory/semaphore might be required before relaunching the process. -First, check with: +### When Cleanup is Needed +- After a crash or force-kill of the `bbsd` process +- If `bbsd` fails to start with "shared memory already exists" errors +- When `ipcs` shows resources owned by user `bbs` + +### Checking for Orphaned Resources +First, check for any remaining shared memory segments or semaphores: ```bash sudo -u bbs ipcs ``` -There should be no items owned by `bbs`. Otherwise, clean up with: +Look for entries in the "SHM" (shared memory) and "SEM" (semaphore) sections where the "OWNER" is `bbs`. + +### Cleaning Up +If resources exist, remove them with: ```bash sudo -u bbs ipcrm -a ``` -# For Docker Users +This removes all shared memory and semaphore resources accessible to the `bbs` user. + +## 14. Docker Installation (Alternative Method) + +For containerized deployment, LBBS provides Docker support. -You may either build the Docker image from source code by running: +### Building from Source +To build the Docker image from source code: ```bash docker compose up --build -d ``` -or pull the Docker image per release from Docker Hub by running: +### Using Pre-built Images +To use pre-built images from Docker Hub: ```bash docker compose pull +docker compose up -d ``` -You should always create/update the configuration files for local configuration (e.g., database connection, network port) as described above. \ No newline at end of file +### Configuration for Docker +When using Docker, you still need to configure LBBS appropriately: + +1. **Configuration Files**: Create and customize the configuration files as described in Step 6. +2. **Database Connection**: Ensure `db_conn.conf.php` points to your MySQL server (which should be accessible from the container). +3. **Port Mapping**: By default, Docker Compose maps: + - SSH port: 2322 → 2322 (container) + - Telnet port: 2323 → 2323 (container) + + Adjust these in `docker-compose.yml` if needed. +4. **Persistent Data**: The `data/` and `conf/` directories are mounted as volumes for persistence. + +### Docker Compose Management +- Start: `docker compose up -d` +- Stop: `docker compose down` +- View logs: `docker compose logs -f` +- Restart: `docker compose restart` + +For more details, refer to the `docker-compose.yml` file and Docker documentation. diff --git a/INSTALL.zh_CN.md b/INSTALL.zh_CN.md index 0471d98..c16dda7 100644 --- a/INSTALL.zh_CN.md +++ b/INSTALL.zh_CN.md @@ -1,6 +1,6 @@ # 安装说明 -英文版本的更新日志位于 [INSTALL.md](INSTALL.md)。 +英文版本的安装说明位于 [INSTALL.md](INSTALL.md)。 要在 Linux(例如:Debian 13、CentOS Stream 10)上安装 LBBS,请按照以下步骤操作: @@ -79,12 +79,31 @@ chown -R bbs:bbs $LBBS_HOME_DIR ## 6. 修改配置文件 -默认配置文件保存为 `*.default`。首先重命名它们: +默认配置文件保存为 `*.default`。首先复制并重命名它们: -- `$LBBS_HOME_DIR/conf/bbsd.conf` -- `$LBBS_HOME_DIR/conf/bbsnet.conf` -- `$LBBS_HOME_DIR/conf/badwords.conf` -- `$LBBS_HOME_DIR/utils/conf/db_conn.conf.php` +```bash +cd $LBBS_HOME_DIR +cp conf/bbsd.conf.default conf/bbsd.conf +cp conf/bbsnet.conf.default conf/bbsnet.conf +cp conf/badwords.conf.default conf/badwords.conf +cp utils/conf/db_conn.conf.php.default utils/conf/db_conn.conf.php +``` + +然后编辑每个文件以匹配您的环境: + +### bbsd.conf +需要调整的关键设置: +- `db_host`, `db_username`, `db_password`, `db_database`: MySQL 连接详情 +- `bbs_server`, `bbs_port`, `bbs_ssh_port`: 网络设置 +- `bbs_name`: 您的 BBS 名称 +- `bbs_max_client`: 最大并发连接数(根据服务器容量调整) + +### db_conn.conf.php +设置数据库连接参数: +- `$DB_hostname`, `$DB_username`, `$DB_password`, `$DB_database` + +### bbsnet.conf & badwords.conf +根据您的 BBS 策略进行审查和自定义。 ## 7. 复制 MySQL CA 证书 @@ -102,6 +121,8 @@ sudo -u bbs php $LBBS_HOME_DIR/utils/bin/gen_top.php ## 9. 创建 SSH2 证书 +为 SSH 服务器组件生成 SSH 主机密钥。`-N ""` 标志为密钥设置空密码(自动化服务启动所需)。 + ```bash ssh-keygen -t rsa -C "您的服务器名称" -N "" -f $LBBS_HOME_DIR/conf/ssh_host_rsa_key ssh-keygen -t ed25519 -C "您的服务器名称" -N "" -f $LBBS_HOME_DIR/conf/ssh_host_ed25519_key @@ -130,26 +151,60 @@ sudo -u bbs $LBBS_HOME_DIR/bin/bbsd 如果发生意外故障或操作不当导致 LBBS 进程异常终止,在重新启动进程之前可能需要手动清理共享内存/信号量。 -首先,使用以下命令检查: +### 何时需要清理 +- `bbsd` 进程崩溃或被强制终止后 +- 如果 `bbsd` 启动时出现"共享内存已存在"错误 +- 当 `ipcs` 显示属于用户 `bbs` 的资源时 + +### 检查孤儿资源 +首先,检查是否有剩余的共享内存段或信号量: ```bash sudo -u bbs ipcs ``` -不应存在属于 `bbs` 的项目。否则,使用以下命令清理: +查看 "SHM"(共享内存)和 "SEM"(信号量)部分中 "OWNER" 为 `bbs` 的条目。 + +### 清理 +如果存在资源,使用以下命令删除: ```bash sudo -u bbs ipcrm -a ``` -# 对于 Docker 用户 +这将删除 `bbs` 用户可访问的所有共享内存和信号量资源。 + +## 14. Docker 安装(替代方法) + +对于容器化部署,LBBS 提供 Docker 支持。 -您可以通过运行以下命令从源代码构建 Docker 镜像: +### 从源代码构建 +要从源代码构建 Docker 镜像: ```bash docker compose up --build -d ``` -或者通过运行以下命令从 Docker Hub 拉取每个版本的 Docker 镜像: +### 使用预构建镜像 +要使用 Docker Hub 中的预构建镜像: ```bash docker compose pull +docker compose up -d ``` -您应始终按照上述说明创建/更新本地配置(例如,数据库连接、网络端口)的配置文件。 \ No newline at end of file +### Docker 配置 +使用 Docker 时,您仍然需要适当配置 LBBS: + +1. **配置文件**:按照步骤 6 中的说明创建和自定义配置文件。 +2. **数据库连接**:确保 `db_conn.conf.php` 指向您的 MySQL 服务器(容器应能访问该服务器)。 +3. **端口映射**:默认情况下,Docker Compose 映射: + - SSH 端口:2222 → 22(容器) + - Telnet 端口:2323 → 23(容器) + + 如果需要,请在 `docker-compose.yml` 中调整这些设置。 +4. **持久化数据**:`data/` 和 `conf/` 目录作为卷挂载以实现持久化。 + +### Docker Compose 管理 +- 启动:`docker compose up -d` +- 停止:`docker compose down` +- 查看日志:`docker compose logs -f` +- 重启:`docker compose restart` + +有关更多详细信息,请参阅 `docker-compose.yml` 文件和 Docker 文档。