Skip to content

Service Plugin Specifications

Document VersionContent RevisionReviserRevision Date
V1.0Added basic content for plugin specificationsWang Yao2023-11-25
V1.1Added description for HooksWang Yao2024-01-12
V1.2Added description for visual configuration standardsGuochenghao2024-02-22

Basic Requirements

There are no strict programming language requirements for service plugins; you can choose an appropriate programming language. However, please pay attention to the following points:

  1. The program should run directly on the target device. If it relies on a runtime environment, it should operate normally once the environment is configured.
  2. Avoid relying on the system's dynamic link libraries. If system dynamic link libraries are used, ensure that the corresponding libraries are also installed on the target device.
  3. If the program depends on dynamic libraries, it can use relative paths to place the dynamic library alongside the program.
  4. If the program is written in a compiled language (e.g., C, C++, Go), it needs to be compiled into an executable file.
  5. If the program is written in an interpreted language (e.g., Python, JS, Java), it needs to declare the interpreter type or package the interpreter together with the program.
  6. The program and its necessary dependencies must be grouped together.
  7. Service management only supports computers running Windows, Linux, and macOS; it does not support mobile platforms (Android, iOS).
  8. It supports running service management on domestic operating systems, such as Kylin and UOS.
  9. Programs with a GUI (e.g., WPF, Qt, Unity) are not supported.
  10. If it's a B/S architecture program, it's feasible to internally provide a web service on the server.
  11. Services running in nohup mode are not supported.

Program Development Recommendations

  1. It is recommended to store program data in the user directory or the program’s relative directory, rather than an absolute path.
  2. Programs can access the current user directory using HOME or USERPROFILE.
  3. If the configuration and data files are stored in a relative path, they need to be declared in the description file's datas field to prevent them from being overwritten during program updates.
  4. It is advisable to capture program termination signals to save relevant data and close file connections before the program ends, to prevent data file corruption.
  5. If the program requires a longer time to process the finalization tasks, please adjust the stop_timeout duration to ensure there is ample time to handle this, otherwise, if the program takes too long to stop, it will be considered unresponsive, triggering forced termination logic.
  6. The program may enable any number of subprocesses, but it should not start processes that do not have a parent-child relationship with the main process. If service management cannot accurately determine the subprocess's relationship, it may fail to terminate the process correctly.
  7. The program should not run in nohup mode.
  8. The program does not need to set up process guardians, as service management itself comes with process guardian functionality.

Plugin Description Specification daemon.json

Complete example of a description file:

json
{
  "id": "",
  "interpreter": "node",
  "interpreter_self": "",
  "interpreter_args": [],
  "path": "./ccs_pro.js",
  "pkg": "com.sansi.ccs-pro",
  "version": "2.2.27",
  "log_file": "",
  "pid_file": "",
  "icon": "favicon.ico",
  "name": "Universal Central Control",
  "description": "Universal Central Control System (CCS Pro)",
  "args": [],
  "auto_start": true,
  "auto_restart": true,
  "restart_max": 3,
  "restart_delay": 0,
  "cwd": "",
  "env_vars": [],
  "port": 3436,
  "port_type": "HTTP",
  "os": "",
  "arch": "",
  "is_match": true,
  "stop_timeout": 5000,
  "doc": "https://ccs-pro.sansi.io/",
  "api_doc": "http://{{currentIp}}:{{currentPort}}/docs/api/",
  "homepage": "http://{{currentIp}}:{{currentPort}}",
  "configs": [
    {
      "title": "Server Configuration",
      "type": "json",
      "path": "{{home}}/Sansi/CCS-Platform/config/ccs-server.json",
      "schema": "{{app}}/config/ccs-server.schema.zh_CN.json"
    },
    {
      "title": "Client Configuration",
      "type": "json",
      "path": "{{home}}/Sansi/CCS-Platform/config/ccs-editor.json",
      "schema": "{{app}}/config/ccs-editor.schema.zh_CN.json"
    }
  ],
  "gateway": [
    {
      "enable": true,
      "gateWayType": "HTTP",
      "apiPath": "http://127.0.0.1:3436",
      "apiPrefix": "/sansi/ccs",
      "removePrefix": false
    }
  ],
  "datas": [
    "{{app}}/date/*", "{{app}}/config/app.json"
  ],
  "logs": [
    "{{app}}/logs/*"
	],
  "firewall_enable": true,
  "firewall_ports": [
    "3436"
  ],
  "hooks": [
  	{
  		"type": "HTTP",
  		"stage": "PreStop",
  		"timeout": 10000,
  		"data": {
				"http": {
					"method": "GET",
					"url": "http://{{currentIp}}:{{currentPort}}/test"
				}
  		}
  	},
    {
      "type": "HTTP",
      "stage": "PreUnInstall",
      "timeout": 10000,
      "data": {
        "http": {
          "method": "GET",
          "url": "http://127.0.0.1:1280/sansi/daemon/api/v1/daemon/config"
        }
      }
    }
  ]
}

Field Descriptions

Field Name (json)Field TypeDefault ValueReference ValuesField Description
idstringQwOUYfIYProgram ID (auto-generated, cannot be modified through config update)
interpreterstringnode / java / pythonInterpreter, such as python3, node, java, can be empty
interpreter_selfstring./bin/node.exeSelf-provided interpreter for the service
interpreter_args[]string[]["-jar","-Dfile.encoding=utf-8"]Arguments for the interpreter
pathstring./app.jsProgram path (cannot be modified through config update)
pkgstringcom.sansi.demoUnique identifier for the program
versionstring"1.0.0"1.0.0Program version number (cannot be modified through config update)
log_filestring"/logs.log"""Log file location (cannot be customized or modified through config update)
pid_filestring"/pid"""PID file (cannot be customized or modified through config update)
iconstring./icon.pngProgram icon
namestringXX ServiceProgram name
descriptionstringService providing XX functionalityProgram description
args[]string[]["--port", "8080"]Program arguments
auto_start*booltruetrueAutomatically start; this application will start automatically after install and daemon startup
auto_restart*booltruetrueAutomatically restart
restart_max*int33Maximum restart attempts; 0 means unlimited
restart_delay*int01000Restart delay time, in milliseconds
cwdstring"./"Program working directory
env_vars[]string[]["KEY=sdfsdfsss"]Environment variables
portint3436Running port
port_typestringHTTP / TCP / UDP / WebsocketType of the running port
osstring"" / windows / linux / darwinSupported operating systems; if empty indicates no OS restrictions
archstring"" / amd64 / arm64Supported CPU architecture; if empty indicates no architecture restrictions (amd64 implies the same as x64, x86-64 cannot be written as x64)
is_matchbooltrueWhether the operating system and architecture are compatible (calculated automatically, no setup needed)
stop_timeout*int50000Timeout duration when stopping the service, in milliseconds
docstringhttps://ccs-pro.sansi.io/Documentation for the current service; can use currentPort to represent the current service's IP and currentPort for its port
api_docstringhttps://ccs-pro.sansi.io/API documentation for the current service; similar usage for currentPort
homepagestringhttps://ccs-pro.sansi.io/Home page address for the current service; similar usage for currentPort
configs[]Config[]See the above exampleList of program configuration information; can use app to represent current program directories, and home to represent user directories accessible to the program.
datas[]string[]["/data/*",
"/config/conf.json"]
List of data for the current program; this directory will be retained during program upgrades. Suitable for programs and data located in relative paths.
logs[]string[]["/logs/*"]List of logs for the current program; this directory will also be retained during upgrades, suitable for programs and logs located in relative paths.
firewall_enablebooltruetrueWhether to enable the firewall
firewall_ports[]string[]["1234", "3456-3467", "8033"]Open ports for the firewall, inbound direction
hooks[]Hook[]See the above exampleCallback properties for various stages of service operation

Gateway

The gateway is used to apply for request proxies in Xuandao Intelligent Control, without exposing the real address to the outside world. Each service can apply for multiple gateway proxies.

In the entire Xuandao Intelligent Control platform, all gateway prefixes must be unique.

json
{
  "gateway": [
    {
      "enable": true,
      "gateWayType": "HTTP",
      "apiPath": "http://127.0.0.1:3436",
      "apiPrefix": "/sansi/ccs",
      "removePrefix": false
    }
  ]
}

Field Descriptions

FieldTypeMeaningSupported Parameters
enableboolWhether to enable the gatewaytrue / false
gateWayTypestringGateway typeHTTP、WebSocket
apiPathstringReal address
removePrefixboolWhether to remove the prefix

Hooks

Hooks are callback properties for the various stages of service operation. Currently, they only support HTTP calls. Note that in their URLs, the fields and are supported, where currentIp represents the IP address of the current service, and currentPort represents the currently opened port of the service.

A single hook entry looks like this:

json
{
  "type": "HTTP",
  "stage": "PreStop",
  "timeout": 10000,
  "data": {
    "http": {
      "method": "GET",
      "url": "http://{{currentIp}}:{{currentPort}}/test"
    }
  }
}

Field Descriptions

FieldTypeMeaningSupported Parameters
typestringHook typeHTTP
stageintHook stagePreInstall, PostInstall, PreUnInstall, PostUnInstall, PreStart, PostStart, PreStop, PostStop, PreBackup, PostBackup, PreRestore, PostRestore
timeoutintTimeout duration for this stage (milliseconds)Less than or equal to 0 will take the default value of 10 seconds
dataHookDataHook dataSee below
data.httpHookDataHttpHTTP type dataCurrently does not support calls with a body
data.http.methodstringRequest methodGET, POST, PUT, DELETE
data.http.urlstringRequest addressSupports and fields; currentIp represents the IP address of the current service, and currentPort represents the currently opened port of the service

Visual Configuration Specification schema.zh_CN.json

Below is the configuration file for the server. default_config.png

Effect of the visualized backend. read_config.png

Use schema.zh_CN.json to explain the fields in the configuration file.

schema.zh_CN.json 示例

json5
[
  {
    "props": {
      "header": "Central Control Server"
    },
    "formProps": {
      "labelWidth": "100px"
    },
    "fields": [
      {
        "name": "auth_enable",
        "component": "switch",
        "formProps": {
          "label": "Enable User Authentication:"
        },
        "inputProps": {}
      },
      {
        "name": "database",
        "component": "select",
        "formProps": {
          "label": "Authentication Method:"
        },
        "inputProps": {
          "options": [
            {
              "label": "Built-in Database",
              "value": "nedb"
            },
            {
              "label": "User Authentication Service",
              "value": "oauth"
            }
          ]
        }
      },
      {
        "name": "oauth_url",
        "component": "input",
        "formProps": {
          "label": "User Authentication Service:"
        },
        "inputProps": {}
      }
    ]
  }
]

Edit daemon.json,load schema.zh_CN.json file config_schema.png

The directory structure is as follows: file_path.png

Default Parser Types:

componentSupported Field PropertiesDescription
inputstringText input box
linkstringLink
selectstringContent selector (single choice)
switchbooleanSwitch button
date-pickerstringDate picker
time-pickerstringTime picker
color-pickerstringColor picker
ratenumberRating