Automating Script Run Startup on Unraid Server
Unraid is a popular NAS (Network Attached Storage) operating system that allows users to run various services and applications on their servers. One common task that Unraid users may want to automate is running a script at startup. This article will cover the steps to create a script and automate its execution at server startup.
Creating a Script
The first step in automating a script at startup is to create the script. This can be done using any text editor, such as nano or vi. For this example, we will create a script that turns off the fans to reduce noise at startup.
vi /boot/startup.d/01-startup-script.sh
In the text editor, add the following code:
#!/bin/bash
# Wait for network to come up
until ping -c 1 -W 1 google.com &>/dev/null
do
sleep 1
done
# Turn off fans
/usr/local/emhttp/plugins/sshell/sshell fan offSave and exit the text editor. Then, make the script executable:
chmod +x /boot/startup.d/01-startup-script.sh
Automating Script Execution at Startup
Unraid automatically executes scripts in the /boot/startup.d/ directory at startup. The scripts are executed in alphabetical order based on their filename. In this example, we named the script 01-startup-script.sh to ensure it is executed before other scripts.
Testing the Script
To test the script, reboot the Unraid server. After the server has fully booted, run the following command to check the fan status:
sshell fan status
The output should indicate that the fans are off.
References
- Unraid Documentation: sshell Plugin
- Unraid Forums: Turn off fans on startup
Automating a script at startup on Unraid is a straightforward process that involves creating a script and placing it in the /boot/startup.d/ directory. The script will be executed at startup in alphabetical order based on its filename. In this example, we created a script that turns off the fans at startup to reduce noise.