Aria Auto Config: Seamless Apache Service Auto-Restart using Beacons & Reactors

PAGE CONTENTS
Goal
Introduction
System Requirements
Step-by-Step Guide

Goal

Automate the Auto-Start of Apache Service using Aria Auto Config (SaltStack) Beacons & Reactors.

Introduction

    In today’s fast-paced world of IT Ops, ensuring the continuous availability of essential services is paramount. One such critical service is the Apache web server, often used to host websites and applications. In this blog, we will explore how to leverage the power of Aria Auto Config (SaltStack) beacons and reactors to automatically restart the Apache service on a target machine whenever it crashes or stops unexpectedly. By proactively detecting service interruptions and initiating corrective actions, you can minimize downtime and provide a seamless experience for your users.

System Requirements

1. Salt-Master is configured and available.

2. Target Machine with Ubuntu 22.04 LTS: salt-minion configured and available.

Step-by-Step Guide

1. Login into Aria Auto Config UI and Navigate to Configurations > File Server

2. Create a salt state file “apache.sls” , I used the path ” /apache-remedy/ in base directory 

needed-pkgs:
  pkg.installed:
    - pkgs:
      - python-pyinotify

stage-beacon:
  file.managed:
    - name: /etc/salt/minion.d/beacons.conf
    - source: salt://apache-remedy/beacons.conf
    - makedirs: True
     
salt-minion:
  service.running:
    - enable: True
    - watch:
      - stage-beacon

3. To ensure that the Apache Service is automatically started in case of a crash or service being stopped intermittently, we need to set up a beacon and reactor. 

4. Let us create beacons.conf file in the path “/apache-remedy/beacons.conf”. This will keep monitoring the service apache2 with a delay of 15 seconds and will alert the reactor via event bus in case the service is not Active and Running.

beacons:
  service:
    - services:
        apache2:
          onchangeonly: True
          delay: 15
          uncleanshutdown: /run/apache2.pid

5. Let us now create Reactor Configuration, path “/apache-remedy/reactorconfig.conf”

reactor:
  - 'salt/beacon/*/service/apache2':
    - salt://reactor/service.sls

6. Next we will create a salt state file named “service.sls” which will trigger orchestration to start the Apache Service once the Beacon has sent an event that the Apache Service is stopped. Path “/apache-remedy/service.sls”

{% if data['apache2']['running'] == False %}
start_service:
  local.service.start:
    - tgt: {{ data['id'] }}
    - arg:
      - apache2
{% endif %}

7. We will need to create a salt state file to copy the Reactor Configuration to /etc/master/master.d/ Path for the salt state “/apache-remedy/reactor-copy.sls

reactor-copy:
  file.managed:
    - name: /etc/salt/master.d/reactorconfig.conf
    - source: salt://reactor/reactorconfig.conf
     
restart-master:
  service.running:
    - name: salt-master
    - watch:
      - reactor-copy

8. Let us create a couple of Jobs to complete the sequence of files to be copied and the salt state file applied.

9. Navigate to Configurations > Jobs > CREATE JOB : apache-reactor. Next, choose the salt-master minion and run the Job “apache-reactor” job against that salt-master minion. 

   

10. Create JOB: apache and run the job “apache” against the target host ubuntu salt-minion where the Apache server is installed. 

 

11. Navigate to Activity > In Progress > Completed: Wait for all the jobs to get completed successfully. 

12. Open the Ubuntu Target host address and ensure that Apache is serving the HTTP requests and you are able to see the home page. 

13. Let us test the Auto-Start of Apache Service works as expected or not. You can manually stop the service by logging into Ubuntu Server or through Aria Auto Config itself. Either way, Apache2 service will be started automatically. 

14. Navigate to Aria Auto Config UI, click on the Ubuntu Minion > Choose Run Command: Choose “salt”, Function: “service. stop”, Arguments: apache2  >> click on  RUN COMMAND. Ubuntu Server : Apache service will be stopped and HTTP requests will not be served. 

14. Navigate to Activity >> Completed  [Wait for 30 seconds as we have added delay]. 

15. You may note that we stopped the Apache service through service.stop salt command. The beacon observed that the apache2 service is stopped. Beacon triggered an event to the reactor running on Salt-Master. The Reactor ensures that the Apache Service is started as per the above configurations that we have done. 

16. You can choose any path for storing the salt states and conf files in the File Server, I have chosen /apache-remedy/ it can be of your choice. You modify the delay to 5 seconds or 10 seconds as per your requirement. 

17. You may note that we cannot have two beacons for a given minion. If you need to monitor two services or more, kindly include the required configuration as part of the same state file and configs. 

Conclusion: By combining Aria Auto Config’s (SaltStack) beacons and reactors, you’ve successfully automated the process of monitoring and restarting the Apache service on a target machine in the event of a crash or unexpected stop. This streamlined approach ensures the continuous availability of your web services, reduces downtime, and empowers your IT operations to respond proactively to service interruptions.

Remember to fine-tune the beacon interval and reactor configurations according to your environment’s needs. With this implementation, you’ve taken a significant step towards optimizing your system’s reliability and delivering a seamless user experience.

Thank you for reading. Watch the below video for the live demo of the above Apache Service Auto Start using Aria Auto Config (SaltStack) using Beacons & Reactors.