TrueNAS SCALETrueNAS SCALE Nightly Development Documentation
This content follows experimental early release software. Use the Product and Version selectors above to view content specific to a stable software release.

Init_Shutdown_Script

The SCALE CLI guide is a work in progress! New namespace and command documentation is continually added and maintained, so check back here often to see what is new!

Init_shutdown Namespace

The init_shutdown namespace has 5 commands, and is based on init/shutdown script functions found in the SCALE API and web UI. It provides access to init/shutdown script management methods through the init_shutdown namespace commands.

Init/shutdown scripts are capable of making OS-level changes and can be dangerous when done incorrectly. Use caution before creating script or command tasks.

Make sure you are comfortable with ZFS, Linux, and system configuration, backup, and restoration before creating and executing script tasks.

Init_shutdown Commands

The following init_shutdown namespace commands allow you to create, view, update, and delete init/shutdown script tasks.

You can enter commands from the main CLI prompt or from the system namespace prompt.

Create Command

The create command creates a new init/shutdown script task.

Init/shutdown scripts allow you to run scripted tasks before or after initialization (start-up), or at shutdown. All init/shutdown scripts run using sh(1).

Using the Create Command

Description

create has two required properties, type and when, and three optional properties (see Create Properties below). type has two possible values, SCRIPT or COMMAND, that each require one additional property. SCRIPT requires either the script or script_text property. COMMAND requires the command property.

Enter all required and any optional properties you want, surround string values with double quotes ", and then press Enter.

Create Properties
PropertyRequiredDescriptionSyntax Example
typeYesSpecifies the type of init/shutdown task. Options are SCRIPT or COMMAND.type=SCRIPT
commandYes*Required when type is COMMAND. Enter a command with any options you want or the path to a command stored on the system.command="touch /mnt/tank/data/cmdTest.txt"
script_textYes*Either script_text or script is required when type is SCRIPT. Enter the full text for the script.script_text="touch /mnt/tank/data/ScriptTest.txt"
scriptYes*Either script_text or script is required when type is SCRIPT. Enter the path to a script stored on the system.script="/mnt/tank/data/​scripts/shutdown_script.sh"
whenYesEnter when the script should execute. Options are:
  • PREINIT – early in the boot process, before services have started
  • POSTINIT – late in the boot process, when most services have started
  • SHUTDOWN – on shutdown
when=SHUTDOWN
enabledNoSet to false to create the script but not enable it. Defaults to true.enabled=true
timeoutNoEnter the time (in seconds) that the system should wait for the script or command to execute. Default value is 10.

Note: A hard timeout limit is configured by the base OS, so when a script or command is set to execute on SHUTDOWN, the timeout specified by script or command is added to the base timeout, so that it is not interrupted by the base limit.
timeout=10
commentNoEnter a human-readable description for the command or script.comment="Shutdown Task"

Usage

From the CLI prompt, enter:

system init_shutdown_script create type=SCRIPT script="path/to/file.sh" when=SHUTDOWN

Where SCRIPT is the task type, script is the property for defining the task, path/to/file.sh is the path to an executable script, and SHUTDOWN is when the task executes.

Press Enter.

Returns an empty line when successful. Use query to confirm the task was created.

Always test the script to verify it executes and achieves the desired results.

Command Example
system init_shutdown_script create type=SCRIPT script="path/to/file.sh" when=SHUTDOWN comment="Shutdown Task"

Delete Command

The delete command removes an existing init/shutdown script task.

Using the Delete Command

Description

delete has one required property, id. Use query to view the id numbers for existing script or command tasks.

Enter the command string and press Enter. Deletes the task matching id.

Usage

From the CLI prompt, enter:

system init_shutdown_script delete id=1

Where 1 is the id of the task to delete. Press Enter.

delete returns an empty line. Use query or get_instance to confirm the task is deleted.

Command Example
system init_shutdown_script delete id=1

Get_instance Command

The get_instance command returns configured settings for an existing init/shutdown script task.

Using the Get_instance Command

Description

get_instance has one required property, id. Use query to view the id numbers for existing script or command tasks.

Enter the command string and press Enter. get_instance returns a table containing information about the task matching id.

Usage

From the CLI prompt, enter:

system init_shutdown_script get_instance id=1

Where 1 is the id of the task. Press Enter.

Command Example
[truenas] system init_shutdown_script> get_instance id=1
+-------------+--------------------------------------------+
|          id | 1                                          |
|        type | SCRIPT                                     |
|     command |                                            |
|      script | /mnt/tank/data/scripts/post_init_script.sh |
|        when | POSTINIT                                   |
|     enabled | true                                       |
|     timeout | 10                                         |
|     comment | Post Init Report                           |
| script_text |                                            |
+-------------+--------------------------------------------+

Query Command

The query command returns information about all existing init/shutdown script tasks on the system.

Using the Query Command

Description

query does not require entering properties or arguments.

Enter the command string and press Enter.

Returns a table containing settings for all configured scripts or commands.

Usage

From the CLI prompt, enter:

system init_shutdown_script query

Press Enter.

Command Example
[truenas] system init_shutdown_script> query
+----+---------+----------------------------------+--------------------------------------------+----------+---------+---------+------------------------+-------------------------------------+
| id | type    | command                          | script                                     | when     | enabled | timeout | comment                | script_text                         |
+----+---------+----------------------------------+--------------------------------------------+----------+---------+---------+------------------------+-------------------------------------+
| 1  | SCRIPT  |                                  | /mnt/tank/data/scripts/post_init_script.sh | POSTINIT | true    | 10      | Post Init Report       |                                     |
| 2  | SCRIPT  |                                  | /mnt/tank/data/scripts/pre_init_script.sh  | PREINIT  | true    | 10      | Pre-Init System Checks |                                     |
| 3  | SCRIPT  |                                  | /mnt/tank/data/scripts/shutdown_script.sh  | SHUTDOWN | true    | 10      | Shutdown Backup        |                                     |
| 4  | COMMAND | touch /mnt/tank/data/cmdTest.txt |                                            | POSTINIT | true    | 10      | Command Test           |                                     |
| 5  | SCRIPT  |                                  |                                            | POSTINIT | true    | 10      | Script Test            | touch /mnt/tank/data/ScriptTest.txt |
+----+---------+----------------------------------+--------------------------------------------+----------+---------+---------+------------------------+-------------------------------------+

Update Command

The update command modifies configured settings for an existing init/shutdown script task.

Using the Update Command

Description

update has one required property, id, and eight optional properties. Use query to view the id numbers for existing script or command tasks. For optional properties, see the create properties.

Enter the command string with any optional properties you want to update and then press Enter.

Usage

From the CLI prompt, enter:

system init_shutdown_script update id=1 property=value

Where 1 is the id of the task to update, property is one of the configuration properties, and value is the new setting for that property. Press Enter.

update returns an empty line. Use query or get_instance to confirm the task is deleted.

Command Example
[truenas] system init_shutdown_script> update id=1 when=PREINIT