Skip to main content

Systemd Deployment

This guide covers deploying Posthoot as a system service using systemd. This approach is ideal for Linux servers where you want to run Posthoot as a native service with automatic startup and management.

Prerequisites

Before you begin, ensure you have:
  • Linux system with systemd (Ubuntu 16.04+, CentOS 7+, etc.)
  • Go 1.21+ installed
  • PostgreSQL 14+ installed and configured
  • Redis 6+ installed and configured
  • Git for cloning the repository
  • Root or sudo access for service installation

Quick Start

1. Install Dependencies

Ubuntu/Debian

CentOS/RHEL

2. Clone and Build

3. Create Service User

4. Configure Environment

Add your configuration:

5. Create Systemd Service

Add the service configuration:

6. Enable and Start Service

Configuration

Environment Variables

Key environment variables for systemd deployment:

Service Configuration

The systemd service includes several security and performance settings:
  • User isolation: Runs as dedicated posthoot user
  • File system protection: Restricted access to system directories
  • Resource limits: Increased file descriptor limits
  • Automatic restart: Service restarts on failure
  • Dependencies: Waits for PostgreSQL and Redis

Logging Configuration

Configure log rotation:
Add configuration:

Management

Basic Commands

Monitoring

Configuration Updates

Database Setup

PostgreSQL Configuration

Redis Configuration

Security

Firewall Configuration

Service Security

The systemd service includes several security features:
  • NoNewPrivileges: Prevents privilege escalation
  • PrivateTmp: Isolated temporary directory
  • ProtectSystem: Restricts file system access
  • ProtectHome: Protects home directories
  • ReadWritePaths: Only allows writing to specific paths

File Permissions

Reverse Proxy Setup

Nginx Configuration

Create Nginx configuration:
Add configuration:
Enable the site:

Monitoring and Logging

Health Check

The service provides a health check endpoint:

Log Analysis

Performance Monitoring

Backup and Recovery

Database Backup

Create backup script:
Add content:
Make executable:

Automated Backups

Add to crontab:

Troubleshooting

Common Issues

1. Service Won’t Start

2. Database Connection Issues

3. Permission Issues

4. Port Already in Use

Debugging

Performance Tuning

System Optimization

Service Optimization

Production Considerations

High Availability

For production environments:
  1. Load balancer: Use multiple instances behind a load balancer
  2. Database clustering: Consider PostgreSQL clustering solutions
  3. Monitoring: Implement comprehensive monitoring and alerting
  4. Backup strategy: Regular backups with off-site storage

Security Hardening

Monitoring Setup

Install monitoring tools:

Support

For systemd-specific issues:
  1. Check systemd logs: sudo journalctl -u posthoot
  2. Verify service configuration: sudo systemctl cat posthoot
  3. Check dependencies: sudo systemctl list-dependencies posthoot
  4. Review system logs: sudo journalctl -xe

Next Steps

After successful deployment:
  1. Configure monitoring and alerting
  2. Set up backups and test recovery
  3. Implement security best practices
  4. Plan scaling strategies
  5. Document procedures for your team