# Shlagernetes deployer - Specifications

# Context

Shlagernetes is an orchestration tool allowing services to be stored on second-hand servers. It handles the configuration of the servers, the installation and maintenance of services as well as their deletion. Services can be static or dynamic websites, VPNs, etc. They can be in a container if required but not necessarily.
Shlagernetes works with an nginx reverse proxy, wireguard VPN, letsencrypt ssl certification and git versioning.

Shl8s works with the principle of Infrastructure As Code. 
On every server, there will be an instance of the Shl8s deployer, written in C. 
The deployer will call bash scripts specific to the service, as well as functions from libraries specific to setting the nginx configuration, the vpn, ssl certification, etc.

# Call

./deployer deploy/remove all/service_name             
            
# Description

deploy_service(service)   
{  
   - determines if the service is on this server  
    if it is:   
    - creates directories (secret, data, http) if necessary   
    - calls the bash scripts specific to the service if they exist (deploy_as)  
    - creates user and .env variables if necessary  
    - calls the deployment functions from the libraries   
}  

remove_service(service) //should there be some kind of less absolute removal?  
{  
   - determines if the service is on this server  
    if it is:       
    - calls the removing bash scripts specific to the service if they exist    
    - calls the removing functions from the libraries  
    - deletes .env variables  
    - deletes directories  
    - deletes user  
    - removes from .csv //should this get done before by the sysadmin? but how to check that something was here if it has been removed ?     
}  

**main.cpp** 
- reads the instructions
If deploy all:
    - checks the environment (/data/mounted and new nginx conf exists)  
    - prepares directories
    - prepares Nginx  
    - prepares Docker  
    - prepares .env   
    for each service:  
        - deploy_service(service) 
    - (re)start nginx 
    - cleans  
else if deploy one service: 
    - checks the environment (/data/mounted and new nginx conf exists)  
    - deploy_service(service)  
    - (re)start nginx
else if remove all:  
    for each service:   
        - remove_service(service)  
    - stop Docker  
    - stop wireguard  
    - stop Nginx  
    - cleans .env   
    - cleans  
else if remove one service:  
    - remove_service(service)  

**plugins/static libraries** 
- nginx
    preparation
    deployment
        writing new conf
        testing
        replacing old conf
        start/restart
        cleaning       
    stop
- wireguard
    deploy (with and without namespace)
    remove
- encryption
    deploy
    remove
- docker 
    preparation
    deploy
    remove
    stop
    clean

**functions/imports if too long**
- user creation
- environment variables handling

