This document outlines the directory structure for scripts in the OpenIM Server project. These scripts play a critical role in various areas like building, deploying, running and managing the services of OpenIM.
```bash
scripts/
├── LICENSE # License related files
│ ├── LICENSE # The license file
│ └── LICENSE_TEMPLATES # Template for license file
├── README.md # Readme file for scripts directory
├── advertise.sh # Script for advertisement services
└── style_info.sh # Script containing style related information
```
The purpose of having a structured scripts directory like this is to make the operations of OpenIM Server clear and easy to manage. Each script has its own responsibility, making it easier to maintain and update. It's also helpful for newcomers who can easily understand what each part of the system is doing by just looking at this directory structure.
Each directory and script in the structure should be understood as a part of a larger whole. All scripts work together to ensure the smooth operation and maintenance of the OpenIM Server.
Here you will learn how to test a script, We take the four functions for starting and checking a service as an example.
## Guide: Using and Understanding OpenIM Utility Functions
This document provides an overview of the four utility functions designed for managing processes and services. These functions can check the status of services based on ports and process names, as well as stop services based on the same criteria.
### Table of Contents
- [1. Checking the Status of Services by Ports](#checking-the-status-of-services-by-ports)
- [2. Checking the Status of Services by Process Names](#checking-the-status-of-services-by-process-names)
- [3. Stopping Services by Ports](#stopping-services-by-ports)
- [4. Stopping Services by Process Names](#stopping-services-by-process-names)
### 1. Checking the Status of Services by Ports
#### Function: `openim::util::check_ports`
This function checks the status of services running on specified ports.
**Usage**:
```bash
openim::util::check_ports <port1><port2> ...
```
**Design**:
- The function iterates through each provided port.
- It uses the `lsof` command to identify if there is a service running on the specified port.
- If a service is running, it logs the command, PID, and start time of the service.
- If a service is not running, it logs that the port is not started.
- If any service is not running, the function returns a status of 1.
#### Example:
```bash
openim::util::check_ports 8080 8081 8082
```
### 2. Checking the Status of Services by Process Names
The script directory design of OpenIM and the writing of scripts and tools refer to many excellent open source projects, such as helm, iam, kubernetes, docker, etc.
Maybe they'll give you inspiration for later maintenance...