[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
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

Qmann wrote: Tue Oct 06, 2020 12:53 pm SMP:
* New order *
(01) (A) Entware
(02) (A) NvKernelDriver
(03) (A) netmgr
(04) (A) NodeJS
(05) (A) QJDK8
(06) (A) container-station
(07) (A) Qapache
(08) (A) MySQL8
(09) (A) MultimediaConsole
(10) (A) HybridBackup
(11) (Φ) helpdesk
(12) (Φ) Qboost
(13) (Φ) ResourceMonitor
(14) (Φ) QKVM
(15) (Φ) PlexPy
(16) (Φ) QSubSonic
(17) (Φ) NotificationCenter
(18) (Φ) SSDLaboratory
(19) (Φ) SecurityCounselor
(20) (Φ) browser-station
(21) (Φ) iPerf3
(22) (Φ) LicenseCenter
(23) (Φ) QcloudSSLCertificate
(24) (Ω) MalwareRemover
(25) (Ω) SortMyQPKGs
Note that 'autorun.sh' is executed before nearly all QPKGs, and isn't a QPKG itself, so it's not shown in your package list. More details can be seen in the OP about this.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
Qmann
Easy as a breeze
Posts: 302
Joined: Mon Jun 08, 2020 8:09 am
Location: USA

Re: [SCRIPT] create-autorun.sh

Post by Qmann »

Thanks and it worked!

As I read up on this more, specifically to Plex, I ended up changing my container to make Plex run and root instead of a user, and then passing /dev/dri to the container was not problem on the permissions of the core system. This is the best solution so the QNAP system doesn't have to be touched, and should be safe running as root inside the container. I easily forget how careless you can be in a container and you don't always have to use a non-priv user to run stuff.

BTW - Thanks for the SMQPKGs app! It's amazing! :)

Qmann
Model: TVS-872XT 64GB (Crucial 64GB Kit CT2K32G4SFD8266)
2 x 1TB XPG 1TB NVMe (ASX8200PNP-1TT-C) [RAID-1]
5 x 16TB EXOS [RAID-5]
Borg Backup running to an offisite pi, AND to the local TS-569L
Model: TS-569L Borg server for backups
6 x 8TB Ironwolf [RAID-5]
Qotom-Q355G4 Fanless Mini Micro PC running pSense in front of everything
haproxy for anything inside the LAN
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

Qmann wrote: Wed Oct 07, 2020 11:22 am BTW - Thanks for the SMQPKGs app! It's amazing! :)
No worries mate! :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
LaRseTe
Starting out
Posts: 31
Joined: Fri Dec 23, 2016 5:59 pm

Re: [SCRIPT] create-autorun.sh

Post by LaRseTe »

Hi! did anyone have success using this or something similar when using an encrypted volume? I was hoping it to work while the volume was being unlocked but it doesn't :(
User avatar
Qmann
Easy as a breeze
Posts: 302
Joined: Mon Jun 08, 2020 8:09 am
Location: USA

Re: [SCRIPT] create-autorun.sh

Post by Qmann »

I haven't tried it on an encrypted volume, but it does work perfectly on unencrypted. Encryption seems to complicate a lot of things. :/ If you don't reboot the NAS very often (which most don't), you could unlock and run a small script.
Model: TVS-872XT 64GB (Crucial 64GB Kit CT2K32G4SFD8266)
2 x 1TB XPG 1TB NVMe (ASX8200PNP-1TT-C) [RAID-1]
5 x 16TB EXOS [RAID-5]
Borg Backup running to an offisite pi, AND to the local TS-569L
Model: TS-569L Borg server for backups
6 x 8TB Ironwolf [RAID-5]
Qotom-Q355G4 Fanless Mini Micro PC running pSense in front of everything
haproxy for anything inside the LAN
LaRseTe
Starting out
Posts: 31
Joined: Fri Dec 23, 2016 5:59 pm

Re: [SCRIPT] create-autorun.sh

Post by LaRseTe »

LaRseTe wrote: Mon Apr 05, 2021 6:46 am Hi! did anyone have success using this or something similar when using an encrypted volume? I was hoping it to work while the volume was being unlocked but it doesn't :(
At first I didn't realize this was just an easy and automatic way to accomplish this: https://wiki.qnap.com/wiki/Running_Your ... at_Startup

But doing it, the new autorun file is stored inside the encrypted volume, so what I had to do for it to work with an encrypted volume is just perform the steps manually directly editing the "autorun.sh" file inside the config ramblock.
Ikario
New here
Posts: 8
Joined: Thu Sep 30, 2021 5:13 am

Re: [SCRIPT] create-autorun.sh

Post by Ikario »

Hi!
First of all, the info I found in this topic really helped me so I wanted to start by thanking everyone, especially OneCD.
I have a bit of a question that he or maybe others can help me with. I am running QuTS Hero 4.5.4
I need to run a script that does a few things:
1)Makes a backup of a few config folders
2)chmod /dev/dri so as to give another group access to the integrated GPU
3)use docker-compose to pull a few images and run my docker containers from a yml file.

I have the script and it works fine. I made an autorun script using QNAP included functionality, but it runs too early in the boot process.

Next I tried using entware init.d, made a script that runs my other script and put it on /opt/etc/init.d and it ran but still, too early and the docker-compose commands do nothing, probably because container station is not up yet. I tried adding a sleep command for 5 minutes but nope, it stops entware from starting for 5 minutes and container station runs after that.
I noticed that there's a package called RunLast that will run after all the opkgs are ran and that's pretty much what I need. However, I can't find it in the QNAP Club repository, probably because it's not out for QuTS Hero yet.
Is it possible to make it so that it could run on QuTS Hero? I know the source is out there, I have no experience creating QTS/QuTS packages, but I'd give it a shot if it were possible as the source is on GitHub (Thanks again, OneCD!)
Script on init.d

Code: Select all

#/usr/bin/env bash
/sbin/log_tool -t 0 -a "Ran init.d loader"
case "$1" in
    start)
        /share/ZFS20_DATA/docker/autorun.sh
        ;;
    stop)
        # perform your 'stop' actions here
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo -e "\n Usage: $0 {start|stop|restart}"
        ;;
esac
autorun.sh script:

Code: Select all

#/usr/bin/env bash
echo "Doing config backup with rsync"
sleep 300
/sbin/log_tool -t 0 -a "Doing config backup with rsync, using init.d"
rm -rf /share/ZFS20_DATA/docker/backups/snapshot3 &&
mv /share/ZFS20_DATA/docker/backups/snapshot2 /share/ZFS20_DATA/docker/backups/snapshot3 &&
mv /share/ZFS20_DATA/docker/backups/snapshot1 /share/ZFS20_DATA/docker/backups/snapshot2 &&
mv /share/ZFS20_DATA/docker/backups/snapshot0 /share/ZFS20_DATA/docker/backups/snapshot1 &&
rsync -aA --delete --link-dest=/share/ZFS20_DATA/docker/backups/snapshot1 /share/ZFS20_DATA/docker/config/ /share/ZFS20_DATA/docker/backups/snapshot0/ &&
echo "Updating Bazarr, Jackett, NZBGet, Transmission, Radarr, Sonarr,jDownloader2 and Emby"
/sbin/log_tool -t 0 -a "Updating Bazarr, Jackett, NZBGet, Transmission, Radarr, Sonarr, jDownloader2 and Emby"
chmod -R 770 /dev/dri
cd /share/ZFS20_DATA/docker
pwd
docker-compose pull
docker-compose up -d
docker image prune -f
/sbin/log_tool -t 0 -a "[Autorun] Docker Compose ran successfully using init.d"
echo "All done!"
Other than modifying RunLast, any other tips are appreciated too! Thanks everyone :)
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

Hi and welcome to the forum. :)
Ikario wrote: Tue Oct 12, 2021 5:51 am However, I can't find it in the QNAP Club repository, probably because it's not out for QuTS Hero yet.
Is it possible to make it so that it could run on QuTS Hero?
Good question. I've not been able to try QuTS, so I've no idea if the new OS requires different QPKGs.

Can you please try downloading and installing the RunLast package manually?

Code: Select all

cd /share/Public
curl https://raw.githubusercontent.com/OneCDOnly/RunLast/main/build/RunLast_210809.qpkg -o RunLast.qpkg
sh RunLast.qpkg
Does it work/not work?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Ikario
New here
Posts: 8
Joined: Thu Sep 30, 2021 5:13 am

Re: [SCRIPT] create-autorun.sh

Post by Ikario »

That worked, or I should say, it is now installed. I'm going to try adding my script in a few hours and will let you know if everything is working.

Let me know if there's any way I can help add that app to the QNAP Club repo. As a sidenote, SortMyQPKGs does appear in the QNAP club store for QuTS Hero. That might help narrow down the issue.

Thanks again!
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

I'll check out the Qnapclub repo and see if there's anything I can do.

Cheers!

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Ikario
New here
Posts: 8
Joined: Thu Sep 30, 2021 5:13 am

Re: [SCRIPT] create-autorun.sh

Post by Ikario »

Well, that's weird, it's now showing (It wasn't before). I'm 100% certain it was not showing because I searched for both SortMyQPKGs and RunLast but only the first appeared. Anyway, problem solved I guess, rebooting now and checking if it works.
I really can't thank you enough.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [SCRIPT] create-autorun.sh

Post by OneCD »

Image

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
Qmann
Easy as a breeze
Posts: 302
Joined: Mon Jun 08, 2020 8:09 am
Location: USA

Re: [SCRIPT] create-autorun.sh

Post by Qmann »

Ikario wrote: Tue Oct 12, 2021 5:51 am

Code: Select all

#/usr/bin/env bash
rm -rf /share/ZFS20_DATA/docker/backups/snapshot3 &&
mv /share/ZFS20_DATA/docker/backups/snapshot2 /share/ZFS20_DATA/docker/backups/snapshot3 &&
mv /share/ZFS20_DATA/docker/backups/snapshot1 /share/ZFS20_DATA/docker/backups/snapshot2 &&
mv /share/ZFS20_DATA/docker/backups/snapshot0 /share/ZFS20_DATA/docker/backups/snapshot1 &&
rsync -aA --delete --link-dest=/share/ZFS20_DATA/docker/backups/snapshot1 /share/ZFS20_DATA/docker/config/ /share/ZFS20_DATA/docker/backups/snapshot0/ &&
You may also want to look at rsnapshot. It does what you are trying to do above, only more elegant. :) It can do hourly, weekly, monthly, etc. and manage all the versions. I use it for my QNAP backups over VPN off-site to a rasperry pi/USB drive.

Q
Model: TVS-872XT 64GB (Crucial 64GB Kit CT2K32G4SFD8266)
2 x 1TB XPG 1TB NVMe (ASX8200PNP-1TT-C) [RAID-1]
5 x 16TB EXOS [RAID-5]
Borg Backup running to an offisite pi, AND to the local TS-569L
Model: TS-569L Borg server for backups
6 x 8TB Ironwolf [RAID-5]
Qotom-Q355G4 Fanless Mini Micro PC running pSense in front of everything
haproxy for anything inside the LAN
Ikario
New here
Posts: 8
Joined: Thu Sep 30, 2021 5:13 am

Re: [SCRIPT] create-autorun.sh

Post by Ikario »

Oh that's actually a great tip, looking at it right now, that was my very amateur solution to having multiple snapshots. Thank you!
millercentral
New here
Posts: 2
Joined: Wed Sep 15, 2021 7:51 am

Re: [SCRIPT] create-autorun.sh

Post by millercentral »

Does anyone know if this should work on QuTS Hero/ZFS? I'm running a TS-1273AU with QuTS hero and when I run this script I see the following:

Code: Select all

create-autorun.sh (210130)

info: NAS model: TS-1273AU-RP
info: QTS version: 5.0.0 #20210826
info: default volume: /share/ZFS1_DATA
done: DOM partition found (6)
fail: Unable to mount (ext2) DOM partition (6)! [mount: special device 6 does not exist]
fail: (autorun.sh) creation failed!
Any idea what I'm doing wrong? Thanks!
Post Reply

Return to “Users' Corner”