192 lines
8.0 KiB
Markdown
192 lines
8.0 KiB
Markdown
[KUBE](../README.md) / Site
|
|
|
|
# Site
|
|
|
|
## Site Creation
|
|
|
|
Stages of Site Creation:
|
|
|
|
### 1. Configuration.
|
|
|
|
The configuration, as a file (`<dataPath>/config/<domain>.config`), contains the connection parameters for `MariaDB` and `Redis`. The configuration can be prepared before starting the site creation or will be generated automatically.
|
|
|
|
Example configuration file:
|
|
```
|
|
databaseName=example_com
|
|
databaseUser=example_com
|
|
redisUser=example_com
|
|
databasePass=qwerty
|
|
redisPass=qwerty
|
|
```
|
|
|
|
Fields not specified will be generated automatically. The names of the database, database user, and `Redis` user are generated based on the domain using the functions `mariadbDomain2id` and `domain2redis`.
|
|
|
|
### 2. Initial Check.
|
|
|
|
Before starting the site creation, some configuration checks are performed:
|
|
* Check for absence of the vhost directory for the domain (`/path/to/vhosts/example.com`)
|
|
* Check for absence of the domain entry in the `OpenLiteSpeed` configuration
|
|
* Check for absence of the specified database
|
|
* Check for absence of the specified database user
|
|
* Check for absence of the specified `Redis` user
|
|
|
|
### 3. Distribution Check.
|
|
|
|
When creating a site, you can specify the source for the site files as `pathF` and the source for the database as `pathD`. `pathF` can be a directory or an archive file. `pathD` can be a SQL file for import as is, or an archive file.
|
|
|
|
If a file source `pathF` is specified, its presence is checked. Otherwise, the default distribution is used:
|
|
* for `Wordpress`: the directory `<assetsPath>/vhost.wordpress` (if the directory is missing, the file `<assetsPath>/vhost.wordpress.tar.gz` is used)
|
|
* for `non-Wordpress`: the directory `<assetsPath>/vhost.default` (if the directory is missing, the file `<assetsPath>/vhost.default.tar.gz` is used)
|
|
|
|
If the specified data sources are not found, or the default resources are not found, the process is aborted.
|
|
|
|
### 4. Site Creation.
|
|
|
|
When a site is created, the following steps occur:
|
|
* creation of the site directory structure `<vhostPath>/<domain>/{www,tmp,session}`
|
|
* copying site files from the source to the site directory
|
|
* creation of an OS user for the site files and changing access rights
|
|
* creation of a record in the `OpenLiteSpeed` configuration
|
|
* creation of a database and database user in `MariaDB`
|
|
* creation of a `Redis` user
|
|
* importing the database from the source, if specified
|
|
* writing database connection parameters (for `Wordpress`)
|
|
* writing Redis connection parameters (for `Wordpress`)
|
|
* writing to hosts (?!)
|
|
* restarting `OpenLiteSpeed`
|
|
|
|
***
|
|
|
|
## Site on Wordpress creation
|
|
|
|
* MariaDB
|
|
> The database name and database user name are formed on the basis of domain conversion, where all `.-` are replaced by `_`. If necessary, the conversion rule can be changed (mariadbDomain2id function). When generating connection parameters, the database password is saved to the `data/<domain>.mariadb` file.
|
|
|
|
Example for `example.com`:
|
|
```php
|
|
define( 'DB_HOST', 'mariadb-master' );
|
|
define( 'DB_NAME', 'example_com' );
|
|
define( 'DB_USER', 'example_com' );
|
|
define( 'DB_PASSWORD', 'qwerty' );
|
|
```
|
|
|
|
* Redis
|
|
> Redis username is generated based on domain conversion, where all `.-` are replaced by `_`. The conversion rule can be changed if necessary (`domain2redis` function). When generating connection parameters, the database password is stored in the `data/<domain>.redis` file.
|
|
|
|
Example for `example.com`:
|
|
```php
|
|
define( 'WP_REDIS_HOST', 'redis-0.redis' );
|
|
define( 'WP_REDIS_PORT', '6379' );
|
|
define( 'WP_REDIS_PASSWORD', ['example_com', 'qwerty'] );
|
|
define( 'WP_REDIS_PREFIX', 'example_com:' );
|
|
```
|
|
|
|
> [!NOTE]
|
|
> A separate Redis user is created for each Wordpress and a PrefixKey is also specified to separate keys in Redis.
|
|
***
|
|
|
|
## Commands
|
|
|
|
### `--site add <domain> [pathF] [pathD]`
|
|
Adding a site
|
|
|
|
Example:
|
|
```bash
|
|
sudo kube.sh --site add example.com
|
|
sudo kube.sh --site add example.com /path/to/files /path/to/database
|
|
```
|
|
***
|
|
|
|
### `--site wp <option>`
|
|
Add site(s) on Wordpress. Option:
|
|
- `list` - add list of domains with Wordpress from a default file: (`domainsList` in `config.sh`)
|
|
- `<file>` - add list of domains with Wordpress from a file (e.g., `/path/to/file.txt`)
|
|
- `<domain>` [pathF] [pathD] - add a domain with Wordpress (e.g., `example.com`)
|
|
|
|
Example:
|
|
```bash
|
|
sudo kube.sh --site wp /path/to/file.txt
|
|
sudo kube.sh --site wp list
|
|
sudo kube.sh --site wp example.com
|
|
sudo kube.sh --site wp example.com /path/to/files /path/to/database
|
|
```
|
|
***
|
|
|
|
### `--site remove <domain>`
|
|
|
|
> [!WARNING]
|
|
> Site remove (site directories, site database, `OpenLiteSpeed` configuration entries).
|
|
|
|
Example:
|
|
```bash
|
|
sudo kube.sh --remove example.com
|
|
```
|
|
***
|
|
|
|
### `--site status [domain]`
|
|
|
|
When specifying a domain, the following checks are performed:
|
|
* Presence of the domain in the `OpenLiteSpeed` configuration
|
|
* Presence of the domain in the list of stopped sites (OpenLiteSpeed)
|
|
* Presence of the domain directory in the virtual hosts directory (`vhostsPath`)
|
|
* Presence of the `WordPress` configuration file (`wp-config.php`)
|
|
* Checking the database name entry in the WordPress configuration and verifying its existence
|
|
* Checking the database user entry in the WordPress configuration and verifying its existence
|
|
* Checking database connectivity (retrieving the list of tables in the database)
|
|
* Checking the Redis user entry in the `WordPress` configuration and verifying its existence
|
|
* Checking connectivity to `Redis` (using the `PING` command)
|
|
* Checking the site's HTTP response
|
|
|
|
If the domain is not specified, the following checks are performed for all domains:
|
|
* Presence of the domain in the list of stopped sites (`OpenLiteSpeed`)
|
|
* Presence of the domain directory in the virtual hosts directory (`vhostsPath`)
|
|
* Presence of the `WordPress` configuration file (`wp-config.php`)
|
|
* Checking the database name entry in the `WordPress` configuration and verifying its existence
|
|
* Checking the database user entry in the `WordPress` configuration and verifying its existence
|
|
* Checking the `Redis` user entry in the `WordPress` configuration and verifying its existence
|
|
|
|
Example:
|
|
```bash
|
|
sudo kube.sh --site
|
|
sudo kube.sh --site example.com
|
|
```
|
|
|
|
Examples of responses:
|
|
```bash
|
|
🔹Site | example.com
|
|
✅example.com | Found in OpenLiteSpeed configuration
|
|
✅example.com | Directory: /_data/vhosts/example.com
|
|
✅example.com | Wordpress config: /_data/vhosts/example.com/www/wp-config.php
|
|
✅example.com | MariaDB database: example_com
|
|
✅example.com | MariaDB user: example_com
|
|
✅example.com | MariaDB tables: 10
|
|
✅example.com | Redis user: example_com
|
|
✅example.com | Redis ping: PONG
|
|
✅example.com | Site response: 200
|
|
```
|
|
|
|
```bash
|
|
🔹Site | all
|
|
## | Domain | CFG | DIR | OLS | MD | MU | RU | WP
|
|
--------------------------------------------------------------------------------
|
|
1 | example1.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
2 | example2.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
3 | example3.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
4 | example4.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
5 | example5.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
6 | example6.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅
|
|
7 | example7.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | --
|
|
8 | example8.com | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | --
|
|
9 | Example | --- | --- | ✅ | -- | -- | -- | --
|
|
```
|
|
|
|
Where:
|
|
- `CFG` - existence of the configuration file `$dataPath/config/<domain>.config`
|
|
- `DIR` - existence of the directory `$vhostsPath/<domain>`
|
|
- `OLS` - existence of an entry in the `OpenLiteSpeed` configuration
|
|
- `MD` - existence of the database (based on the entry in the configuration file)
|
|
- `MU` - existence of the database user (based on the entry in the configuration file)
|
|
- `RU` - existence of the Redis user (based on the entry in the configuration file)
|
|
- `WP` - existence of the WP configuration file `$vhostsPath/<domain>/www/wp-config.php`
|
|
)
|