Thursday, August 29, 2013

QNAP: Automatically run a script at startup

Running Your Own Application at Startup
QPKG-based method (new)
This method consists of declaring a dummy QPKG which launches your script at startup.

Log into your QNAP device using SSH or Telnet, for instance by using Putty

Edit QPKG config file:
# vi /etc/config/qpkg.conf

Declare a new dummy package by adding something like that in this file:

Name = autorun
Version = 0.1
Author = neomilium
Date = 2013-05-06
Shell = /share/MD0_DATA/.qpkg/autorun/
Install_Path = /share/MD0_DATA/.qpkg/autorun
Enable = TRUE

As you can see, Shell is the interesting variable: at boot-time, QNAP OS will launch each QPKG's Shell variable content.

Note: if your NAS doesn't have /share/MD0_DATA (i.e. is a one-drive NAS), put the right directory into the Shell and Install_Path variables and adapt the following commands to your needs.

Create the dummy package directory:
# mkdir /share/MD0_DATA/.qpkg/autorun

Create the autorun script with the contents of your choice:
# vi /share/MD0_DATA/.qpkg/autorun/
Note: don't forget "#!/bin/sh" at the beginning of script.

Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/autorun/
Reboot and enjoy!