> For the complete documentation index, see [llms.txt](https://support.marscat.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.marscat.io/development-guide/backend-development/self-service-configuration-and-deployment.md).

# Self Service Configuration and Deployment

Self Service deployment mainly involves the configuration and operation of Self Service nodes, which are key components connecting P2P networks with application services.

## Environment Preparation

**Minimum Server Configuration Requirements**

* **CPU**: 2 cores or more
* **Memory**: 2GB RAM or more
* **Storage**: 20GB available disk space
* **Operating System**: Ubuntu 22.04 LTS or higher
* **Network**: Stable internet connection, no public IP or open ports required

## Dependency Software Installation

{% stepper %}
{% step %}

### Docker Environment

```bash
# Install Docker (version 20.10+)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Verify Docker installation
docker --version
```

{% endstep %}

{% step %}

### Docker Compose

```bash
# Install Docker Compose (version 1.28+)
sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# Verify installation
docker-compose --version
```

{% endstep %}

{% step %}

### Program Download and Extraction

```bash
# Download Self Service node package
wget https://github.com/RelayX-Protocol/Self-Service-Installer/releases/latest/download/selfservice.zip

# Extract package
unzip selfservice.zip
cd selfservice

# View directory structure
ls -la
```

{% endstep %}
{% endstepper %}

### Directory Structure Description

```makefile
selfservice/
├── selfservice.tar        # Self Service node Docker image
├── config.json            # Core configuration file
├── pango.conf             # Node certificate configuration
├── docker-compose.yml     # Docker Compose deployment file
└── data/                  # Data directory (needs to be created)
    ├── logs/              # Log folder
    ├── mongo/             # MongoDB data directory
    └── node/              # Node data directory
        └── userkey.json   # Self Service account
```

## Configuration Details

### config.json - Core Configuration

This is the main configuration file for the Self Service node, controlling node runtime parameters:

```json
{
    "logLevel": "info",
    "mongo": {
        "host": "mongodb-service",
        "port": "27017", 
        "username": "your_username",
        "password": "your_password",
        "dbName": "selfservice"
    },
    "port": "4567",
    "remoteService": "http://127.0.0.1:8088"
}
```

Key Parameter Descriptions:

* `logLevel`: Log level (debug/info/warn/error)
* `mongo`: MongoDB database connection configuration for storing node data and message cache
* `port`: Self Service node listening port
* `remoteService`: Your application service address, supports HTTP/HTTPS

### pango.conf - P2P Network Configuration

This file configures Self Service node connection parameters with RelayX Network:

```ini
[global]
localsrvport=4568
t2trepeater=14ACRC3zwcqcsytNYhc6xT4hUtzhbGAVcK
nodserverurl=http://127.0.0.1:4567
remotesrvdomain=x08.a867744.com
routecert=xxxxxx
routecertexpired=xxxxxx
```

Parameter Descriptions:

* `localsrvport`: P2P network communication port
* `t2trepeater`: Network relay identifier, assigned by official
* `nodserverurl`: Must match the port in config.json
* `routecert`: Service certificate from Self Service certificate (Base64 encoded format)
* `routecertexpired`: Certificate expiration time (Unix timestamp, seconds)

### docker-compose.yml - Container Orchestration Configuration

Docker Compose configuration file defining the complete service stack:

```yaml
version: '3.8'
services:
  mongodb-service:
    image: mongo:6.0.14
    container_name: mongodb-service
    restart: always
    ports:
      - "27017:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: your_user
      MONGO_INITDB_ROOT_PASSWORD: your_secure_password
    volumes:
      - ./data/mongo:/data/db
    networks:
      - relayx-network

  self-service:
    image: relayx/selfservice:v1.0
    container_name: self-service  
    restart: always
    depends_on:
      - mongodb-service
    ports:
      - "4567:4567"
      - "4568:4568"
    volumes:
      - ./data/logs:/app/logs
      - ./config.json:/app/config.json
      - ./pango.conf:/app/self_service/pango.conf
      - ./data/node/userkey.json:/app/self_service/userkey.json
    networks:
      - relayx-network
      
networks:
  relayx-network:
    driver: bridge
```

## Deployment Process

{% stepper %}
{% step %}

### Pre-create Necessary Files and Directories

```bash
# Create data directory structure
mkdir -p data/logs data/mongo data/node

# Place the userkey.json file generated by relayx-cli create self into the data directory
# userkey.json file is located in {RelayAppAddress}.config/ directory

# Set correct file permissions
chmod 644 config.json pango.conf data/node/userkey.json
chmod 755 data data/logs data/mongo data/node
```

{% endstep %}

{% step %}

### Configure Files

Modify the database password and application service address in `config.json` according to the actual environment, as well as the Self Service certificate information in `pango.conf`.
{% endstep %}

{% step %}

### Load Docker Image

```bash
# Load Self Service node image
docker load -i selfservice.tar

# Verify image loaded successfully
docker images | grep selfservice
```

{% endstep %}

{% step %}

### Start Services

```bash
# Start all services
docker-compose up -d

# Check service status
docker-compose ps

# View logs in real-time
docker-compose logs -f
```

{% endstep %}

{% step %}

### Verify Deployment

```bash
# Check service status
curl -f http://localhost:4567/health

# Get Service Key (for frontend integration)
curl http://127.0.0.1:4567/getServiceKey
```

Health Check Interface Response Description:

Status codes returned by the `/health` interface:

* 1: Startup successful, all components running normally
* 2: Database connection failed, check MongoDB configuration and connection
* 3: Node connection failed, check P2P network configuration and certificates

Also returns the number of registered Self Service personnel, including successfully registered and failed users.
{% endstep %}
{% endstepper %}
