First: how a script gets used
The Automation Scripts area at the bottom of the certificate form has two slots. Once your script is in place it shows up in the matching dropdown:
- Issuing script (
# type: issuing): runs during validation and makes the CA validation pass, for example by adding a validation record at your DNS provider. - Post-issuance script (
# type: post): runs after every issue and every renewal and sends the new certificate where it needs to go, for example a cloud provider, another server, or a service reload.
Users pick a script in the form and fill in the fields declared in its header; Nodekeeper calls the script with positional arguments (and environment variables) when it is time and records the result in the certificate details. If you have not used the bundled scripts yet, read Certificate Scripts: Validate and Deploy and Free SSL Certificate Guide first.
- Script
- A text file with a list of commands. Nodekeeper runs it for you when it is time. All scripts in this guide are Bash scripts (extension
.sh). - Issuing script
- Runs while a certificate is being requested, during validation, and helps the CA validate, for example by adding a validation record at your DNS provider.
- Post-issuance script
- Runs after the certificate is issued and after every renewal and sends the new certificate where it is needed, for example another server, then reloads a service.
- Header directives
- The first lines of the script, comments such as
# name:and# type:. The panel reads them to decide the script's name, which dropdown it appears in and which fields the user fills in. - Positional arguments (
$1,$2...) - The values Nodekeeper hands to the script, in order.
$1is the first,$5the fifth. This is how the script learns the domain and where the certificate file is. - Exit code
- A number the script returns when it ends.
0means success; anything else means failure. Nodekeeper uses it to decide whether to retry.
-
The two script slots
Add a certificate in Domains → Certificates; the Automation Scripts area is at the bottom of the dialog: the issuing script on the left, the post-issuance script on the right. Every executable script in
shell/ssl/appears in one of the two dropdowns, according to its# type:line.
Your first script: from an empty file to a run in the panel
Start with a read-only post-issuance script: it only prints the new certificate's domain and expiry date and changes nothing, so it needs no administrator approval and is the safest one to practise with. After these five steps you have gone through the whole chain (write the script, put it on the server, pick it in the panel, it runs, read the result); every other script works the same way.
-
Log in over SSH and go to the script folder
Scripts must be in the
shell/ssl/folder under the Nodekeeper install directory. The default install directory is/opt/nodekeeper; if you changed it at install time, use yours. Log in as root over SSH and run:cd /opt/nodekeeper/shell/ssl ls
You should see:A list of
.shfiles such asaws_acm.sh,cloudflare_dns.shandssh_deploy.sh: these are the bundled scripts in the panel's dropdowns. Your script goes here too. -
Create the script file
Copy the whole block below into the terminal and press Enter. It creates
my_first.shin the current folder: everything between the line aftercat > my_first.sh <<'EOF'and the finalEOFis the file content. If you prefer an editor, runnano my_first.sh, paste only the middle part, pressCtrl+Oto save andCtrl+Xto quit.cat > my_first.sh <<'EOF' #!/bin/bash # name: 我的第一个脚本 / My first script # tip: 只读:打印新证书的域名和到期时间,不改任何东西。/ Read-only: prints the domain and expiry date of the new certificate, changes nothing. # type: post set -euo pipefail domain="${1%%[ ,]*}" cert_file="${5:-}" [[ -r "$cert_file" ]] || { echo "找不到证书文件 / certificate file not found: $cert_file" >&2; exit 1; } echo "域名 / domain: $domain" openssl x509 -in "$cert_file" -noout -subject -enddate echo "完成 / done" EOFThis line What it does and why cat > my_first.sh <<'EOF'Writes everything up to EOFintomy_first.sh. The quotes in'EOF'keep$1and friends as they are instead of replacing them right away.#!/bin/bashThe first line must name the interpreter: it tells the system to run the file with Bash. # name: 我的第一个脚本 / My first scriptThe name shown in the dropdown. Write it in both languages so both panel languages read well. # tip: ...The description shown under the dropdown when the script is selected. Say what it does and whether it changes anything. # type: postPuts it in the Post-issuance script dropdown. With issuingit appears in the During issuance dropdown instead.set -euo pipefailSafety switch: stop at the first failing command (with a non-zero exit) and treat unset variables as errors. Almost every script should have it. domain="${1%%[ ,]*}"$1is the certificate's domain. For a multi-domain certificate it is a list;%%[ ,]*cuts everything from the first space or comma, leaving the first domain.cert_file="${5:-}"$5is the path of the certificate file on this server.:-means "empty if not given", soset -udoes not complain.[[ -r "$cert_file" ]] || { echo "..." >&2; exit 1; }Checks the certificate file exists and is readable; if not, prints the reason and exits with 1. The panel then shows Failed with that reason.openssl x509 -in "$cert_file" -noout -subject -enddateReads the certificate with openssl and prints its subject (domain) and expiry date. Read-only. echo "完成 / done"Prints a final line. When the script reaches the end normally, the exit code is 0: success.You should see:Run
lsagain:my_first.shis in the list. -
Make it executable and try it by hand first
A new file cannot be executed until you allow it. Then call it the way Nodekeeper does: argument 1 is the domain, 5 the certificate file path, 6 the key file path, with
''(empty) placeholders in between. Find the two paths in the panel: Domains → Certificates, click View on a certificate; the certificate file path and private key file path are in the details (below).chmod +x my_first.sh ./my_first.sh example.com '' '' '' /path/to/cert.pem /path/to/key.key
This line What it does and why chmod +x my_first.shMakes the file executable. Without it, Nodekeeper reports Permission deniedwhen it runs the script../my_first.sh example.com '' '' '' ...Replace example.comwith your domain and the two paths with the ones from the details. The three''fill positions 2, 3 and 4 (certificate text, chain, key text, not used here) so the certificate file path lands in position 5.
$ chmod +x my_first.sh $ ls -l my_first.sh -rwxr-xr-x 1 root root 517 Nov 28 10:46 my_first.sh $ ./my_first.sh ssl-demo.vps.tz '' '' '' '/opt/nodekeeper/certs/ssl-demo.vps.tz,www.ssl-demo.vps.tz/ssl-demo.vps.tz,www.ssl-demo.vps.tz.pem' '/opt/nodekeeper/certs/ssl-demo.vps.tz,www.ssl-demo.vps.tz/ssl-demo.vps.tz,www.ssl-demo.vps.tz.key' 域名 / domain: ssl-demo.vps.tz subject=CN=ssl-demo.vps.tz notAfter=Feb 25 23:59:59 2027 GMT 完成 / done
If a path in the details does not start with / (for example certs/example.com/example.com.pem), it is relative to the install directory: put /opt/nodekeeper/ in front when you run the script by hand. Put a path with commas (multi-domain certificates) in single quotes.
You should see:The terminal prints the domain line,
subject=CN = ...,notAfter=...(the expiry date) and the done line. Runecho $?right after: it shows0, the exit code of a success. -
Pick it in the panel
Back in the panel, open Domains → Certificates, click Add Certificate and scroll to Automation Scripts at the bottom of the dialog. In the Post-issuance script dropdown on the right, find "我的第一个脚本 / My first script" (the name from your
# name:line), select it, fill in the rest of the certificate and save. No restart needed: once the file is in the folder, it is in the dropdown.A script can only be chosen when you add a certificate; an existing certificate's script cannot be changed. To practise, import a self-signed certificate as an Existing Certificate (that is what the screenshot does), so you don't wait for a CA.
You should see:The text from your
# tip:line appears under the dropdown. -
Run it and read the result in the certificate details
Once the certificate is issued, the script runs by itself, and again after every renewal. If you don't want to wait: click View on the certificate in the list, then Run now in the Post-issue script section (at most once per 30 seconds per certificate), wait a few seconds and click Refresh run record. Last run shows the run time, result, exit code and the end of the script output.
You should see:Result Succeeded, exit code
0, and the same output you saw in the terminal. The whole chain works.
Something wrong? Check this table
| What you see | Why | What to do |
|---|---|---|
| I can't find where to choose a script on an existing certificate | A script is chosen when the certificate is added; it cannot be changed in the details. | Add another certificate for the domain with the script selected; to practise, import a self-signed certificate as an Existing Certificate. |
| My script is not in the dropdown | The file is not in shell/ssl/ or its extension is not .sh; or # type: says issuing, so it is in the During issuance dropdown on the left. | Check the name with ls -l /opt/nodekeeper/shell/ssl/; check the # type: post line near the top. |
Run failed with Permission denied | The file is not executable. | chmod +x /opt/nodekeeper/shell/ssl/my_first.sh, then Run now. |
/bin/bash^M: bad interpreter | The file was edited on Windows and every line ends with an extra carriage return (CRLF). | Run sed -i 's/\r$//' my_first.sh; from now on edit on the server with nano / vim, or set your editor's line endings to LF. |
openssl: command not found | The command is not installed on the server. | Debian / Ubuntu: apt install openssl; CentOS / Rocky: dnf install openssl. In your own scripts, check every command you use exists on the server. |
| The manual test prints "certificate file not found" | Argument 5 is in the wrong position (one '' missing) or the path is wrong. | Count: three '' after the domain, then the certificate file path. |
| The result stays Failed and it runs again every minute | The script's exit code is not 0. Nodekeeper retries every minute until it succeeds. | Read the last lines of the output in Last run, fix the script, then Run now. |
Where scripts live and how to write the header
- Put the file in
shell/ssl/under the Nodekeeper install directory, name it with letters, digits and. _ -only, extension.sh, and make it executable withchmod +x. It appears in the dropdown at once, no restart. - Start with an interpreter line such as
#!/bin/bash. The script runs as the user Nodekeeper runs as (normally root), so only people who can write to that directory can add scripts; write it as code that runs as root.
From the second line on, one # key: value per line. Only lines that start with # count; text in the script body that looks like a directive is ignored.
| Directive | Meaning |
|---|---|
# name: text | The name shown in the dropdown; default is the file name. |
# tip: text | A paragraph shown under the selector: what it does, what it touches, what to fill in. |
# type: post | post = runs after issue / renewal; issuing (default) = runs during validation. For issuing-script arguments see Issuing scripts below. |
# param.key: label|required=true|default=value|password=true | Declares an input for the user, in the order written. The key uses letters, digits and underscores; every option after the label is optional; required accepts true/1/yes/on; an empty default= is ignored, and neither the value nor the label may contain | (a colon in the label is fine). password=true turns it into a password field, stored encrypted and shown afterwards only as ******. |
# secrets: env | Password parameters (password=true) are not put on the command line but in the environment variable NK_PARAM_<KEY UPPERCASE>. Use it whenever you have a password or key. |
# approval: required | The script runs only after an administrator approves the certificate's parameter set in the panel (see approval below). Scripts without this line need no approval. |
Give every password=true parameter a name that looks like a secret (*_password, *_token, *_secret_key, *_key): the audit log masks by name.
-
A header with parameters, line by line
Below is the header of a script that asks the user for three values. Once the header is written, the panel builds the form from it; nothing in the panel needs changing.
#!/bin/bash # name: 上传证书到我的服务器 / Upload certificate to my server # tip: 签发或续期后把证书上传到指定服务器;会碰到别的机器,需要管理员核准。/ Uploads the certificate to a server after issue or renewal; reaches another machine, so it needs approval. # type: post # approval: required # secrets: env # param.host: 服务器地址 / Host|required=true # param.user: 用户名 / User name|required=true|default=deploy # param.password: 密码 / Password|required=true|password=true
This line What it does and why # approval: requiredThe script reaches another machine, so it only runs after an administrator approves it in the panel (see approval). # secrets: envPassword parameters go through environment variables instead of the command line (other users on the machine can see a running command line). # param.host: 服务器地址 / Host|required=trueAdds a required field "Host" to the form. It is the first declared parameter, so the script reads it as $7.# param.user: 用户名 / User name|required=true|default=deployThe second parameter ( $8), pre-filled withdeploy; the user can change it.# param.password: 密码 / Password|required=true|password=trueA password field: stored encrypted, shown as ******after saving. Because of# secrets: envits position$9is empty and the real value is inNK_PARAM_PASSWORD.You should see:Select this script in the certificate form and three fields appear: Host, User name (pre-filled with deploy) and Password (masked while typing).
-
Declared parameters become the form
Each
# param.key: label|optionsline becomes one input in the form once the script is selected, in header order;required=truefields must be filled anddefault=values are pre-filled. Below is the form of the bundled SSH deploy script: every input matches oneparamline in its header.
What a post-issuance script receives
A post-issuance script gets positional arguments, the fixed ones first, then your declared parameters in the order declared.
| Position | Content |
|---|---|
$1 | The certificate's domain(s), separated by comma or space (use the first for file names) |
$2 | The certificate (PEM text; on a re-run, the site certificate plus the chain) |
$3 | The intermediate chain (PEM, may be empty) |
$4 | The private key (PEM text) |
$5 | Path of the certificate file on this machine |
$6 | Path of the private key file on this machine |
$7 onwards | Your declared parameters, in header order |
- Read the files
$5and$6, not the PEM text in$2and$4. Command-line arguments can be read by other users on the same machine while the script runs; file paths are harmless. - With
# secrets: env, the argument list is rebuilt from the header: for everyparamline, in order, the stored value (or itsdefault, or an empty string) goes to that position, so later edits to a script's parameter list never shift the values of older certificates. A password parameter keeps its position but holds an empty string; read the environment variableNK_PARAM_<KEY UPPERCASE>instead, for example${NK_PARAM_FTP_PASSWORD:-$9}(falling back to the argument when you run it by hand), thenunsetit. - Values never contain line breaks or control characters. Still validate every value before using it in a URL, path or command: a parameter is user input.
- The three bundled deploy scripts (AWS ACM, Tencent Cloud SSL, SSH deploy) honour
NK_SSL_SCRIPT_DRYRUN=1(check input, print the plan, no network); worth copying so you can try it first. The other bundled scripts do not, and your own script has to implement the check itself (the FTPS example below does), so never expect a dry run from a script you do not know.
- PEM
- The usual text format for certificates and keys, starting with
-----BEGIN CERTIFICATE-----..pem,.crtand.keyfiles usually hold it. - Certificate chain (intermediates)
- The certificates that prove the CA that signed yours is trusted. Browsers need site certificate + chain to validate, so you normally deploy the full chain.
- Environment variable
- A set of name=value pairs a program gets at start. Only that program and the ones it starts can see them, unlike command-line arguments, which other users can see.
-
Read the arguments in the script
Read the arguments you need into named variables at the top of the script, so you don't have to remember what
$7is later. This continues the header from the previous section (three declared parameters):domain="${1%%[ ,]*}" # 第一个域名 / the first domain cert_file="${5:-}" # 证书文件(含证书链)/ certificate file (with chain) key_file="${6:-}" # 私钥文件 / private key file host="${7:-}" # 声明的第 1 个参数 / 1st declared parameter user="${8:-}" # 声明的第 2 个参数 / 2nd declared parameter password="${NK_PARAM_PASSWORD:-${9:-}}"; unset NK_PARAM_PASSWORDThis line What it does and why domain="${1%%[ ,]*}"The first domain, handy for naming uploaded files. cert_file="${5:-}"The certificate file path (site certificate + chain). Read the file; don't use the PEM text in $2.key_file="${6:-}"The private key file path. Read the key on this machine only; never print it or put it on a command line. host="${7:-}" / user="${8:-}"Declared parameters 1 and 2, in the order of the header's paramlines.password="${NK_PARAM_PASSWORD:-${9:-}}"; unset NK_PARAM_PASSWORDPrefer the environment variable (when Nodekeeper runs it), fall back to $9(your manual test);unsetright away so commands started later don't inherit it.
Issuing scripts: automate validation (DNS example)
An issuing script runs while the certificate is waiting for validation: it runs once at the first check of each pending certificate and not again after it succeeds; if it fails, the reason shows in the certificate's renewal status and it is tried again at the next check. For a multi-domain certificate with DNS validation the script is called once per domain, with that domain in $1. Issuing scripts are not approved by anyone, so a script that declares # approval: required cannot be used in this slot.
Arguments: $1 is the domain (may start with *. for a wildcard), $2 is the validation method, then the method-specific items, then the "service config path" (the placeholder 8888888 when the certificate has none: never treat it as a real path), and finally your declared parameters (in header order; with # secrets: env password parameters come through the environment here too).
$2 method | Following arguments |
|---|---|
dns | $3 record type (currently always cname), $4 record host name (full name such as _xxxx.example.com), $5 record value, $6 service config path, your parameters from $7 |
http / https | $3 web root, $4 validation URL, $5 validation file content, $6 service config path, your parameters from $7 |
email | $3 the chosen validation address, $4 service config path, your parameters from $5 |
email_builtin | $3 validation address, $4 MX host @, $5 MX target mx1.host.mw, $6 MX priority 10, $7 service config path, your parameters from $8 |
- Check the method first: if the script only supports DNS, fail with a clear message when
$2is notdns. - Make it safe to run again: if a record with the same name exists, update it instead of adding a second one (two CNAMEs on one name are usually rejected by the DNS provider).
- Argument values: Nodekeeper never passes a parameter value that starts with
-or contains a newline, but still validate values before putting them into a URL or a command. - You don't have to wait for DNS propagation after adding the record: Nodekeeper keeps driving the CA validation on its check cycle.
-
What an issuing script's form looks like
Picking an issuing script works like a post-issuance script, only in the dropdown on the left. Below is the bundled Cloudflare DNS validation script: its header declares two parameters, so the form has two fields. Choose DNS validation so the script receives the record to add.

-
A skeleton issuing script: DNS validation
Below is a skeleton issuing script: it validates its arguments, takes the key from the environment, only works when
$2isdns, updates-or-creates the record, and fails with a bilingual reason. Thecurlin the middle calls a placeholder address: replace it with the real API of your DNS provider (parameter names and authentication differ per provider). Save it asshell/ssl/my_dns.sh,chmod +x, pick it as the issuing script, and choose DNS validation.#!/bin/bash # name: My DNS validation / 我的 DNS 验证 # tip: Adds the certificate validation CNAME at my DNS provider. / 在我的 DNS 服务商那里自动添加证书验证用的 CNAME 记录。 # type: issuing # secrets: env # param.api_user: API user / 接口账号|required=true # param.api_token: API token / 接口令牌|required=true|password=true set -u umask 077 domain="${1:-}"; method="${2:-}" fail() { echo "错误 / ERROR: $*" >&2; exit 1; } [[ "$method" == dns ]] || fail "本脚本只支持 DNS 验证 / this script only supports DNS validation (got: $method)" rtype="${3:-}"; host="${4:-}"; value="${5:-}" # $6 = 服务配置路径 / service config path (unused here) api_user="${7:-}" api_token="${NK_PARAM_API_TOKEN:-${8:-}}"; unset NK_PARAM_API_TOKEN [[ "$rtype" == cname ]] || fail "不支持的记录类型 / unsupported record type: $rtype" [[ "$host" =~ ^[A-Za-z0-9._-]+$ ]] || fail "记录主机名不合法 / invalid record host: $host" [[ "$value" =~ ^[A-Za-z0-9._-]+$ ]] || fail "记录值不合法 / invalid record value" [[ -n "$api_user" && -n "$api_token" ]] || fail "请填写 api_user 和 api_token / please fill api_user and api_token" if [[ "${NK_SSL_SCRIPT_DRYRUN:-}" == 1 ]]; then echo "[dry-run] would upsert CNAME $host -> $value for $domain"; exit 0 fi # 换成你的 DNS 服务商的接口:同名记录存在就更新,不存在就新建(upsert)。 # Replace with your DNS provider's API: update the record if the name exists, create it otherwise (upsert). # 令牌经 stdin 交给 curl(-K -),不进命令行 / the token goes to curl on stdin (-K -), never on the command line. printf 'header = "Authorization: Bearer %s"\n' "$api_token" | curl -sS --fail -K - \ --connect-timeout 20 --max-time 60 \ -X PUT "https://dns-api.example.net/v1/records" \ --data-urlencode "user=$api_user" --data-urlencode "type=CNAME" \ --data-urlencode "name=$host" --data-urlencode "content=$value" --data-urlencode "ttl=60" >/dev/null \ || fail "添加验证记录失败 / adding the validation record failed" echo "已添加验证记录 / validation record set: $host CNAME $value"This is a skeleton, not a working script: dns-api.example.net is a placeholder. Adapt it to your provider's API documentation, run it once by hand with NK_SSL_SCRIPT_DRYRUN=1, then do one real run with a test certificate.
This line What it does and why [[ "$method" == dns ]] || fail "..."This script only handles DNS validation; if the user picked another method, it fails with a clear reason instead of doing half the job. rtype="${3:-}"; host="${4:-}"; value="${5:-}"The three DNS items Nodekeeper passes: record type ( cname), record host name and record value.api_token="${NK_PARAM_API_TOKEN:-${8:-}}"; unset NK_PARAM_API_TOKENThe token comes from the environment ( $7is api_user,$8the token's placeholder) and is cleared after reading.[[ "$host" =~ ^[A-Za-z0-9._-]+$ ]] || fail ...Checks the host name and value only contain safe characters before they go into an API request. if [[ "${NK_SSL_SCRIPT_DRYRUN:-}" == 1 ]]; then ... exit 0; fiDry run: print what would happen without touching the network. Use NK_SSL_SCRIPT_DRYRUN=1when testing by hand.printf 'header = ...' | curl ... -K - -X PUT ...Calls the DNS provider to update-or-create the record. The token reaches curl on stdin, not on the command line. Replace this part with your provider's real API. echo "已添加验证记录 / validation record set: ..."One line on success, visible in Last run in the panel.
Something wrong? Check this table
| What you see | Why | What to do |
|---|---|---|
| The certificate stays waiting for validation and the details show the script's failure | The issuing script did not exit with 0, for example a wrong token or a wrong API address or parameter. | Fix the parameter or the script according to the reason; the next check tries again, no need to recreate the certificate. |
| Creating the certificate says the script cannot be used as an issuing script | The header has # approval: required. The issuing slot has no approval step, so that is not allowed. | Keep issuing scripts to validation; move anything that reaches other machines into a post-issuance script. |
| Only one domain of a multi-domain certificate validates | The script is called once per domain with different $1, $4 and $5; the script has a domain or host name hard-coded. | Always use the values from the arguments; never hard-code the domain. |
Make it reliable: exit codes, retries, output, writing files
Exit codes, retries, time limit
- Exit
0= success: it is not run again until the next renewal (or "Run now"). Any other code = failure: the status is Failed and Nodekeeper runs the script again every minute until it succeeds, so it must be safe to run repeatedly (idempotent). - A script that declares approval and runs longer than 15 minutes is terminated together with everything it started and recorded as Timed out; the output printed before that is kept, so the details show where it hung. Scripts without the approval line have no such limit (unchanged from before), so set timeouts yourself. Don't daemonize. Put a timeout on every network call yourself (
curl --connect-timeout 20 --max-time 120,ssh -o ConnectTimeout=20).
Output
- The certificate details show Last run: time, result, exit code and the last ~4 KiB of output (stdout first, then stderr), visible to the certificate owner and administrators. Print what an operator needs: what was done, where, and why it failed, with the reason in the last lines, in Chinese and English (
中文 / English).. Never print secrets: before storing the output Nodekeeper replaces the values ofpassword=trueparameters (and of secret-looking names) and private-key PEM blocks with******, also their base64 and URL-encoded forms and the base64 ofuser:password(thecurl -vBasic header); secrets shorter than 4 characters are not masked. Do not rely on it: other derived values (signed URLs, re-encoded copies) are not recognised - Never print secrets: passwords, tokens, keys, the PEM text of
$4,set -xoutput,curl -vheaders. Before storing the output Nodekeeper masks the values ofpassword=trueparameters (and of parameters with secret-looking names, 4+ characters) and private-key blocks as******, but don't rely on it: a derived value (a base64 of the password, a signed URL) is not recognised.
Writing safely
Idempotent (running twice gives the same result); atomic writes (write a temporary name in the same directory, then rename, so nobody sees a half-written certificate; keep a .bak when replacing); private keys mode 600 (umask 077), never on a command line or in a log; validate paths (absolute, no .., mind symlinks); quote every variable; no interactive prompts; check required parameters first and fail early and clearly.
- Idempotent
- Running it once or ten times gives the same result. Failed scripts are re-run every minute, so this is a must: update-or-create, not add another copy each time.
- Atomic write
- Write to a temporary file in the same folder, then rename it to the real name in one step. Readers see either the old file or the complete new one, never half a file.
- Timeout
- A maximum wait for every network command (
curl --max-time 120), so the script does not hang when the other side doesn't answer.
-
Write the certificate atomically to another folder
When a service reads the certificate from a folder, write it like this: temporary name first, keep a backup of the old file, then rename.
umask 077 dest=/etc/myapp/tls cp "$cert_file" "$dest/.fullchain.pem.new" cp "$key_file" "$dest/.privkey.pem.new" [[ -f "$dest/fullchain.pem" ]] && cp -p "$dest/fullchain.pem" "$dest/fullchain.pem.bak" mv -f "$dest/.fullchain.pem.new" "$dest/fullchain.pem" mv -f "$dest/.privkey.pem.new" "$dest/privkey.pem"
This line What it does and why umask 077Files created from now on are readable by the owner only (mode 600). Required for the key. cp "$cert_file" "$dest/.fullchain.pem.new"Copy to a hidden temporary file first; the real file is untouched. [[ -f "$dest/fullchain.pem" ]] && cp -p ... .bakKeep a .bakof the old certificate, so you can switch back by hand if needed.mv -f "$dest/.fullchain.pem.new" "$dest/fullchain.pem"A rename within one folder happens in one step: nobody reads a half-written file. This writes outside the Nodekeeper folder, so the whole script must declare # approval: required.
Something wrong? Check this table
| What you see | Why | What to do |
|---|---|---|
| The status says Timed out | A script that declares approval ran for more than 15 minutes and was stopped together with the processes it started. | Check where the output stops; add a timeout to every network command. |
The output contains ****** | Before storing the output, Nodekeeper replaced secret parameter values and private key blocks. | That's the protection working, but don't rely on it: never print secrets. |
| The output starts with "earlier output truncated, only the end is kept" | The output was long; only the last 4000 characters or so are kept. | Print less progress text and put the failure reason in the last lines. |
| The same error shows up every minute | A failed script is re-run every minute until it succeeds. | Fix the cause, then Run now; keep the script idempotent so re-runs don't repeat actions. |
Which scripts must declare # approval: required, and how approval works
- Declare it when the script reaches another machine or path (SSH, scp/rsync, FTP/FTPS/SFTP, SMB/NFS shares, a local path outside Nodekeeper's own directory) or runs a command, host or path taken from a parameter (a "reload command" or "target host" field). Members can pick any script in
shell/ssland the script runs as root: without approval a parameter would be a remote control. If unsure, declare it; the cost is one click by an administrator. - Don't declare it for scripts that only call a cloud API with the key the user typed (AWS ACM, Tencent Cloud SSL, Baidu Cloud CDN, Cloudflare DNS ...): they cannot touch your machines. (The older bundled Nginx helpers
nginx_cleanup.shandreload_nginx.shpredate this rule: they work on this server's own Nginx configuration and do not declare it. Scripts you write should follow the rule above.) - Flow: a user creates a certificate, picks the script, fills the parameters and saves → the details show "Awaiting administrator approval", the list shows an "Awaiting approval" badge, and the script does not run → an administrator with the approval permission (by default only the administrator group) clicks "Approve...", checks the script, domains and every parameter in the dialog (secrets shown as
******) and clicks "Approve and run" → the script runs and the result appears in Last run. A row created by an administrator is approved automatically. - The whole set is approved: the certificate, its owner, its domains, the script path and every parameter (secrets compared by fingerprint). If any of them changes, the approval is void, the state becomes "Changed since approval - needs approval again" and the script stops running until approved again. An administrator can "Revoke approval" at any time.
- Limits: the approval covers the script's path and parameters, not the file's contents; whoever can edit files in
shell/sslis already the server's administrator. A certificate whose script only later started to declare approval shows "Awaiting administrator approval" until an administrator approves it once. Old scripts without the line behave exactly as before. - Only as a post-issue script: a script that declares approval cannot be chosen as the issue (validation) script. That slot has no approval gate, so the panel refuses it when the certificate is created and Nodekeeper refuses to run it there.
- Parameters by position: a script without
# secrets: envreceives its parameters by position, so the stored keys must be exactly the header'sparam.*keys in the header's order (trailing optional ones may be missing). The panel form does this already; a request that does not is refused, and a stored row that does not match is neither run nor approvable. With# secrets: envthe list is rebuilt from the header, so it cannot go wrong. - Fail closed: if the script's header cannot be read (file missing or unreadable) the script is not run and the run record says why; a header with non-UTF-8 text (for example GBK comments) is still read.
-
After saving: awaiting approval
For a script that declares
# approval: required, the details show a yellow Awaiting administrator approval badge after the certificate is saved, and the script does not run.
-
An administrator checks the whole set and approves
The administrator clicks Approve..., and the dialog lists the script, owner, domains and every parameter (password parameters show as
******). If everything is right, they click Approve and run.
-
Read the result
After approval the details show Approved, the approver and the time; Last run shows the run time, result, exit code and the end of the script output. This is where you see whether your script reports well.

Something wrong? Check this table
| What you see | Why | What to do |
|---|---|---|
| It stays Awaiting administrator approval | No administrator has approved it yet; members cannot approve. | Ask an administrator (by default only the administrator group can approve) to open the details and click Approve... |
| It changed to Changed since approval - needs approval again | The certificate, owner, domains, script path or a parameter changed, so the old approval no longer applies. | An administrator checks the new set and approves again. |
Complete examples: post-issuance scripts
Three steps: a minimal script, a complete FTPS upload script, and how to use it in the panel and try it by hand first.
-
A minimal post-issuance script
This script copies the new certificate to a fixed folder and then reloads a service. The paths and the service name are written into the script, not taken from panel parameters. It writes to
/etc/myapp, outside Nodekeeper's own directory, so it declares# approval: required. Save it asshell/ssl/reload_myapp.sh, runchmod +xon it, then pick "Reload myapp" in the Post-issuance script dropdown; it runs once an administrator has approved it (a certificate created by an administrator is approved automatically). The folder/etc/myapp/tlsmust already exist, owned by root with mode 0700.#!/bin/bash # name: Reload myapp # tip: After issue or renewal, deploy the certificate to myapp and reload it # type: post # approval: required # param.log_label: Name shown in the log |required=false|default=myapp set -euo pipefail DOMAIN="${1%%[ ,]*}" # first name on a multi-domain certificate CERT_FILE="$5" KEY_FILE="$6" LABEL="${7:-myapp}" # your first declared parameter is the 7th argument [[ -r "$CERT_FILE" && -r "$KEY_FILE" ]] || { echo "[$LABEL] certificate files not found" >&2; exit 1; } install -m 644 "$CERT_FILE" /etc/myapp/tls/fullchain.pem install -m 600 "$KEY_FILE" /etc/myapp/tls/privkey.pem systemctl reload myapp echo "[$LABEL] certificate for ${DOMAIN} deployed and reloaded"Running it again gives the same result (the same files overwritten, the same service reloaded), and any failing step exits non-zero, so it is retried at the next minute.
This line What it does and why # approval: requiredIt writes to /etc/myapp, outside the Nodekeeper folder, so an administrator must approve it.DOMAIN="${1%%[ ,]*}"The first domain, only used in the message. LABEL="${7:-myapp}"The first declared parameter is $7; myapp when empty.install -m 600 "$KEY_FILE" /etc/myapp/tls/privkey.peminstallcopies the file and sets its mode at once: 644 for the certificate, 600 for the key.systemctl reload myappMakes the service re-read the certificate. On an error set -eexits non-zero and it is retried a minute later. -
A complete example: FTPS upload
After every issue or renewal, this script uploads
<domain>.pem(with the chain) and<domain>.keyto your FTP server over FTP with explicit TLS (FTPS). It declares approval (it reaches another machine), keeps the password off the command line (# secrets: env, andcurl -K -reads the login from standard input), validates every parameter, uploads under a temporary name and renames afterwards, and ends with a Chinese and English reason on failure. Save it asshell/ssl/ftps_upload.shand runchmod +x.Adapt it to your server and test it once against that server: FTP servers differ in how they handle the rename; this skeleton was checked for syntax and input validation, not against every FTP server.
#!/bin/bash # name: FTPS 上传证书 / Upload certificate over FTPS # tip: 签发或续期后,用 FTPS(显式 TLS)把证书和私钥上传到你的 FTP 服务器。会碰到别的机器,需要管理员在面板核准。 / After issue or renewal, uploads the certificate and key to your FTP server over explicit TLS (FTPS). It reaches another machine, so an administrator must approve it in the panel. # type: post # approval: required # secrets: env # param.ftp_host: FTP 主机(域名或 IP,可带 :端口)/ FTP host (name or IP, optional :port)|required=true # param.ftp_user: FTP 用户名 / FTP user name|required=true # param.ftp_password: FTP 密码 / FTP password|required=true|password=true # param.remote_dir: 远程目录,相对 FTP 登录目录,例如 ssl / Remote directory, relative to the FTP login directory, e.g. ssl|required=true|default=ssl set -u umask 077 # ---- 1. 读参数:位置参数 1-6 是 Nodekeeper 固定给的,7 起按上面声明的顺序 / Read parameters: 1-6 are fixed by Nodekeeper, 7+ follow the declared order ---- domain_raw="${1:-}" # 域名(可能是多个,逗号或空格分隔)/ domain(s), comma or space separated cert_file="${5:-}" # 证书文件路径(完整链)/ certificate file path (full chain) key_file="${6:-}" # 私钥文件路径 / private key file path host="${7:-}" user="${8:-}" pass="${NK_PARAM_FTP_PASSWORD:-${9:-}}" # 秘密参数走环境变量,$9 只是占位 / the secret comes from the environment, $9 is just a placeholder unset NK_PARAM_FTP_PASSWORD remote_dir="${10:-}" fail() { echo "错误 / ERROR: $*" >&2; exit 1; } # ---- 2. 校验输入(不要信任参数:它们会拼进 URL 和 FTP 命令)/ Validate input (parameters end up in a URL and FTP commands) ---- first="${domain_raw%%[ ,]*}" name="${first//\*/_wildcard_}" [[ "$name" =~ ^[A-Za-z0-9._-]+$ ]] || fail "域名不合法 / invalid domain: $first" [[ "$host" =~ ^[A-Za-z0-9._:-]+$ ]] || fail "ftp_host 只能含字母数字 . _ : - / ftp_host may only contain letters, digits . _ : -" [[ -n "$user" ]] || fail "请填写 ftp_user / please fill ftp_user" [[ -n "$pass" ]] || fail "请填写 ftp_password / please fill ftp_password" [[ "$remote_dir" =~ ^[A-Za-z0-9._/-]*$ && "$remote_dir" != /* && "$remote_dir" != *..* ]] \ || fail "remote_dir 必须是相对目录,只含字母数字 . _ / - / remote_dir must be a relative path of letters, digits . _ / -" remote_dir="${remote_dir%/}" [[ -r "$cert_file" && -r "$key_file" ]] || fail "读不到证书或私钥文件 / cannot read the certificate or key file" # ---- 3. 演练模式:只说要做什么,不联网 / Dry-run: say what would happen, no network ---- if [[ "${NK_SSL_SCRIPT_DRYRUN:-}" == 1 ]]; then echo "[dry-run] would upload $name.pem and $name.key to ftp://$host/${remote_dir:+$remote_dir/} over explicit TLS" exit 0 fi # ---- 4. 上传:先传成临时名,传完再改名(对方服务器不会读到半截文件)/ Upload under a temporary name, rename when done (the server never serves a half file) ---- # 账号密码经 stdin 交给 curl(-K -),不出现在命令行(/proc/<pid>/cmdline 谁都能读)/ The login goes to curl on stdin (-K -), not on the command line (anyone can read /proc/<pid>/cmdline) upload() { # $1 本地文件 local file $2 最终文件名 final name local tmp=".$2.nk-tmp" cred cred="$(printf '%s:%s' "$user" "$pass" | sed 's/\\/\\\\/g; s/"/\\"/g')" printf 'user = "%s"\n' "$cred" | curl -sS --fail --ssl-reqd --ftp-create-dirs \ --connect-timeout 20 --max-time 120 -K - \ -T "$1" -Q "-RNFR $tmp" -Q "-RNTO $2" \ "ftp://$host/${remote_dir:+$remote_dir/}$tmp" } upload "$cert_file" "$name.pem" || fail "上传证书失败 / uploading the certificate failed" upload "$key_file" "$name.key" || fail "上传私钥失败 / uploading the key failed" echo "已上传 / uploaded: $name.pem, $name.key -> $host/${remote_dir:+$remote_dir/}"The remote directory is relative to the FTP login directory (for example ssl). If your server uses a self-signed certificate, make the machine running Nodekeeper trust it first; the script has no switch that turns certificate checking off. The private key is uploaded with whatever file mode the FTP server gives new files (often 644): check it once, and keep that directory off any web root and away from other users. The two files are not replaced atomically as a pair: if the key upload fails after the certificate was replaced, the server briefly holds the new certificate with the old key until the next retry (every minute).
This line What it does and why # param.ftp_password: ...|password=trueA password field, stored encrypted; with # secrets: envit is read fromNK_PARAM_FTP_PASSWORD.remote_dir="${10:-}"The fourth declared parameter, position $10(two-digit positions need braces).[[ "$host" =~ ^[A-Za-z0-9._:-]+$ ]] || fail ...Parameters go into a URL and FTP commands, so each one is checked; anything invalid exits with a reason. if [[ "${NK_SSL_SCRIPT_DRYRUN:-}" == 1 ]]; thenDry run: print what would be uploaded, no network. printf 'user = "%s"\n' "$cred" | curl ... -K -The login reaches curl on stdin, never on the command line. -T "$1" -Q "-RNFR $tmp" -Q "-RNTO $2"Upload under a temporary name, rename when done, so the FTP side never serves half a file. upload ... || fail "上传证书失败 / ..."Any failed step exits non-zero with the reason in the last line of the output. -
Using the FTPS script: fill in, approve, read the result
In the certificate form's Post-issuance script, pick "FTPS 上传证书 / Upload certificate over FTPS" (the name in the script's
# name:line), and fill in the FTP host, user name, password and remote directory. The password box is a password field, stored encrypted and shown only as******after saving. After saving, the details show Awaiting administrator approval; an administrator clicks Approve..., checks the host, user name and remote directory, and clicks Approve and run. Then confirm in Last run of the details: result Succeeded, exit code0, and the "uploaded" line in the output. If it fails, the reason is in the same place; after you fix the parameters an administrator has to approve once more.Try it by hand first: you can run the script yourself the way Nodekeeper does,
$1to$6first, then the parameters in header order. With# secrets: envthe secret is passed twice: an empty placeholder at its position (that is what Nodekeeper puts on the command line) and the real value inNK_PARAM_<KEY UPPERCASE>. For example (the''aftermyuseris the password placeholder; dropNK_SSL_SCRIPT_DRYRUN=1for a real upload; run it as the user Nodekeeper runs as):NK_SSL_SCRIPT_DRYRUN=1 NK_PARAM_FTP_PASSWORD=x ./ftps_upload.sh example.com '' '' '' /path/fullchain.pem /path/key.pem ftp.example.com myuser '' ssl
Checklist
- A
#!first line,name,tip,type: post, executable. - It reaches another machine or path, or runs something taken from a parameter → declare
approval: required. - Password parameters use
password=true+# secrets: env, read from the environment, never printed, never on a command line. - Read
$5and$6, validate every parameter, quote every variable. - Idempotent, atomic writes, a timeout on every network call, finishing well under 15 minutes.
- Exit
0only on real success; the failure reason is the last output line, in Chinese and English. - Tried with
NK_SSL_SCRIPT_DRYRUN=1and once for real; the details show the expected result.
Frequently asked questions
- Can I write it in Python or another language?
- Yes. Put the interpreter on the first line (for example
#!/usr/bin/env python3), keep the.shextension, and write the header directives as lines starting with#. The interpreter must be installed on the server. - Which user does the script run as?
- The user Nodekeeper runs as, normally root. That is why only server administrators can put scripts into
shell/ssl; write them as code that runs as root. - If I change the script file, does it need approval again?
- No, and it does not trigger one: approval covers the script path and the parameters, not the file content. Whoever can change that folder is already a server administrator; review your changes yourself.
- Can I add a script to a certificate that is already issued?
- Not by editing it: the script is chosen in Add Certificate. To give an existing domain a script, add another certificate with the script selected.
- Does it run on renewal? How often?
- Yes. After every issue and every renewal; after a success (exit code 0) it does not run again until the next renewal or a Run now. A failure is retried every minute until it succeeds.
- Can members use my script?
- Yes. Every account sees the scripts in
shell/sslin the dropdowns. That is why a script that reaches other machines or runs commands from its parameters must declare# approval: required; otherwise a member's parameters would drive a script that runs as root. - How do I try it without touching the network?
- Implement the
NK_SSL_SCRIPT_DRYRUN=1check in your script (the FTPS and DNS examples here have it) and set that variable when you run it by hand. Nodekeeper does not set it for you, and a script that doesn't check it runs for real.
