This is a run-once BASH script to create an autorun environment on your QNAP NAS. This can be used to automatically execute your own scripts when the NAS boots-up.
The aim of this project is to support all QNAP NAS models and all QTS & QuTS hero versions. Please advise if you encounter any errors when running it on your NAS.
What it does
This installer script writes an autorun.sh processor into your default volume, below the .system directory. It then symlinks this from the DOM back to your default data volume so that it is run on NAS startup. This means you don’t need to load the DOM partition every time you want to change the contents of autorun.sh
The autorun device and partition are automatically determined by this script.
If you didn’t have an autorun.sh file before, then the autorun.sh file created by this utility will contain a script directory processor, and will make a scripts directory available for your own shell-scripts. Everything in this scripts directory is run (in-order) during NAS startup by the default autorun.sh file created only. The notes below are only applicable to the autorun.sh written by this utility. If you already had another autorun.sh file, then it will remain and be used instead, and the following notes won’t apply.
The location of the autorun system will depend on your default volume name. For example: if your default volume is CACHEDEV1_DATA, then the automatic script processor will be created at:
/share/CACHEDEV1_DATA/.system/autorun/autorun.sh
… and the scripts directory will be created at:
/share/CACHEDEV1_DATA/.system/autorun/scripts/
autorun.sh is triggered at some point during NAS bootup, which then runs each executable file in the scripts directory in the default filename list order. If you need to run one script before the other, prefix them with a number such as:
A log file is created during autorun.sh execution. It is located at /var/log/autorun.log and contains the date-time and name of each of the executable scripts found in the scripts directory as they were run, along with any stdout and stderr generated by these scripts.
The source for this project can be found on GitHub
Installation on QTS 5.2.5 works, but if i try to run my scripts i got a “command not found” error. It seams that the autorun.sh is running before all QPKG’s so it does not find related commands. If i run it later manually all is working as expected. A “sleep” command at the beginning has no effect (except the “sleep”).
Correct. autorun.sh executes before QPKGs are started.
sleep won’t help as it just holds-up the boot process until autorun has finished, which includes starting QPKGs.
I later created the RunLast QPKG to help workaround this, but it no longer works as of QTS 5.2.0 due to changes made by QNAP to start QPKGs asynchronously.
There’s presently no way to run scripts after startup that rely on QPKGs.
This is not quite right.
I have now found a solution by using “RunLast” from the “MyQNAP” repository. I was surprised that it produced the same error at first. So I did a little research. I found out that the QNAP services are not exclusively started asynchronously and especially that they do not always wait for the successful start of the dependencies.
So I modified my start script so that it takes this into account.
This has partly to do with the way QNAP links its binaries and libraries in and out, depending on the installed apps.
For example, “autostart.sh” usually fails because most of the libraries and binaries are not yet “linked”. The same also applies in part to “RunLast”.
But please do not stop developing “RunLast”. It already follows the right approach, especially because of the nice structure of the SysV start scripts. You can get almost anything to run with it if you consider the dependencies of your application on other QPGG’s and steal a little from their start scripts. I have an simple example for my ClamD, which I use for my Xeams:
Best regards,
Mandragor59
***** There are no problems, there are only challenges *****