This is a run-once BASH script to create an autorun environment on your NAS. Which can then be used to automatically run your own scripts when the NAS boots-up.
What it does
This installer script writes an autorun.sh processor into your default volume, below the .system directory. It then symlinks this into the DOM so that it's triggered on NAS startup. It also creates a scripts directory for your own custom creations and NAS modifications. Everything in the scripts directory is run (in order) during NAS startup.
How to use it
- SSH into your NAS as the 'admin' user,
- Run the installer script:
Code: Select all
curl -skL https://git.io/create-autorun.sh | bash
- Place your executable scripts (or symlinks) into the 'scripts' directory.
- For those with QTS 4.3.x, you'll also need to let QTS know that it should permit the autorun.sh script to execute. Navigate to Control Panel -> System -> Hardware, then enable the option "Run user defined processes during startup".
- The location of the autorun system will depend on your default volume name. For example: my default volume is 'MD0_DATA', so the automatic processor is created at:
... and the scripts directory is created at:
- 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:
Code: Select all
010-example.sh 020-example.sh 025-example.sh
- 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 scripts found in the scripts directory as they were run, as well as any captured stdout.
- The source for this project can be found on GitHub
As there has been no official word on this from QNAP, we're reduced to observations-only. Here are the results from my latest startup-sequence tests with QTS 4.2.6 #20171208 on my TS-559 Pro+.
I modified each installed QPKG to record the NAS uptime and the name of the package init script in the system log as each package was started. I also created a single autorun script called autotest.sh that logs the same information:
As you can see, QTS executed autorun.sh and then began launching the QPKGS as per /etc/config/qpkg.conf. I ran the same startup several times, and saw no more that a few seconds difference between each one.System started.
- The odd-man-out here is the first load of CloudDrive.sh. It seems that QTS preloads this package early-on, then loads it again later. I'm sure QNAP have a good reason for that.
So, it seems autorun.sh can affect the loading of QPKGs.System started.
[283.61] /share/MD0_DATA/.system/autorun/scripts/autotest.sh - begin 60 second sleep
[343.73] /share/MD0_DATA/.system/autorun/scripts/autotest.sh - end 60 second sleep
edit log milestones
20180916: moved to GitHub repo.
20171228: included startup-sequence test results.
20171217: major rewrite and support for exceptions (ubifs->ext4) - thank you @z3d0_ and @schumaku
20171117: included note to enable autorun during startup in Control Panel - thank you @schumaku
20170212: added support for system device [sdx] - thank you @HB and @schumaku
20170206: mount point is now under [/tmp] - thank you @mundeli and @schumaku
20170204: added support for [UBIFS] - thank you @ugduibill and @schumaku