Init Script Docs
Instance Opened时AutoDone环境Initialization、DatabaseImport、Issuance of certificates与Scheduled TasksConfiguration —— 让 智界互联 的Own NodeExample「交付即可用」。本页DescriptionInitialization script(Auto化Deployment Templates)的工作Method、MacrosType、SafetyStrategy与FAQ。
1Overview
Initialization script(Auto化部署)是 智界互联 面向 Own Node Provided out-of-the-box capability: solidify the repetitive work of "installing environment, leading database, assigning permissions, issuing certificates, hanging timed tasks" into a groupDeployment Templates, Instance opened by systemAutomatic sequential execution, the customer gets the instance and can deploy the business directly.
| Ability | Description |
|---|---|
| Preset initialization command | Update the software source, install dependencies, start the service, set the boot up |
| Automatically import database SQL | Automatic table building/initialization data scripting by template content |
| Issue HTTPS certificate | The certificate and private key are issued with the template and the site HTTPS configuration is completed. |
| Configure Scheduled Tasks | Write crontab or systemd timer, business timing task is ready with the instance |
| Directory Permission Template | Batch create directories and unify permissions and owners to avoid permission pitfalls |
2Execution timing and process
Initialization script atOpen your own package instancetriggered automatically without any action by the customer.The full link is as follows:
- The customer places the order and pays successfully, the order status changes to Paid;
- SystemScheduling available nodes: In the "Online and not full" node, the node with the least number of allocated instances is preferred;
- Take the node's quota and create an instance record (write IP, SSH port, login username, login password, operating system, expiration time, etc.);
- App Deployment Template: read all Enabled templates, ascending by template IDExecute in order;
- Once all are successful, mark the order as Completed, and write the opening log; if any link is abnormal, the order is marked as Failed Alarms are triggered and handled manually.
3Template Types and Examples
Deployment Templates ByTypeThere are four types of use:
| Type | Usage | Typical scenario |
|---|---|---|
script | Custom initialization script (multi-line shell, default type) | Environment initialization, installation dependencies, startup services |
command | Single command | Execute a system command, register a service |
sql | Preset Database SQL (Auto Import) | Build a database, build tables, initialize basic data |
dir_perm | Directory Permission Template | Batch create directories and unify permissions and owners |
script — Custom initialization script
#!/bin/bash set -e # 1) Update软件源并安装Commonly used组件 apt-get update -y apt-get install -y nginx curl git # 2) 创Building a website点目录并Settings属主 mkdir -p /www/wwwroot/site chown -R www-data:www-data /www/wwwroot/site # 3) 启动Services并Settings开机自启 systemctl enable nginx systemctl restart nginx echo "init done"
command — Single command
systemctl enable --now nginx
sql — provisioning database SQL
CREATE TABLE IF NOT EXISTS app_user (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
name VARCHAR(64) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
INSERT INTO app_user (name) VALUES ('demo');
dir_perm — directory permissions template
# Path Permissions 属主:属组 /www/wwwroot/site 755 www-data:www-data /www/wwwroot/site/runtime 775 www-data:www-data
IF NOT EXISTS、mkdir -p)to avoid errors when running again.4Node-level initialization script
In addition to the global deployment template, each own node can be configured with oneNode-level initialization scriptfor generic initialization of all instances on this node, for example:
- Replace the intranet software source/image source to speed up the dependent installation;
- Install a unified monitoring agent, log collector, or security component;
- Write the basic configuration of unified hosts, time zone, DNS, etc.
5Security & Isolation
To ensure the security of node and customer data, the initialization script and all remote command issuance follow these policies:
| Strategy | Description |
|---|---|
| Only own nodes | Upstream Resource InstancesForbiddenThe SSH of this platform is issued, and the back-end forces verification and records the interception log according to the source of the resource. |
| High Risk Command Interception | Instructions with high-risk segments are rejected by default |
| Parameter Filtering | Password and other parameters limit the character set (alphanumeric and _@!#$%^&*()-+=.,)to prevent command injection |
| Audit Log | The original instructions and execution results are written in the audit log and can be traced back |
| Connection current limiting | Remote connection setup timed out to avoid congestion |
High risk segments blocked (example):
6Dependencies and preconditions
The initialization script can be executed smoothly, provided that the following conditions are met:
- Node is online and not full: The node status is online, and the number of allocated instances does not reach the "maximum number of openable instances";
- Node SSH connectivity: The platform server can connect to the node through SSH (default port 22), and the authentication method supports the key or password;
- The server is capable of remote execution: PHP needs to be installed
php-ssh2Extensions; cannot issue commands to nodes when not installed, will give clear prompts and record logs; - Template Enabled: OnlyEnabled Statustemplate will be involved in the execution.
7Managing Templates
- Add template: Fill in the name, type and content and save it, it will be enabled by default;
- Adjust order: The template is executed in ascending order by ID, the earlier it is created, the earlier it runs; when there are multiple dependencies, please create them in order;
- Deactivate template: Set the template status to deactivated, that is, no longer valid for newly opened instances;
- Changes: The modified template is only valid for instances that are opened later.Does not affect opened instances。
8Scope of application
| Comparison term | Own Node | Upstream Resources | Wisdom Jane Magic Cube |
|---|---|---|
| Initialization script | Support(environment initialization/SQL import/certificate issuance/timing task) | Not supported, subject to upstream delivery |
| Execution method | Automatically executed by the platform according to the template when it is turned on | Automatically activated by upstream system |
| SSH Command Issue | Support (Security Whitelist) | Prohibited (back-end mandatory quarantine) |
| Self-service operation and maintenance | Restart/Reinstall/Refill/Renew | Renewal and upstream O&M entrance |