[QPKG] RunLast

This is the best place for community developers to publish their genius work. Your Apps enrich the QNAP Turbo NAS.
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

[QPKG] RunLast

Post by OneCD »

Image

Description

RunLast creates an environment to run commands or shell-scripts after QPKG re-integration has occurred during QTS NAS bootup.

This allows you to run scripts dependent on QPKGs during QTS startup.


What it does

This package creates a scripts directory in the package installation path: Place your SysV-style scripts in the init.d directory. These will be executed with a start parameter after NAS startup, and with a stop parameter before NAS shutdown. Scripts in the scripts directory will be executed only during startup, and always after the custom init.d start script execution.


Installation
  • available in the MyQNAP repo, and can also be installed via the sherpa package manager.

Notes
  • When this package is installed, there's not much to see. Find the package icon and click the 'Open' button to display the current log file - any stdout and stderr from your scripts will be shown here.
  • The log file is viewable via your web browser but is not a real web document, so it can change without your browser noticing. Whenever viewing the log, ensure you force a page refresh: CTRL+F5.
  • To jump to the scripts directory:

    Code: Select all

    cd $(getcfg RunLast Scripts_Path -f /etc/config/qpkg.conf)
  • Or, to jump to the init.d directory:

    Code: Select all

    cd $(getcfg RunLast SysV_Path -f /etc/config/qpkg.conf)
  • The source for this project can be found on GitHub.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
peelos
Been there, done that
Posts: 580
Joined: Sun Jun 26, 2016 9:28 pm

Re: [QPKG] RunLast

Post by peelos »

Many thanks OneCD, will be interesting to read peoples use cases for this App.
NAS: TVS-1282-i7-7700-40G / 4 x 500GB SSD 2.5" RAID 10 / 2 x 500GB M.2 SSD / 8 x 12TB WD Whites 3.5" RAID 6 / Noctua L9x65 / 3 x 80mm PWM Noctua fans / Corsair 600W PSU / Asus Turbo GTX 1060 6GB GPU
Software: Plex Media Server / Transmission / Sonarr / Radarr / Bazarr / Jackett / Tautulli / Home Assistant / Resilio Sync / Python / NetData / SortMyQPKGs
pfSense Firewall / OpenVPN Server: QOTOM Fanless Mini PC / Core i5 / 8GB RAM / 128GB SSD / 4 Gigabit NICs / AES-NI
Wireless Routers: 2 x Netgear AC1900 R7000 Nighthawk / 1 x Netgear AC3200 R8000 Nighthawk / FreshTomato Firmware
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] RunLast

Post by OneCD »

No worries @peelos, hopefully it will have some value. I’ll be testing and tweaking it for a while. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
L3rd
Know my way around
Posts: 164
Joined: Thu Sep 20, 2007 8:11 pm

Re: [QPKG] RunLast

Post by L3rd »

I'm using the qpkg on a TS-212p to re-enable a swap-file stored on a usb key after each reboot:

Code: Select all

swapon /share/external/sdr1/myswapfile
Thanks!
NAS:
QNAP TVS-682 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .FW: 4.5.2.xxxx
QNAP TS-351 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .FW: 4.5.2.xxxx
QNAP TS-509 Pro . . [Xeon L5408(SLBBT)] . . . . . . . . . . . . . . . FW: 4.2.6 Build 20200821 (2020-09-02) (TS-809 Pro)
QNAP TS-212P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FW: 4.3.3.1432
QNAP TS-109 Pro . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FW: 3.3.3 build 1003 (2014-10-09)
QNAP QG-103N QGenie . . . . . . . . . . . . . . . . . . . . . . . . . . . . . FW: 3.2.3 (2018/08/10)
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] RunLast

Post by OneCD »

L3rd wrote: Sat Jan 19, 2019 4:52 am I'm using the qpkg on a TS-212p to re-enable a swap-file stored on a usb key after each reboot:
Nice! :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
Don
Guru
Posts: 12289
Joined: Thu Jan 03, 2008 4:56 am
Location: Long Island, New York

Re: [QPKG] RunLast

Post by Don »

Nice. I like the idea of the script directory. I am assuming that you should name your files so they sort in the order you want them to execute? Like the following for example.

01-StartDNSMASq.sh
02-Aliases.sh
03-xxx.sh
04-aaa.sh
Use the forum search feature before posting.

Use RAID and external backups. RAID will protect you from disk failure, keep your system running, and data accessible while the disk is replaced, and the RAID rebuilt. Backups will allow you to recover data that is lost or corrupted, or from system failure. One does not replace the other.

NAS: TVS-882BR | F/W: 5.0.1.2346 | 40GB | 2 x 1TB M.2 SATA RAID 1 (System/VMs) | 3 x 1TB M.2 NMVe QM2-4P-384A RAID 5 (cache) | 5 x 14TB Exos HDD RAID 6 (Data) | 1 x Blu-ray
NAS: TVS-h674 | F/W: 5.0.1.2376 | 16GB | 3 x 18TB RAID 5
Apps: DNSMasq, PLEX, iDrive, QVPN, QLMS, MP3fs, HBS3, Entware, DLstation, VS, +
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] RunLast

Post by OneCD »

Don wrote: Sun Jan 20, 2019 5:27 am I am assuming that you should name your files so they sort in the order you want them to execute?
Yes, that's correct (I really need to add a bit more detail to the first post).

@Don, while you're there, I've been toying with the idea of creating a symlink to a location that's easier for users to get to. Maybe [/scripts/runlast/]?

What are your thoughts?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
Don
Guru
Posts: 12289
Joined: Thu Jan 03, 2008 4:56 am
Location: Long Island, New York

Re: [QPKG] RunLast

Post by Don »

Where would "/scripts/runlast/" be located?
Use the forum search feature before posting.

Use RAID and external backups. RAID will protect you from disk failure, keep your system running, and data accessible while the disk is replaced, and the RAID rebuilt. Backups will allow you to recover data that is lost or corrupted, or from system failure. One does not replace the other.

NAS: TVS-882BR | F/W: 5.0.1.2346 | 40GB | 2 x 1TB M.2 SATA RAID 1 (System/VMs) | 3 x 1TB M.2 NMVe QM2-4P-384A RAID 5 (cache) | 5 x 14TB Exos HDD RAID 6 (Data) | 1 x Blu-ray
NAS: TVS-h674 | F/W: 5.0.1.2376 | 16GB | 3 x 18TB RAID 5
Apps: DNSMasq, PLEX, iDrive, QVPN, QLMS, MP3fs, HBS3, Entware, DLstation, VS, +
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] RunLast

Post by OneCD »

If it would help you test it, run this to create the symlink:

Code: Select all

mkdir /scripts && ln -s $(getcfg RunLast Install_Path -f /etc/config/qpkg.conf)/scripts /scripts/runlast

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
cactoid
New here
Posts: 4
Joined: Sat Jun 01, 2019 3:11 am

Re: [QPKG] RunLast

Post by cactoid »

Thanks for the recommendation - my server starts up on boot now :D

A quick question, if I login to the web dashboard/admin page on the QNap I see a notification stating that RunLast is starting up - even though my server is already up and running

If I shutdown my node server (QNap is still running) then the notification disappears

Is this expected or should I be formatting my script differently in order to have the node server run in the background?

Code: Select all

#!/bin/bash
node /myDir/myApp/myapp.js &
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] RunLast

Post by OneCD »

cactoid wrote: Mon Jun 03, 2019 10:21 pm Is this expected or should I be formatting my script differently in order to have the node server run in the background?
Good question. To test, you might try running your shell-script manually to launch your JS. Does control return to the BASH prompt? Or does it wait until your JS completes (or is shutdown)?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
cactoid
New here
Posts: 4
Joined: Sat Jun 01, 2019 3:11 am

Re: [QPKG] RunLast

Post by cactoid »

OneCD wrote: Tue Jun 04, 2019 4:36 am Good question. To test, you might try running your shell-script manually to launch your JS. Does control return to the BASH prompt? Or does it wait until your JS completes (or is shutdown)?
If I run the script manually control does return to the prompt
Although even with the notification displayed it doesn't seem to cause any issues using QNap as normal - will have another look today
LightMoon
New here
Posts: 8
Joined: Sun Sep 08, 2019 7:58 am

Re: [QPKG] RunLast

Post by LightMoon »

OneCD wrote: Sun Jan 20, 2019 7:40 am If it would help you test it, run this to create the symlink:

Code: Select all

mkdir /scripts && ln -s $(getcfg RunLast Install_Path -f /etc/config/qpkg.conf)/scripts /scripts/runlast
I have created a script directory in the root; however, that directory has been deleted after firmware upgrade!
Is it expected?
Are there any other locations that I can create a directory which wouldn't be affected after FW upgrade?

Second question,
When I am creating a script bash file, should I change the permissions afterwards to make it executable?
User avatar
OneCD
Guru
Posts: 12010
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] RunLast

Post by OneCD »

Hi and welcome to the forum. :)
LightMoon wrote: Sun Sep 08, 2019 8:03 am I have created a script directory in the root; however, that directory has been deleted after firmware upgrade!
Is it expected?
It sure is. ;)

[/] is not a persistent location in QTS, so any directories need to be recreated after each poweron.
LightMoon wrote: Sun Sep 08, 2019 8:03 am Are there any other locations that I can create a directory which wouldn't be affected after FW upgrade?
Yes, use the scripts directory indicated by this QPKG. i.e.

Code: Select all

$(getcfg RunLast Install_Path -f /etc/config/qpkg.conf)/scripts
The code you first used to create [/scripts] isn't part of this package yet. It essentially creates a symlink to a "virtual" [/scripts/runlast] directory. This would allow you to put scripts into it and they'll remain persistent, but will only be accessible after each reboot if that same symlink is recreated.

I put that code up so the community could test and advise if they find it easier to navigate to [/scripts/runlast] rather than the "real" location under this QPKG. I'm still waiting to hear back. ;)
LightMoon wrote: Sun Sep 08, 2019 8:03 am When I am creating a script bash file, should I change the permissions afterwards to make it executable?
Yes.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Turbo_112
Starting out
Posts: 22
Joined: Wed May 07, 2014 2:26 am
Location: The Netherlands

Re: [QPKG] RunLast

Post by Turbo_112 »

After the last update of RunLast my script doesn't start anymore. It stays in the script directory. The LastRun log gives a exitcode 1.
In terminalscreen (Putty) it works fine.
The Qnap log says Starting and Ending the scripts, but it gives no username in the log like other apps.
What's going wrong ?

This is the script:

#!/bin/bash
sudo --user=XXXXX /share/Download/nzbget/nzbget -D
exit 0
Post Reply

Return to “Community Apps”