Skip to content

Latest commit

 

History

History
237 lines (172 loc) · 4.93 KB

deployment.md

File metadata and controls

237 lines (172 loc) · 4.93 KB

Shig Server Deployment

Table of Contents

Run Shig Server as systemctl demon

This guide explains how to set up a Shig server as a systemd service and manage it using systemctl.


Prerequisites

  • A Linux-based server
  • Root or sudo access
  • Downloaded application. Please read the installation instructions: Install.
  • Create Application Directory
    sudo mkdir -p /opt/shig
  • Add Shig Server application and configuration in directory
    • /opt/shig/bin/shig_server
    • /opt/shig/config.toml

Step 1: Create the Service File

Create User and Group

Create group:

    sudo groupadd shig

Create a system user for the application:

    sudo useradd -r -g shig -d /opt/shig -s /bin/false shig

Explanation:

  • -r: Creates a system user.
  • -g shig: Assigns the user to the appgroup group.
  • -d /opt/shig: Sets /opt/shig as the user's home directory.
  • -s /bin/false: Prevents the user from logging in.

Set ownership of the application directory:

  sudo chown -R shig:shig /opt/shig
  sudo chmod -R 750 /opt/shig

Create system demon

Navigate to the systemd directory:

   cd /etc/systemd/system/

Create a new service file for your server:

   sudo nano shig.service

Add the following content to the file (customize as needed):

[Unit]
Description=Shig server daemon
After=network.target

[Service]
Type=simple
User=shig
Group=shig
ExecStart=/opt/shig/bin/shig_server -c /opt/shig/config.toml
WorkingDirectory=/opt/shig
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=shig
Restart=always

[Install]
WantedBy=multi-user.target

Save and exit the file.

Step 2: Reload and Enable the Service

Reload the systemd daemon to recognize the new service:

  sudo systemctl daemon-reload

Enable the service to start on boot:

  sudo systemctl enable shig.service

Start the service:

  sudo systemctl start shig.service

Check the status of the service to ensure it's running:

  sudo systemctl status shig.service

Setting up Shig Server behind Nginx

This guide provides step-by-step instructions to configure a Shig Server behind Nginx, secured with SSL certificates from Let's Encrypt.


Step 1: Install Required Tools

Update your server packages:

   sudo apt update && sudo apt upgrade -y

Install Nginx:

   sudo apt install nginx -y

Install Certbot:

  sudo apt install certbot python3-certbot-nginx -y

Step 2: Run Your Shig Server

Run Shig Server and ensure Shig Server is running on a specific port (e.g., http://localhost:8080) and test your Shig Server: Use curl or a browser to verify:

  curl http://localhost:8080

Step 3: Configure Nginx

Create an Nginx configuration file:

  sudo nano /etc/nginx/sites-available/shig-service

Add the following content to the file:

server {
    listen 80;
    server_name your-domain.com www.your-domain.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Replace: your-domain.com with your actual domain name. http://localhost:8080 with the URL and port where your Shig Server is running.

Enable the configuration: Create a symbolic link to enable the site:

  sudo ln -s /etc/nginx/sites-available/my-web-service /etc/nginx/sites-enabled/

Test the Nginx configuration:

  sudo nginx -t

Restart Nginx:

  sudo systemctl restart nginx

Step 4: Obtain SSL Certificates from Let’s Encrypt

Run Certbot to get SSL certificates:

  sudo certbot --nginx -d your-domain.com -d www.your-domain.com

Follow the prompts: Certbot will automatically configure Nginx for HTTPS.

Verify the certificates: After completion, your site should be accessible via https://your-domain.com.

Step 5: Set Up Automatic Certificate Renewal

Test automatic renewal: Certbot’s cron job should already be installed, but you can test it manually:

  sudo certbot renew --dry-run

Check logs for renewal: Logs are available at /var/log/letsencrypt/.

Step 6: Verify the Setup

Check Nginx logs:

  sudo tail -f /var/log/nginx/access.log /var/log/nginx/error.log

Ensure HTTPS is working: Open your domain in a browser and verify the SSL padlock in the address bar.

Optionally enable HTTP to HTTPS redirection: Edit your Nginx configuration:

server {
    listen 80;
    server_name your-domain.com www.your-domain.com;
    return 301 https://$host$request_uri;
}

Restart Nginx to apply:

  sudo systemctl restart nginx