Skip to content

System API

System API runs OS-level operations on the host the platform is running on: shut down / restart the platform, set the system clock, run arbitrary commands, and manage pending system requests.

Shuts the platform process down.

ins.shutdown();

Restarts the platform.

var h = ins.now().getHours();
if (h >= 2 && h <= 4) {
ins.writeLog("warn", "System", "Scheduled restart");
ins.restart();
}

Sets the server’s system clock to ms (epoch).

ParameterDescription
msTarget time (epoch milliseconds)
dateCmdFormatJava SimpleDateFormat pattern used only on Windows (e.g. "MM-dd-yyyy") — it formats ms and passes the result to cmd /c date <value>; the time is set separately through time with HH:mm:ss. On Linux this parameter is ignored — the service internally uses a fixed yyyy-MM-dd HH:mm:ss format plus date -s.
// Windows
ins.setDateTime(Date.now(), "MM-dd-yyyy");
// Linux — format is ignored, may be empty
ins.setDateTime(Date.now(), "");

Runs an OS command on the host. The return is not the command’s output — it is the exit code (int). 0 means success.

Pass the argument list as an array — no shell parsing, lower injection risk.

var rc = ins.exec(["df", "-h", "/"]);
if (rc != 0) {
ins.writeLog("error", "System", "df failed — exit " + rc);
}

Pass a single string; it is split on whitespace internally (simple splitter, does not honor quoted arguments).

ins.exec("df -h /");

The platform maintains a queue of “system requests” (e.g. user-approved shutdown / restart). This API gives scripts access to that queue.

Returns pending system requests — Collection<SystemRequestDto>.

var reqs = ins.getSystemRequests();
reqs.forEach(function(r) {
ins.consoleLog(r.getType() + "" + r.getRequestDate());
});

Removes a request from the queue.

var reqs = ins.getSystemRequests();
reqs.forEach(function(r) {
if (r.getType() == "RESTART") ins.deleteSystemRequest(r);
});
MethodTypeDescription
getType()StringRequest type (e.g. "SHUTDOWN", "RESTART")
getRequester()Map<String, Object>Requesting-user info
getRequestDate()DateCreation time
function main() {
var rc = ins.exec(["sh", "-c", "df -h / | awk 'NR==2 {print $5}' | tr -d '%' > /opt/inscada/tmp/disk.txt"]);
if (rc != 0) return;
var used = parseInt(ins.readFile("tmp/disk.txt").trim(), 10);
if (used > 95) {
ins.sendMail(["ops"], "Disk " + used + "%", "Critical disk usage — restart planned in next maintenance window");
}
}
main();