Showing posts with label application. Show all posts
Showing posts with label application. Show all posts

Friday

Simple Nginx Conf for Microservices Application

########################################################################

# Main Nginx configuration file for Dockerized Microservices

#

# More information about the configuration options is available on 

# * the English wiki - http://wiki.nginx.org/Main

# * the Russian documentation - http://sysoev.ru/nginx/

#

#######################################################################


#----------------------------------------------------------------------

# Main Module - directives that cover basic functionality

#

# http://wiki.nginx.org/NginxHttpMainModule

#

#----------------------------------------------------------------------


user nginx;

worker_processes auto;


error_log /opt/nginx/logs/error.log;

#error_log /var/log/nginx/error.log notice;

#error_log /var/log/nginx/error.log info;


pid /var/run/nginx.pid;


#----------------------------------------------------------------------

# Events Module 

#

# http://wiki.nginx.org/NginxHttpEventsModule

#

#----------------------------------------------------------------------


events {

    worker_connections 2048;

}


#----------------------------------------------------------------------

# HTTP Core Module

#

# http://wiki.nginx.org/NginxHttpCoreModule 

#

#----------------------------------------------------------------------


http {

    include /opt/nginx/conf/mime.types;

    default_type application/octet-stream;


    log_format main '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log /opt/nginx/logs/access.log main;


    sendfile on;

    autoindex off;

    

    map $scheme $fastcgi_https {

        default off;

        https on;

    }


    keepalive_timeout 60;


    gzip on;

    gzip_comp_level 2;

    gzip_proxied any;

    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    gzip_disable "msie6";

    gzip_vary on;

    gzip_min_length 1024;

    gzip_http_version 1.1;

    # gzip_static on;


    # Load config files from the /etc/nginx/conf.d directory

    # The default server is in conf.d/default.conf

    include /opt/nginx/conf/conf.d/*.conf;

    # include /etc/nginx/sites-enabled/*;

    # tcp_nopush on;

}


Sunday

Run Two Systemd Services Alternately

To achieve the desired sequence where `app1` starts, runs for 10 minutes, then `app2` starts and runs for 10 minutes, and this cycle repeats, you can create two separate timer units and services, one for each application, and use a cyclic approach. Here's how you can do it:


1. Create two timer units, one for each application, with cyclic activation:


   `myapp1.timer`:

   ```ini

   [Unit]

   Description=Timer for My Application 1


   [Timer]

   OnBootSec=10min

   OnUnitInactiveSec=10min


   [Install]

   WantedBy=timers.target

   ```


   `myapp2.timer`:

   ```ini

   [Unit]

   Description=Timer for My Application 2


   [Timer]

   OnBootSec=20min

   OnUnitInactiveSec=10min


   [Install]

   WantedBy=timers.target

   ```


In this configuration, `myapp1.timer` is set to trigger `myapp1.service` 10 minutes after boot and every 10 minutes after it becomes inactive. `myapp2.timer` is set to trigger `myapp2.service` 20 minutes after boot and every 10 minutes after it becomes inactive.


2. Create two service units, one for each application:


   `myapp1.service`:

   ```ini

   [Unit]

   Description=My Application 1


   [Service]

   ExecStart=/path/to/app1

   Restart=always


   [Install]

   WantedBy=multi-user.target

   ```


   `myapp2.service`:

   ```ini

   [Unit]

   Description=My Application 2


   [Service]

   ExecStart=/path/to/app2

   Restart=always


   [Install]

   WantedBy=multi-user.target

   ```


Replace `/path/to/app1` and `/path/to/app2` with the actual paths to your application executables.


3. Enable and start both timer units:


   ```

   sudo systemctl enable myapp1.timer

   sudo systemctl enable myapp2.timer

   sudo systemctl start myapp1.timer

   sudo systemctl start myapp2.timer

   ```


With this setup, `app1` will start when the system boots, run for 10 minutes, then stop. After that, `app2` will start and run for 10 minutes, and the cycle repeats. This pattern continues indefinitely.

AI Assistant For Test Assignment

  Photo by Google DeepMind Creating an AI application to assist school teachers with testing assignments and result analysis can greatly ben...