Running Your Own Application at Startup: Difference between revisions

From QNAPedia
Jump to navigation Jump to search
Add TAS-x68, TS-x28, TS-x31 and Al-based NAS
Nyax4 (talk | contribs)
Tag: visualeditor
 
(16 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Some advanced uses of your NAS may require you to run custom applications at boot-time. Even though QNAP NAS are Linux-based, you cannot use the usual Linux methods for launching an application at startup: default config files are reset on every startup.
Some advanced uses of your NAS may require you to run custom applications at boot-time. Even though QNAP NAS are Linux-based, you cannot use the usual Linux methods for launching an application at startup: default config files are reset on every startup.


 


== Skills required ==


== Skills required ==
*must be able to remote login via ssh or telnet (e.g. use '''SSH PuTTY''')
*must know how to edit files using nano, vi, or edit via SFTP (e.g. use '''WinSCP''')


*must be able to remote login via ssh or telnet (e.g. use '''SSH PuTTY''')
 
*must know how to edit files using nano, vi, or edit via SFTP (e.g. use '''WinSCP''')


== MTD-based method ==
== MTD-based method ==


autorun.sh is a script which will be executed on every startup of the TS-x09, TS-x19 and TS-x39. Editing this file allows you to start your own programs or overwrite config files with your own copies.
autorun.sh is a script which will be executed on every startup of the TS-x09, TS-x19 and TS-x39. Editing this file allows you to start your own programs or overwrite config files with your own copies.
 
 


=== Manual edit of autorun.sh ===
=== Manual edit of autorun.sh ===


#Log into your QNAP device using SSH or Telnet, for instance by using Putty
#Log into your QNAP device using SSH or Telnet, for instance by using Putty  
#Optional: install nano; use '''ipkg install nano''' & edit with nano instead of vi
#Optional: install nano; use '''ipkg install nano''' & edit with nano instead of vi  
#Mount config ramblock by finding your specific model below:
#Mount config ramblock by finding your specific model below:  


'''TS-201: ''' Mount the config ramblock /dev/mtdblock4:
'''TS-201: ''' Mount the config ramblock /dev/mtdblock4:


#mount -t ext2 /dev/mtdblock4 /tmp/config
#mount -t ext2 /dev/mtdblock4 /tmp/config  


'''TS-109, TS-109P, TS-110, TS-119,TS-209, TS-209P, TS-212, TS-219 '''(TS-219P II:since the new firmware update you maybe have to use ext4 instead of ext2)''', TS-409 (Marvell ARM), TS-412, TS-419P:'''
'''TS-109, TS-109P, TS-110, TS-119,TS-209, TS-209P, TS-212, TS-219 '''(TS-219P II:since the new firmware update you maybe have to use ext4 instead of ext2)''', TS-409 (Marvell ARM), TS-412, TS-419P:'''
Line 34: Line 41:
'''TS-269L: ''' Mount the config ramblock /dev/sdc6:
'''TS-269L: ''' Mount the config ramblock /dev/sdc6:
<pre>mount -t ext2 /dev/sdc6 /tmp/config</pre>
<pre>mount -t ext2 /dev/sdc6 /tmp/config</pre>
'''TS-212P3, TS-230: ''' Mount the config ramblock /dev/mmcblk0p5:
<pre>mount -t ext2 /dev/mmcblk0p5 /tmp/config</pre>


'''All HAL-based Intel and AMD NAS:'''
'''All HAL-based Intel and AMD NAS:'''
Starting from QTS 4.3.3 it's required to enable the autorun.sh processing in the Control Panel -> Hardware -> General: Run user defined startup processes (autorun.sh)
<pre>mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config</pre>
<pre>mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config</pre>
&nbsp;
'''''Create/Edit /tmp/config/autorun.sh'''''.
#either using vi: <pre># vi /tmp/config/autorun.sh</pre>
&nbsp;
#Get vi editor into edit mode:&nbsp;'''press a'''
##Edit whatever you need to
##Exit edit mode:&nbsp;'''press ESC'''
##Save and exit: '''x''' 
#or editing it using a desktop PC and e.g. SFTP
#Ensure that /tmp/config/autorun.sh is executable <pre># chmod +x /tmp/config/autorun.sh</pre>




&nbsp;


'''''Create/Edit /tmp/config/autorun.sh'''''.
#'''IMPORTANT:'''&nbsp;Unmount the mounted flash partition: <pre># umount /tmp/config</pre>


#either using vi:<br/><pre># vi /tmp/config/autorun.sh</pre>


#
&nbsp;
#Get vi editor into edit mode:&nbsp;'''press a'''
##Edit whatever you need to
##Exit edit mode:&nbsp;'''press ESC'''
##Save and exit: '''x'''
#or editing it using a desktop PC and e.g. SFTP
#Ensure that /tmp/config/autorun.sh is executable<br/><pre># chmod +x /tmp/config/autorun.s</pre>


#'''IMPORTANT:'''&nbsp;Unmount the mounted flash partition:<pre># umount /tmp/config</pre>
&nbsp;


=== '''editautorun.sh: script to ease autorun.sh edit''' ===
=== '''editautorun.sh: script to ease autorun.sh edit''' ===
Line 80: Line 102:
TS-439, TS-509, TS-639, TS-809, TS-809U (x86) use ...
TS-439, TS-509, TS-639, TS-809, TS-809U (x86) use ...
<pre>mount -t ext2 /dev/sdx6 /tmp/config
<pre>mount -t ext2 /dev/sdx6 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config
</pre>
TS-230 use ...
<pre>mount -t ext2 /dev/mmcblk0p5 /tmp/config
vi /tmp/config/autorun.sh
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
Line 111: Line 142:
echo "unmounting /tmp/config..."
echo "unmounting /tmp/config..."
umount /tmp/config
umount /tmp/config
ubidetach -m 6
</pre>
&nbsp;
=== '''Using "init" script to mount the flash''' ===
The QNAP GUI has the ability to view the autorun.sh content.&nbsp; As at V4.5.1.1540 on a TS-831XU-RP this is how the GUI does that:
<pre>/etc/init.d/init_disk.sh mount_flash_config
(displays /tmp/nasconfig_tmp/autorun.sh)
/etc/init.d/init_disk.sh umount_flash_config
</pre>
</pre>
Using these commands, you can create/edit the "autorun.sh" in the location given.
&nbsp;
=== '''Allow running autorun.sh during startup''' ===
After completing the autorun.sh, please don't forget to enable the option to allow running autorun.sh during the system startup. [[File:AllowAutorun2.png|RTENOTITLE]]

Latest revision as of 22:38, 8 June 2021

Some advanced uses of your NAS may require you to run custom applications at boot-time. Even though QNAP NAS are Linux-based, you cannot use the usual Linux methods for launching an application at startup: default config files are reset on every startup.

 

Skills required

  • must be able to remote login via ssh or telnet (e.g. use SSH PuTTY)
  • must know how to edit files using nano, vi, or edit via SFTP (e.g. use WinSCP)

 

MTD-based method

autorun.sh is a script which will be executed on every startup of the TS-x09, TS-x19 and TS-x39. Editing this file allows you to start your own programs or overwrite config files with your own copies.

 

 

Manual edit of autorun.sh

  1. Log into your QNAP device using SSH or Telnet, for instance by using Putty
  2. Optional: install nano; use ipkg install nano & edit with nano instead of vi
  3. Mount config ramblock by finding your specific model below:

TS-201: Mount the config ramblock /dev/mtdblock4:

  1. mount -t ext2 /dev/mtdblock4 /tmp/config

TS-109, TS-109P, TS-110, TS-119,TS-209, TS-209P, TS-212, TS-219 (TS-219P II:since the new firmware update you maybe have to use ext4 instead of ext2), TS-409 (Marvell ARM), TS-412, TS-419P:

Mount the config ramblock /dev/mtdblock5:

mount -t ext2 /dev/mtdblock5 /tmp/config

TS-439, TS-509, TS-639, TS-809, TS-809U (x86):

Mount the config ramblock /dev/sdx6:

mount -t ext2 /dev/sdx6 /tmp/config

TS-269L: Mount the config ramblock /dev/sdc6:

mount -t ext2 /dev/sdc6 /tmp/config

TS-212P3, TS-230: Mount the config ramblock /dev/mmcblk0p5:

mount -t ext2 /dev/mmcblk0p5 /tmp/config

All HAL-based Intel and AMD NAS:

Starting from QTS 4.3.3 it's required to enable the autorun.sh processing in the Control Panel -> Hardware -> General: Run user defined startup processes (autorun.sh)

mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config

 

Create/Edit /tmp/config/autorun.sh.

  1. either using vi:
    # vi /tmp/config/autorun.sh


 

  1. Get vi editor into edit mode: press a
    1. Edit whatever you need to
    2. Exit edit mode: press ESC
    3. Save and exit: x
  2. or editing it using a desktop PC and e.g. SFTP
  3. Ensure that /tmp/config/autorun.sh is executable
    # chmod +x /tmp/config/autorun.sh


 

  1. IMPORTANT: Unmount the mounted flash partition:
    # umount /tmp/config


 

 

editautorun.sh: script to ease autorun.sh edit

If you edit this file regularly you can save some time by creating a shell script (e.g. editautorun.sh) to automate the process. You can call the script by either putting it in the environment path, or add its folder to the path or call it by an alias.

The script contents are:

For TS-201 use ...

mount -t ext2 /dev/mtdblock4 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

For TS-109, TS-109P, TS-119, TS-209, TS-209P, TS-219, TS-412, TS-409 (Marvell ARM) use ...

mount -t ext2 /dev/mtdblock5 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

TS-439, TS-509, TS-639, TS-809, TS-809U (x86) use ...

mount -t ext2 /dev/sdx6 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

TS-230 use ...

mount -t ext2 /dev/mmcblk0p5 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

All HAL-based Intel and AMD NAS use ...

mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config
touch /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
$EDITOR /tmp/config/autorun.sh
umount /tmp/config

TAS-x68, TS-x28 use ...

/bin/mount -t ext4 /dev/mmcblk0p7 /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config

All AL-based NAS(TS-x31+ and TS-x31X) and TS-x31 use ...

ubiattach -m 6 -d 2
/bin/mount -t ubifs ubi2:config /tmp/config
vi /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
echo .
echo "unmounting /tmp/config..."
umount /tmp/config
ubidetach -m 6

 


Using "init" script to mount the flash

The QNAP GUI has the ability to view the autorun.sh content.  As at V4.5.1.1540 on a TS-831XU-RP this is how the GUI does that:

/etc/init.d/init_disk.sh mount_flash_config
(displays /tmp/nasconfig_tmp/autorun.sh)
/etc/init.d/init_disk.sh umount_flash_config

Using these commands, you can create/edit the "autorun.sh" in the location given.

 

Allow running autorun.sh during startup

After completing the autorun.sh, please don't forget to enable the option to allow running autorun.sh during the system startup. RTENOTITLE