Help Documentation

Init Script Docs

Instance Opened时AutoDone环境Initialization、DatabaseImport、Issuance of certificates与Scheduled TasksConfiguration —— 让 智界互联 的Own NodeExample「交付即可用」。本页DescriptionInitialization script(Auto化Deployment Templates)的工作Method、MacrosType、SafetyStrategy与FAQ。

Only own nodesActivate and ExecuteCategory 4 TemplatesHigh Risk Command InterceptionFull audit

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.

AbilityDescription
Preset initialization commandUpdate the software source, install dependencies, start the service, set the boot up
Automatically import database SQLAutomatic table building/initialization data scripting by template content
Issue HTTPS certificateThe certificate and private key are issued with the template and the site HTTPS configuration is completed.
Configure Scheduled TasksWrite crontab or systemd timer, business timing task is ready with the instance
Directory Permission TemplateBatch create directories and unify permissions and owners to avoid permission pitfalls
Scope of application:Above abilityOnly for own nodes(This platform builds/controls its own resources).The upstream "Zhi Jane Magic Cube" resources are opened and delivered by the upstream, and are not issued as initialization scripts on this platform.

2Execution timing and process

Initialization script atOpen your own package instancetriggered automatically without any action by the customer.The full link is as follows:

  1. The customer places the order and pays successfully, the order status changes to Paid;
  2. SystemScheduling available nodes: In the "Online and not full" node, the node with the least number of allocated instances is preferred;
  3. Take the node's quota and create an instance record (write IP, SSH port, login username, login password, operating system, expiration time, etc.);
  4. App Deployment Template: read all Enabled templates, ascending by template IDExecute in order;
  5. 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.
Instance first dropped off at Running, and then execute the deployment template;Opened instances will not be executed retroactivelySubsequently added macros.If the template fails in the middle, the remaining templates will continue to try, and the failure reason will be written to the deployment log.

3Template Types and Examples

Deployment Templates ByTypeThere are four types of use:

TypeUsageTypical scenario
scriptCustom initialization script (multi-line shell, default type)Environment initialization, installation dependencies, startup services
commandSingle commandExecute a system command, register a service
sqlPreset Database SQL (Auto Import)Build a database, build tables, initialize basic data
dir_permDirectory Permission TemplateBatch 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
Above isSchematic; The template content is unifiedly maintained by the platform operation and maintenance, and the actual implementation is subject to online configuration.Scripts are advised to follow the Idempotent, Repeatable principle (if used 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.
Node-level scripts work with global templates:Node levelResponsible for "general preparation on this machine",Global TemplatesResponsible for “Business initialization for each instance”.

5Security & Isolation

To ensure the security of node and customer data, the initialization script and all remote command issuance follow these policies:

StrategyDescription
Only own nodesUpstream 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 InterceptionInstructions with high-risk segments are rejected by default
Parameter FilteringPassword and other parameters limit the character set (alphanumeric and _@!#$%^&*()-+=.,)to prevent command injection
Audit LogThe original instructions and execution results are written in the audit log and can be traced back
Connection current limitingRemote connection setup timed out to avoid congestion

High risk segments blocked (example):

rm -rfmkfsdd ifiptablesformatchmod -R 777 /wget http://curl http://mv /shutdownreboot -fkill -9 1
To perform O&M operations beyond the whitelist, submit a ticket that will be handled manually by the platform engineer in a controlled environment.

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-ssh2 Extensions; 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.
If the instance opens successfully but the initialization content is not valid, it is usually "node unreachable/SSH authentication failed/php-ssh2 extension missing".The work order can be submitted with the instance number, and the platform will check the deployment log for post-processing.

7Managing Templates

  1. Add template: Fill in the name, type and content and save it, it will be enabled by default;
  2. 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;
  3. Deactivate template: Set the template status to deactivated, that is, no longer valid for newly opened instances;
  4. Changes: The modified template is only valid for instances that are opened later.Does not affect opened instances。
The template is unifiedly maintained by the platform operation and maintenance, and the customer does not need to configure it.If you want to provision specific initialization content for the business (such as fixed directory, initialization SQL, boot-up service), you can submit a work order to explain the requirements.

8Scope of application

Comparison termOwn NodeUpstream Resources | Wisdom Jane Magic Cube
Initialization scriptSupport(environment initialization/SQL import/certificate issuance/timing task)Not supported, subject to upstream delivery
Execution methodAutomatically executed by the platform according to the template when it is turned onAutomatically activated by upstream system
SSH Command IssueSupport (Security Whitelist)Prohibited (back-end mandatory quarantine)
Self-service operation and maintenanceRestart/Reinstall/Refill/RenewRenewal and upstream O&M entrance

9FAQ

Q1: Will the instance I buy automatically execute the initialization script?
If your instance is fromOwn NodePackage, which automatically executes the enabled deployment template when it is activated;Upstream resourcesThe instance is delivered upstream and does not execute the platform initialization script.
Q2: Why didn't I see the initialization content after opening it?
Possible reasons: node unreachable/SSH authentication failed/server not installed php-ssh2 extension/template not enabled. Please submit a ticket with the instance number and we will check the deployment logs.
Q3: Will the failure to execute the template affect the use of the instance?
The instance itself has been created, and the failure of a single template will be recorded and skipped, which does not affect the basic availability of the instance, but the corresponding initialization content will not take effect and needs to be manually made up.
Q4: Can I execute my custom script?
You can submit a ticket to explain the requirements, and the platform configures the template within the scope of the controlled whitelist; instructions involving high-risk operations (such as formatting, firewall rule adjustment) will be intercepted by the security policy.
Q5: Will the initialization script be re-executed after the system is reinstalled?
The reinstallation system will go through the instance reinstallation process. Whether the deployment template is reapplied or not, please refer to the platform's current strategy. If you need to reinitialize, please submit a ticket.
Q6: Will the new template work for my existing instances?
No. The template is only valid for new instances that are opened later, and open instances are not executed retroactively.
Smart Support×
Hello,当前人工不Online,现在由AI为您解答问题