[SCRIPT] create-autorun.sh

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
Post Reply
RichJacot
Starting out
Posts: 17
Joined: Fri Apr 24, 2020 9:16 pm

Re: [SCRIPT] create-autorun.sh

Post by RichJacot » Thu May 07, 2020 7:05 am

Yes, it has remained through all of my reboots. hmmm... It shouldn't?

[/share/CACHEDEV1_DATA/.system/autorun] # cd /
[/] # ll
total 4.0K
drwxr-xr-x 22 admin administrators 540 2020-05-06 17:27 ./
drwxr-xr-x 22 admin administrators 540 2020-05-06 17:27 ../
-rw-r--r-- 1 admin administrators 135 2020-05-06 17:25 1
drwxr-xr-x 2 admin administrators 2.1K 2020-05-06 17:22 bin/
drwxr-xr-x 15 admin administrators 21K 2020-05-06 17:35 dev/
drwxr-xr-x 34 admin administrators 3.2K 2020-05-06 17:35 etc/
drwxr-xr-x 2 admin administrators 40 2020-05-06 17:22 flashfs_tmp/
lrwxrwxrwx 1 admin administrators 13 2020-05-06 17:22 hd_root_tmp -> /mnt/HDA_ROOT/
drwxr-xr-x 4 admin administrators 80 2020-04-09 15:57 home/
drwxr-xr-x 7 admin administrators 4.4K 2020-05-06 17:23 lib/
lrwxrwxrwx 1 admin administrators 3 2020-05-06 12:21 lib64 -> lib/
lrwxrwxrwx 1 admin administrators 11 2020-05-06 12:21 linuxrc -> bin/busybox*
drwx------ 2 admin administrators 40 2020-04-09 15:58 lost+found/
drwxr-xr-x 13 admin administrators 280 2020-05-06 17:24 mnt/
drwxr-xr-x 2 admin administrators 40 2020-05-06 12:21 new_root/
drwxr-sr-x 2 admin administrators 200 2020-05-06 17:27 opt/
lrwxrwxrwx 1 admin administrators 19 2020-05-06 12:21 php.ini -> /etc/config/php.ini
drwxrwxrwx 2 admin administrators 40 2020-05-06 17:27 plex.transcoding.tmp/
dr-xr-xr-x 340 admin administrators 0 2020-05-06 12:21 proc/
drwxr-xr-x 2 admin administrators 240 2020-05-06 17:25 root/
drwxr-xr-x 2 admin administrators 40 2020-05-06 17:25 rpc/
drwxr-xr-x 2 admin administrators 9.6K 2020-05-06 17:26 sbin/
drwxrwxrwt 31 admin administrators 800 2020-05-06 17:25 share/
dr-xr-xr-x 12 admin administrators 0 2020-05-06 11:21 sys/
drwxrwxrwx 18 admin administrators 2.5K 2020-05-06 18:04 tmp/
drwxr-xr-x 9 admin administrators 200 2020-04-09 14:50 usr/
drwxr-xr-x 16 admin administrators 740 2020-05-06 18:04 var/
[/] #
TVS-672N - 32GB - 4.4.2.1270 - Static volume - RAID5 - 5 x 4TB -- RW Cache - RAID1 - 2 x 500GB M.2 SSD
TS-453B - 16GB - 4.4.2.1270 - Static volume - RAID5 - 4 x 3TB

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Thu May 07, 2020 7:12 am

RichJacot wrote:
Thu May 07, 2020 7:05 am
Yes, it has remained through all of my reboots. hmmm... It shouldn't?
Only that yours would be the first. QTS is an embedded OS. It's not like a regular Linux desktop or server distro. It has a preset and read-only filesystem image which is loaded on boot and expanded into RAM. So, user-created directories from the root filesystem are not saved or restored.

How are you checking your new tmpfs has been created?

What's the output from:

Code: Select all

df
... ?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

RichJacot
Starting out
Posts: 17
Joined: Fri Apr 24, 2020 9:16 pm

Re: [SCRIPT] create-autorun.sh

Post by RichJacot » Thu May 07, 2020 7:31 am

Yes, df. Let me remove my script and reboot to see if it stays. I haven't looked without my script in place.

I'll send you the outputs shortly.

Sent from my SM-N975U using Tapatalk

TVS-672N - 32GB - 4.4.2.1270 - Static volume - RAID5 - 5 x 4TB -- RW Cache - RAID1 - 2 x 500GB M.2 SSD
TS-453B - 16GB - 4.4.2.1270 - Static volume - RAID5 - 4 x 3TB

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Thu May 07, 2020 7:50 am

I wonder if it's being created by something else after autorun.sh is executed?

Try your script with these mods:

Code: Select all

#!/bin/bash
TARGET_PATH=/plex.transcoding.tmp
[[ ! -d $TARGET_PATH ]] && { mkdir -p $TARGET_PATH; echo "created target" ;} || echo "target already exists"
/bin/mount -t tmpfs -o size=16G tmpfs $TARGET_PATH; echo "a:$?"
/bin/touch /share/CACHEDEV1_DATA/.system/autorun/scripts/plxran; echo "b:$?"

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

RichJacot
Starting out
Posts: 17
Joined: Fri Apr 24, 2020 9:16 pm

Re: [SCRIPT] create-autorun.sh

Post by RichJacot » Thu May 07, 2020 8:43 am

Sorry, to many users now. I'm going to have to do this in the morning.

Sent from my SM-N975U using Tapatalk

TVS-672N - 32GB - 4.4.2.1270 - Static volume - RAID5 - 5 x 4TB -- RW Cache - RAID1 - 2 x 500GB M.2 SSD
TS-453B - 16GB - 4.4.2.1270 - Static volume - RAID5 - 4 x 3TB

RichJacot
Starting out
Posts: 17
Joined: Fri Apr 24, 2020 9:16 pm

Re: [SCRIPT] create-autorun.sh

Post by RichJacot » Thu May 07, 2020 7:48 pm

Okay, I removed my script and sure enough my /plex.transcoding.tmp wasn't there. Interesting but I hadn't rebooted without my script in place and every time I looked my /plex.transcoding.tmp dir was there.

I made the changes you suggested and now it appears to be working perfectly now. /plex.transcoding.tmp is there, I can see it with df and below is the autorun.log

[/share/CACHEDEV1_DATA/.system/autorun/scripts] # cat /var/log/autorun.log
Thu May 7 06:27:14 CDT 2020 ----- running autorun.sh -----
Thu May 7 06:27:14 CDT 2020 - /share/CACHEDEV1_DATA/.system/autorun/scripts/PlexTranscodeRAMDrive.sh
created target
a:0
b:0
[/share/CACHEDEV1_DATA/.system/autorun/scripts] #

I ran a couple of streams earlier this morning that needed to be transcoded and I could watch /plex.transcoding.tmp grow.

Thank you Sir!
TVS-672N - 32GB - 4.4.2.1270 - Static volume - RAID5 - 5 x 4TB -- RW Cache - RAID1 - 2 x 500GB M.2 SSD
TS-453B - 16GB - 4.4.2.1270 - Static volume - RAID5 - 4 x 3TB

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Fri May 08, 2020 12:24 am

RichJacot wrote:
Thu May 07, 2020 7:48 pm
I ran a couple of streams earlier this morning that needed to be transcoded and I could watch /plex.transcoding.tmp grow.
Good work. :D

So, your script can now be reduced to:

Code: Select all

#!/bin/bash
TARGET_PATH=/plex.transcoding.tmp
[[ ! -d $TARGET_PATH ]] && mkdir -p $TARGET_PATH
/bin/mount -t tmpfs -o size=16G tmpfs $TARGET_PATH

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

RichJacot
Starting out
Posts: 17
Joined: Fri Apr 24, 2020 9:16 pm

Re: [SCRIPT] create-autorun.sh

Post by RichJacot » Fri May 08, 2020 1:50 am

Roger that and thanks again!
TVS-672N - 32GB - 4.4.2.1270 - Static volume - RAID5 - 5 x 4TB -- RW Cache - RAID1 - 2 x 500GB M.2 SSD
TS-453B - 16GB - 4.4.2.1270 - Static volume - RAID5 - 4 x 3TB

MikeLagit
Easy as a breeze
Posts: 299
Joined: Fri Mar 22, 2013 11:40 pm

Re: [SCRIPT] create-autorun.sh

Post by MikeLagit » Fri May 15, 2020 1:33 am

I'm using Entware with mlocate installed for indexing files for fast finds. I need to prune out the snapshots directory as it creates a ton of duplicates I don't care about. If I edit the /etc/updatedb.conf, it is overwritten at reboot. I don't see a way to implement a permanent version of the config file (correct me if I am wrong), so I resorted to this supercool tool from OneCD. I have it setup, but it's still getting overwritten at boot. Is this an ordering problem? I tested the script below and it adds the prunepath when run it manually, I just cant get it to stick after a reboot. Please see below and let me know if you have suggestions.
[~] # cat /etc/updatedb.conf
PRUNENAMES="/.AppleDB/.AppleDouble/.AppleDesktop/:2eDS_Store/Network Trash Folder/Temporary Items/TheVolumeSettingsFolder/.@__thumb/.@__desc/:2e*/.@__qini/.Qsync/.@upload_cache/.qsync/.qsync_sn/.@qsys/.streams/.digest/.*/"
The above output doesn't have my additional line and should look like this:
[~] # cat /etc/updatedb.conf
PRUNENAMES="/.AppleDB/.AppleDouble/.AppleDesktop/:2eDS_Store/Network Trash Folder/Temporary Items/TheVolumeSettingsFolder/.@__thumb/.@__desc/:2e*/.@__qini/.Qsync/.@upload_cache/.qsync/.qsync_sn/.@qsys/.streams/.digest/.*/"
PRUNEPATHS="/mnt/snapshot"
If I look at my logs it says the script was run:
[~] # cat /var/log/autorun.log
Thu May 14 12:15:02 CDT 2020 ----- running autorun.sh -----
Thu May 14 12:15:02 CDT 2020 - /share/CACHEDEV1_DATA/.system/autorun/scripts/010-mlocate.sh
Running it manually does add the prunepaths to the /etc/updatedb.conf (tested it manually to make sure script is valid and executable).
[~] # cat /share/CACHEDEV1_DATA/.system/autorun/scripts/010-mlocate.sh
#!/bin/bash
echo "PRUNEPATHS=\"/mnt/snapshot\"" >> /etc/updatedb.conf
Please let me know what I could be doing wrong. Is this a case for the RunLast qpkg?
Model: TS-877-1700 16GB
(HDD): [RAID-5] 4 x 8TB Seagate Ironwolf

Model:TS-569L 3GB
(HDD): [RAID-5] 4 x 3TB WD Red

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Fri May 15, 2020 4:47 am

MikeLagit wrote:
Fri May 15, 2020 1:33 am
Is this a case for the RunLast qpkg?
RunLast would be one way to do it. But the problem is that Entware can take some time to complete startup reintegration while the NAS is booting. RunLast may execute your script while Entware is unavailable. Which means you would need to introduce a wait-and-check poll to test for Entware availability over about a 10 minute period. This works but is not ideal.

A neater solution may be to use the init.d system included with Entware. This is just like the ancient init.d system included with QTS, but works with Entware installed IPKGs.

So, your script would be placed into [/opt/etc/init.d] and renamed to start with an 'S'. It will then run when Entware's startup reintegration is complete.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

MikeLagit
Easy as a breeze
Posts: 299
Joined: Fri Mar 22, 2013 11:40 pm

Re: [SCRIPT] create-autorun.sh

Post by MikeLagit » Fri May 15, 2020 5:32 am

I don't see any other S scripts in that dir. Is that the correct location? You're saying I can just move that script into that location and it should execute it?
[/opt/etc/init.d] # ll
total 16K
drwxr-xr-x 2 admin administrators 4.0K 2018-06-07 19:09 ./
drwxr-xr-x 6 admin administrators 4.0K 2020-04-28 17:03 ../
-rw-r--r-- 1 admin administrators 2.8K 2018-03-12 14:22 rc.func
-rwxr-xr-x 1 admin administrators 966 2018-03-12 14:22 rc.unslung*
[/opt/etc/init.d] #
Model: TS-877-1700 16GB
(HDD): [RAID-5] 4 x 8TB Seagate Ironwolf

Model:TS-569L 3GB
(HDD): [RAID-5] 4 x 3TB WD Red

User avatar
OneCD
Ask me anything
Posts: 7434
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD » Fri May 15, 2020 5:46 am

MikeLagit wrote:
Fri May 15, 2020 5:32 am
I don't see any other S scripts in that dir. Is that the correct location?
Which only means there are no currently installed IPKGs with init scripts. The only ones requiring init scripts are daemons.
MikeLagit wrote:
Fri May 15, 2020 5:32 am
You're saying I can just move that script into that location and it should execute it?
That's the theory. ;)

Try it and see. Add your script to that location, and rename it to prefix an 'S'. Then 'stop' - wait - then 'start' the Entware QPKG in your App Center (no need to reboot the NAS). This will run the same package reintegration process as when QTS is booting. When this completes, your script should be executed.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

MikeLagit
Easy as a breeze
Posts: 299
Joined: Fri Mar 22, 2013 11:40 pm

Re: [SCRIPT] create-autorun.sh

Post by MikeLagit » Fri May 15, 2020 12:18 pm

Worked like a charm! Thanks you for the help!!
Model: TS-877-1700 16GB
(HDD): [RAID-5] 4 x 8TB Seagate Ironwolf

Model:TS-569L 3GB
(HDD): [RAID-5] 4 x 3TB WD Red

Post Reply

Return to “Users' Corner”