77 lines
2.3 KiB
Markdown
77 lines
2.3 KiB
Markdown
|
|
# No-as-a-Service
|
|
|
|
This is a simple Ruby web service that responds with "No" in various languages. It's designed to accept both HTML and JSON requests and includes rate limiting, structured logging, and support for deployment using **Podman** and **systemd**.
|
|
|
|
## Features
|
|
- Returns "No" in multiple languages and styles.
|
|
- Supports both HTML and JSON response formats.
|
|
- Rate limiting to avoid abuse (30 requests per minute per IP).
|
|
- Logs structured output, forwarding logs to **journald** for integration with **systemd**.
|
|
|
|
## Files
|
|
- **app.rb**: The main Ruby application file with Sinatra web service.
|
|
- **Containerfile**: Instructions for building the container image using Podman.
|
|
- **no-as-a-service.service**: systemd service configuration for managing the application.
|
|
|
|
## Installation & Deployment
|
|
|
|
### Prerequisites
|
|
- **Podman**: To build and run the container.
|
|
- **systemd**: For managing the service.
|
|
- **Journald**: For logging.
|
|
|
|
### Step 1: Build the Container Image
|
|
|
|
Clone the repository or download the files, and navigate to the folder containing the `Containerfile` and `app.rb`.
|
|
|
|
Run the following command to build the container image with Podman:
|
|
|
|
```bash
|
|
podman build -t noaas .
|
|
```
|
|
|
|
### Step 2: Create the systemd Service
|
|
|
|
Copy the **`no-as-a-service.service`** file to your systemd service directory:
|
|
|
|
```bash
|
|
sudo cp no-as-a-service.service /etc/systemd/system/
|
|
```
|
|
|
|
Enable and start the service:
|
|
|
|
```bash
|
|
sudo systemctl daemon-reexec
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable --now no-as-a-service
|
|
```
|
|
|
|
### Step 3: Accessing the Service
|
|
|
|
Once the service is running, you can access it at:
|
|
|
|
- **HTML Response**: Open a browser and visit `http://localhost:8080/`.
|
|
- **JSON Response**: Send a GET request to `http://localhost:8080/` with an `Accept: application/json` header, or append `?format=json` to the URL.
|
|
|
|
### Logs
|
|
|
|
Logs are forwarded to **Journald**. You can view logs using:
|
|
|
|
```bash
|
|
journalctl -u no-as-a-service -t noaas -f
|
|
```
|
|
|
|
### Rate Limiting
|
|
|
|
Each IP is limited to 30 requests per minute. If this limit is exceeded, the response will be a `429 Too Many Requests` status with a JSON error message.
|
|
|
|
### Customizing Language Responses
|
|
|
|
You can customize the "No" responses in various languages by modifying the `NO_RESPONSES` hash in `app.rb`.
|
|
|
|
---
|
|
|
|
### License
|
|
|
|
This project is licensed under the MIT License - see the LICENSE file for details.
|