{"id":30769895,"url":"https://github.com/hazemdotcom/barq-lite-deployment","last_synced_at":"2026-04-11T12:03:18.276Z","repository":{"id":311452951,"uuid":"1043739254","full_name":"hazemdotcom/barq-lite-deployment","owner":"hazemdotcom","description":"Automated deployment and management of BARQ Lite Java application using Ansible and Bash scripts","archived":false,"fork":false,"pushed_at":"2025-08-24T14:49:51.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-24T19:43:31.352Z","etag":null,"topics":["ansible","ansible-playbook","ansible-role","deploy","deployment","deployment-automation","docker","docker-image","dockerfile","idempotency","idempotent","inventory","jar","java","yaml"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hazemdotcom.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-24T14:16:38.000Z","updated_at":"2025-08-24T14:53:19.000Z","dependencies_parsed_at":"2025-08-24T19:43:36.977Z","dependency_job_id":"a17f9579-965d-4b3f-8763-e3cc810b3302","html_url":"https://github.com/hazemdotcom/barq-lite-deployment","commit_stats":null,"previous_names":["hazemdotcom/barq-lite-deployment"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/hazemdotcom/barq-lite-deployment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazemdotcom%2Fbarq-lite-deployment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazemdotcom%2Fbarq-lite-deployment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazemdotcom%2Fbarq-lite-deployment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazemdotcom%2Fbarq-lite-deployment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hazemdotcom","download_url":"https://codeload.github.com/hazemdotcom/barq-lite-deployment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazemdotcom%2Fbarq-lite-deployment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273685604,"owners_count":25149722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-playbook","ansible-role","deploy","deployment","deployment-automation","docker","docker-image","dockerfile","idempotency","idempotent","inventory","jar","java","yaml"],"created_at":"2025-09-04T23:02:35.569Z","updated_at":"2026-04-11T12:03:13.243Z","avatar_url":"https://github.com/hazemdotcom.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# BARQ Lite – Two-Server Ops Project\n\n## Overview / Description\n\nThe **BARQ Lite – Two-Server Ops Project** automates the deployment and operational management of a small Java-based application across two Linux servers (`s1` and `s2`).  \n\nThe project achieves the following:\n\n- Sets up necessary directories and log files for the application.\n- Deploys a prebuilt Java JAR (`barq-lite.jar`) to both servers using Ansible.\n- Configures a systemd service to ensure the application runs at boot and logs to `/var/log/barq/barq.log`.\n- Automates log compression and retention using a Bash script scheduled via cron.\n- Automates TLS certificate reporting with a Bash script and cron job.\n- Ensures tasks are idempotent and can be re-run without causing unintended changes.\n\n\u003e **Note:** The optional Docker deployment for the Java application is not included in this setup.\n## Project Scope / Scenario\n\nThis project is designed to set up and automate operational tasks for the **BARQ Lite** Java application on two Linux servers, `s1` and `s2`.  \n\n**Scenario:**\n\n- **Servers:** Two Linux servers with no initial application files, logs, or TLS certificates.  \n- **Application:** A prebuilt Java application (`barq-lite.jar`) that writes logs to `/var/log/barq/barq.log`.  \n- **Tasks:**\n  - Create necessary directories for logs and releases.\n  - Deploy the Java application to `/opt/barq/releases/\u003crelease_id\u003e/`.\n  - Update `/opt/barq/current` symlink to point to the latest release.\n  - Configure a systemd service (`barq.service`) to run the application on boot.\n  - Automate log management via a Bash script (`log-lite.sh`) scheduled with cron.\n  - Automate TLS certificate reporting via a Bash script (`cert-lite.sh`) scheduled with cron.\n- **Automation Tools:** Bash for scripting, Ansible for deployment and orchestration.\n- **Goal:** Ensure the Java application runs reliably, logs are properly managed, and TLS certificates are monitored automatically across both servers.\n## Prerequisites\n\nBefore running the playbooks and scripts, ensure the following prerequisites are met on both servers (`s1` and `s2`):\n\n### Operating System\n- Linux-based server (Ubuntu 20.04/22.04, Debian 10/11, or CentOS 7/8)\n\n### Packages and Tools\n- **Java JDK** (required to run `barq-lite.jar`)  \n  ```bash\n  java -version\n## Environment Setup\n\nBefore deploying the application, the following resources are created on both servers:\n\n### 1. Application Logs\n- Directory: `/var/log/barq/`\n- Two initial log files are created:\n  - One with **yesterday's date** in the filename\n  - One with **today's date** in the filename\n- These logs are used by the Java application and for automated log compression.\n\n### 2. Java Application Release\n- The prebuilt JAR file `barq-lite.jar` is deployed to: \n`/opt/barq/releases/\u003crelease_id\u003e/`\n- A symbolic link `/opt/barq/current` points to the latest release, ensuring easy rollback and deployment management.\n- Logs generated by the application are written to `/var/log/barq/barq.log`.\n\n### 3. TLS Certificate Folder\n- Directory: `/etc/ssl/patrol/`\n- At least one short-lived self-signed certificate is generated for testing purposes.\n- Certificates are later scanned and reported via a Bash script (`cert-lite.sh`) scheduled in cron.\n\n\u003e All directories and files are created in an idempotent manner using Ansible, so re-running the playbooks does not overwrite existing resources unnecessarily.\n## Bash Scripts \u0026 Cron Jobs\n\nTwo Bash scripts are implemented to automate operational tasks on the servers.\n\n### 1. `log-lite.sh` – Log Compression \u0026 Retention\n- **Purpose:** \nCompresses all log files from yesterday in `/var/log/barq/` and deletes compressed logs older than 7 days.  \n\n- **Location:** \n`/usr/local/bin/log-lite.sh`  \n\n- **Cron Schedule:** \nRuns daily at **01:10**  \n  ```cron\n  10 1 * * * /usr/local/bin/log-lite.sh\n### 2. `cert-lite.sh` – TLS Certificate Report\n\n- **Purpose:**  \n  Automates the scanning of TLS certificates in `/etc/ssl/patrol/` and generates a report containing the certificate name, expiration date, and remaining days until expiry.\n\n- **Location:**  \n  `/usr/local/bin/cert-lite.sh`\n\n- **Report format:**\n    ```\n    cert_name | NotAfter_date | days_remaining\n    ```\n- **Cron Schedule:**  \n  Runs automatically every day at **07:00**\n  ```cron\n  0 7 * * * /usr/local/bin/cert-lite.sh\n## Ansible Deployment\nThe BARQ Lite Java application is deployed and managed using Ansible to ensure a consistent and automated setup across both servers.\n### 1. Inventory\n\nThe Ansible inventory defines the servers that will be managed:\n\n```ini\n[barq]\ns1 ansible_host=192.168.1.10 ansible_user=hazem\ns2 ansible_host=192.168.1.11 ansible_user=hazem\n```\n### 2. Roles and Playbooks\n\nThe deployment is modularized using roles and orchestrated via playbooks.\n\n**Roles:**\n- `barq_logs` – Creates log directories and initial log files\n- `barq_app` – Uploads the Java JAR, creates release directories, updates the symlink\n- `barq_service` – Configures systemd service for the Java application\n\n**Playbooks:**\n- `deploy-app.yaml` – Main playbook that executes the roles in a serial deployment (one server at a time)\n\n**Running the Playbooks**\n\nFollow these steps to deploy BARQ Lite Java Application on both servers (`s1` and `s2`):\n\n1. **Ensure prerequisites are installed on the control node:**\n   - Ansible\n   - SSH access to the target servers\n   - Sudo privileges on the target servers\n\n2. **Run the main deployment playbook:**\n\n```bash\nansible-playbook -i inventory.txt deploy-app.yaml -K --ask-pass\n```\n-   `-i inventory.txt` → specifies the inventory file\n    \n-   `-K` → prompts for the sudo (become) password if required\n\n### 3. Java Application Deployment\n\n- The prebuilt Java JAR (`barq-lite.jar`) is uploaded to:\n`/opt/barq/releases/\u003crelease_id\u003e/`\n- A symbolic link `/opt/barq/current` points to the latest release.\n- Ensures easy rollback by updating the symlink.\n- Deployment is performed serially to avoid simultaneous changes on multiple servers.\n\n### 4. Systemd Service Setup\n\nA systemd service (`barq.service`) is configured to run the Java application at boot:\n\n```ini\n[Unit]\nDescription=BARQ Lite Java App\nAfter=network.target\n\n[Service]\nUser=root\nExecStart=/usr/bin/java -jar /opt/barq/current/barq-lite.jar\nStandardOutput=file:/var/log/barq/barq.log\nStandardError=file:/var/log/barq/barq.log\nRestart=always\n\n[Install]\nWantedBy=multi-user.target \n```\n-   Service is enabled and started automatically.\n    \n-   Logs are written to `/var/log/barq/barq.log`.\n\n\n### **5. Idempotency**\n\nAll Ansible tasks are designed to be idempotent, meaning they can be executed multiple times without causing unintended changes.\n\nExamples:\n- Directories are created only if they do not exist.\n- Files are copied only if they differ from the target.\n- Systemd service state is checked before applying changes.\n\nThis ensures safe re-execution of playbooks for maintenance or updates.\n## Directory / File Structure\n\nThe project is organized as follows:\n\n\n```\nansible/  \n\t├── deploy-app.yaml\n\t├── inventory.txt \n\t├── barq-lite.jar\n\t├── roles/\n\t\t├── barq_logs/  \n\t\t│ └── tasks/main.yml  \n\t\t├── barq_app/  \n\t\t│ └── tasks/main.yml  \n\t\t├── barq_service/  \n\t\t│ └── tasks/main.yml  \n```\n## Conclusion\n\nThis project automates the deployment and management of the BARQ Lite Java application across multiple servers.  \n\nKey achievements:\n\n- Automated creation of application directories, log files, and TLS certificate folders.\n- Bash scripts for log compression and TLS certificate reporting with scheduled cron jobs.\n- Java application deployment using Ansible with release management and symbolic linking.\n- Systemd service setup for automatic startup and log handling.\n- Idempotent Ansible tasks allowing safe re-execution for updates or maintenance.\n- Optional Docker packaging can containerize the application for future deployment enhancements.\n\nAll playbooks and scripts are modular, maintainable, and designed for easy extension or scaling to additional servers.\n## Contact\n\nFor any questions, issues, or feedback regarding this project, you can reach me at:\n\n**Hazem Bakr**  \n- Email: hazem.a.m.bakr@gmail.com\n- GitHub: [hazemdotcom](https://github.com/hazemdotcom)  \n- LinkedIn: [hazembakr](https://www.linkedin.com/in/hazembakr)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazemdotcom%2Fbarq-lite-deployment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhazemdotcom%2Fbarq-lite-deployment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazemdotcom%2Fbarq-lite-deployment/lists"}