Configure Script Start Options
SUMMARY Configure the device to perform specific system resource checks before executing a script.
You can configure start options for certain types of scripts on supported platforms. When you configure start options, the device performs specific system resource checks before executing a script. The checks determine whether the system should start or prevent script execution based on the configured values. By configuring script start options you can ensure that a device executes only essential scripts when system resources are limited, thereby enabling the device to continue performing all critical network functions.
You can configure start options to prevent script execution based on the system's memory usage, as described in Configure the System Memory Usage Threshold for Scripts.
You configure script start options to prevent a script from executing under certain conditions. To instead enable the device to start a script but slow the script's execution or halt the script if it exceeds certain limits as it runs, see the following documentation:
Configure the System Memory Usage Threshold for Scripts
You can configure a device to prevent a script from executing if the system's memory usage is above a configured threshold. For example, you might want to prevent the execution of a particularly resource intensive script or type of script if the system memory usage is above 75 percent. Alternatively, if a particular script plays a vital role in the device's operation, you might configure a higher system memory usage threshold or no threshold for that specific script to ensure that the device still executes the script even if the system has more limited resources at that time.
You configure the start start-options mem-factor
statement to define
the system memory usage threshold above which a script does not execute. You can
define a threshold for op, event, SNMP, and Juniper Extension Toolkit (JET) scripts.
You can apply the statement to an individual script or to all scripts of a given
type. When you configure the statement for a type of script, for example, op
scripts, the statement applies to all Python, SLAX, and XSLT scripts of that type.
If you define different thresholds for the script type and an individual script of
the same type, the configuration for the individual script takes precedence.
Junos devices do not enforce script start options for remote op scripts, which
are executed using the op url
command. Script start options are
enforced only for local op scripts.
For JET applications, the daemonize
and
mem-factor
statements are mutually exclusive. If a JET
application includes the daemonize
statement in its
configuration, you cannot configure the mem-factor
statement
either for that individual script or globally for all JET scripts. If you
configure both statements and commit the configuration, the device issues a
commit error.
When you execute a script that has the mem-factor
statement
configured for that script or that type of script, the device compares the current
system memory usage to the configured mem-factor
value. If the
system memory usage is lower than the configured threshold, then the script executes
normally. If the system memory usage exceeds the configured threshold, the device
does not execute the script and generates a system log message to that effect. If
you do not configure the mem-factor statement
for either the
individual script or script type, then the system does not perform any system memory
usage checks and executes the script normally.
Junos devices calculate the system memory usage differently depending on the operating system. Junos OS uses the following calculation to determine the system memory usage:
current memory usage = (Total memory – (Cache memory + Free memory + Inactive Memory))*100 / Total memory
For example, consider the following show system memory
command
output on a device running Junos OS:
user@host> show system memory System memory usage distribution: Total memory: 4135380 Kbytes (100%) Reserved memory: 137172 Kbytes ( 3%) Wired memory: 334964 Kbytes ( 8%) Active memory: 772468 Kbytes ( 18%) Inactive memory: 2738480 Kbytes ( 66%) Cache memory: 0 Kbytes ( 0%) Free memory: 261964 Kbytes ( 6%) ...
In this case, the current system memory usage is approximately twenty-seven percent.
If you a invoke a script, the device does not execute the script if this usage
exceeds the configured mem-factor
value for that script. The device
compares the usage against the mem-factor
value for the script type
only if you do not configure the mem-factor
statement for the
individual script.
Junos OS Evolved includes the system memory usage directly in the show system
memory
command's XML output.
user@host-re0 show system memory node re0 | display xml <rpc-reply xmlns:junos="http://xml.juniper.net/junos/23.1R1/junos"> <system-memory-information> <system-memory-summary-information> <system-memory-total>16062004</system-memory-total> <system-memory-total-percent>100%</system-memory-total-percent> <system-memory-used>3540932</system-memory-used> <system-memory-used-percent>22%</system-memory-used-percent> ...
When you invoke a script that has the mem-factor
statement
configured, the device logs the CSCRIPT_START_OPTIONS_MEM_FACTOR system log message
with severity level INFO.
Oct 11 11:39:07 host cscript[93413]: CSCRIPT_START_OPTIONS_MEM_FACTOR: Start-options is set with mem-factor '70'
If a device prevents the execution of a script because the current system memory usage exceeds the configured threshold, the cscript process records system log messages in the log file. The CLI does not issue any warning or error that the script was halted. The device logs the CSCRIPT_START_OPTIONS_SYSTEM_MEM and CSCRIPT_START_OPTIONS_WARNING system log messages with severity level WARNING for this event.
user@host> show log messages | match cscript Oct 11 11:39:07 host cscript[93413]: CSCRIPT_START_OPTIONS_SYSTEM_MEM: Start-options System Memory Usage Statistics: Total memory:'4137428' Free memory:'132936' Oct 11 11:39:07 host cscript[93413]: CSCRIPT_START_OPTIONS_WARNING: Start-options System Memory Usage '74' exceeds the mem-factor '70', aborting the script 'bgp-neighbors.slax' execution
The CLI does not indicate if the device halts a script's execution. For example,
op scripts do not emit any output in this case, SNMP scripts return a No
such instance
error, and JET scripts still emit a message that the
extension service application was started. You must always refer to the system
log messages to confirm that the device prevented a script from running.
Configure Start Options for Individual Scripts
To configure script start options for individual scripts:
Configure Start Option for All Scripts of a Given Type
To configure script start options for all scripts of a given type: