Post init will not run a script to unlock a pool, either sh or perl versions

I’m new to Scale, In Core I used this script to unlock a pool on an IP being available. In new scale migration this sh script failed so DuckAI converted it to run in Linux/Scale but Post init fails to launch as well. Since I have another Post init script in perl that works I converted the sh script to perl but again Post Init fails to launch.

Using the shell both work without error. This is a Post init issue? Permission are 770 so Owner and group have Read Write and Execute as I can run from the shell.

I have also tried both Post Init Command and Script, neither launch.

Though I don’t think necessary being a Post Init issue I posted the script below anyway, just in case.

The scripts job: It loops until IP 192.168.xxx.xxx is detected on the network then launches xxxx.pl which unlocks the pool, finishing by cancelling this script on detection of /Statement_Check becomes available in the unlocked pool.

The script works so why can’t I launch it.

#!/bin/bash
#Post Init will not launch but shell will.
# Define the IP address to check

IP_addr="192.168.xx.xxx"
if [ -e /mnt/xxxxxxx/xxxxxxStatement_Check ]; then
  echo "System Already Mounted..Script Cancelled." >&2
  exit 1  # Exit the script with an error code
else
  count1=0
  count2=0

  # Use -c to specify the number of packets to send
  Ping=$(ping -c 1 -i 20 "$IP_addr" 2>/dev/null | grep -oP '\d+(?=% packet loss)')

  # Check if the ping command was successful
  if [ $? -ne 0 ]; then
    echo "Ping command failed. Please check the network connection or the IP address." >&2
    exit 1  # Exit the script with an error code
 fi

  if [ "$Ping" = "0" ]; then  # Check if packet loss is 0%
    count1=$((count1 + 1))
    echo "$IP_addr UP"  # Output the IP address status
    /mnt/xxxxxxx/xxxxxxxxxxxx/xxxxxxxxxx/xxxxxx.pl
  else
    count2=$((count2 + 1))
    echo "$IP_addr DOWN"  # Output the IP address status
    /mnt/xxxxxxx/xxxxxxxxxx/xxxxxxxxxxx/System_IP_105_Available.sh
  fi
fi

echo "$count1 IP addresses UP and $count2 IP addresses DOWN"

The log file /var/log/middlewared.log will show you if there were any errors while running the init-scripts. Try the following:

$ sudo grep InitShutdownScriptService /var/log/middlewared.log

Here’s an example of an error (exit code 1 in this example):

(DEBUG) InitShutdownScriptService.execute_task():158 - Failed to execute 'echo "START"; sleep 10; echo "STOP"; exit 1' with error 'START\nSTOP\n'

If you want easier debugging: You can use the following command to run all postinit script. This is the same call that truenas uses during boot:

$ sudo midclt call --job initshutdownscript.execute_init_tasks POSTINIT

Ok, getting somewhere:

In these two examples sh and pl scripts to me it seems a permissions issue as it can’t find the scripts? or something else.

[2025/10/17 16:38:14] (DEBUG) InitShutdownScriptService.execute_task():158 - Failed to execute ‘/bin/sh /mntxxxxxxxxxxxxxxxxxxxxxxxxxxxx_Available.sh’ with error ‘/bin/sh: 0: cannot open /mnt/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxAvailable.sh: No such file\n’

[2025/10/17 21:48:14] (DEBUG) InitShutdownScriptService.execute_task():158 - Failed to execute ‘/mnt/xxxxxxxxxxxxxxxxxxxxxxxxAvailable.pl’ with error ‘sh: 1: /mnt/xAvailable.pl: not found\n’

I think these commands are run as root, so maybe not a permission issue. But check that the path of the script is correct.

Can you check if doing it manually like this will still result in a error in middlewared.log?

$ sudo midclt call --job initshutdownscript.execute_init_tasks POSTINIT

Maybe the script is executed before the pool is fully mounted? I don’t know if post-init scripts are guaranteed to execute post-mount. Could be a timing issue. Simplest solutions to that would be to change the command to:

sleep 10; /mntxxxxxxxxxxxxxxxxxxxxxxxxxxxx_Available.sh

This way it will wait 10 second before executing the script.

I tried that earlier on but failed, Since you brought it up try again and in case I did something wrong.

Arghhhh…10 seconds failed, 20 seconds failed, 30 seconds failed, 90 seconds success!!!

Dam, Scale is slower than Core to boot on same PC with no hardware changes.

It goes to show you can be trapped in a bubble until somebody just nudges you and you then see what’s in front of you all along. That’s a few hours I’ll never get back.

Thanks Bacon.

1 Like