[QPKG] SortMyQPKGs

This is the best place for community developers to publish their genius work. Your Apps enrich the QNAP Turbo NAS.
Post Reply
User avatar
Don
Guru
Posts: 12289
Joined: Thu Jan 03, 2008 4:56 am
Location: Long Island, New York

Re: [QPKG] SortMyQPKGs

Post by Don »

You can control the order. just read through the topic to see how.
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: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] SortMyQPKGs

Post by OneCD »

maroonwarrior71 wrote: Sun Jul 14, 2019 4:19 am Would it be possible to have QVPN start earlier in the Alpha list than Plex and xTeVe? Weird things happen sometimes when Plex starts with remote access without VPN, then VPN becomes active. I figure it'll be easily fixed by just starting QVPN first.
Okiedoke. Would it be better to move all the VPN apps to load before the media servers in ALPHA? Would there be any problems with this?
maroonwarrior71 wrote: Sun Jul 14, 2019 4:19 am Also - is there a way to do my own custom Alpha / Omega lists?
These posts discuss custom lists: Please test your preferred launch-order (VPNs before media servers) and post back any success or failure. :geek:

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
gibxxi
Know my way around
Posts: 180
Joined: Mon Mar 30, 2015 11:15 pm
Contact:

Re: [QPKG] SortMyQPKGs

Post by gibxxi »

Hi OneCD,

Been having an annoying issue with this add-on that I don't believe for a second is your fault, but annoying nonetheless.

Every time I do a Firmware update on either of my two QNAPs (See sig), SortMyQPKGs will stop working, or at least stop generating up-to-date logs on launch. The only way around this seems to be to completely uninstall the add-on, reboot, re-install, reboot again, and then (and only then) trigger a sort action, for it to work.

It does nothing on initial install as far as I can see. A reboot (post-install) is required, in my case, for it to work. I'm sure i've mentioned this before, but it might be a quirk in the QNAP firmware that affects my model(s) as from a hardware perspective, they're almost identical, that doesn't affect other (i.e: newer) models.

Just wondering if there's some way around this that doesn't require all this faffing-about, every time I upgrade to a new firmware version.

Regards,

Gib.
"Si vis pacem para bellum!"
NAS1: QNAP TS453-Pro (8GB, 4x4TB WD-Red), NAS2: QNAP TS453-Mini (8GB, 4x2TB WD-Red).
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] SortMyQPKGs

Post by OneCD »

Hey Gib. :D
gibxxi wrote: Sun Aug 11, 2019 4:36 am I'm sure i've mentioned this before, but it might be a quirk in the QNAP firmware that affects my model(s) as from a hardware perspective, they're almost identical, that doesn't affect other (i.e: newer) models.
Ah, that's entirely possible. I don't know how much variance there is to suit different models. From my observations, QNAP have created a single OS that adapts itself to different models automatically (except binaries, which are compiled to suit each different CPU arch). Unfortunately, this adaption is performed in BASH on every startup, which is why QTS is so slow to start. :S
gibxxi wrote: Sun Aug 11, 2019 4:36 am Just wondering if there's some way around this that doesn't require all this faffing-about, every time I upgrade to a new firmware version.
The hope is:
  1. When SortMyQPKGs is installed (or 'start'ed via the App Center), it inserts a hook into [/etc/init.d/shutdown_check.sh], but doesn't do anything else - no sorting is performed. This is an extract from the SortMyQPKGs init:

    Code: Select all

    case $1 in
        install|start)
            if ! (grep -q 'sort-my-qpkgs.sh' $SHUTDOWN_PATHFILE); then
                findtext='#backup logs'
                inserttext='/etc/init.d/sort-my-qpkgs.sh autofix'
                sed -i "s|$findtext|$inserttext\n$findtext|" $SHUTDOWN_PATHFILE
            fi
            if [[ $1 = install ]]; then
                RecordOperationRequest "$1"
                RecordOperationComplete "$1"
                CommitLog
            fi
            ;;
  2. When [/etc/init.d/shutdown_check.sh] is run on NAS poweroff/reboot, then a QPKG sort is performed, and the shutdown/reboot continues. This ensures QPKGS are ready to launch during the next powerup:

    Code: Select all

        autofix)
            RecordOperationRequest "$1"
            ShowSources >> $TEMP_LOG_PATHFILE
            Upshift $CONFIG_PATHFILE
            ShowPackagesBefore >> $TEMP_LOG_PATHFILE
            SortPackages
            ShowPackagesAfter >> $TEMP_LOG_PATHFILE
            RecordOperationComplete "$1"
            CommitLog
            ;;
So, if [/etc/init.d/shutdown_check.sh] isn't being run on your NAS during shutdown, or has different content to what SortMyQPKGs is looking for (which is the text '#backup logs'), then SortMyQPKGs will not operate automatically.

Can you please post the contents of your [/etc/init.d/shutdown_check.sh] script?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
gibxxi
Know my way around
Posts: 180
Joined: Mon Mar 30, 2015 11:15 pm
Contact:

Re: [QPKG] SortMyQPKGs

Post by gibxxi »

Hi OneCD,

Many thanks for the quick response. The only difference, hardware-wise that I can see between the TS453-Pro and TS453-Mini (Aside from the obvious visual difference), is that Drives 3 & 4 run off a 3Gbps SATA controller on the Mini, as a pose to a full-speed 6Gbps SATA controller on the Pro. The CPUs, installed memory (Which I've upgraded in mine), and core functionality of the units are the same. The Mini lacks the LCD of the Pro, but that isn't "core" hardware, so I discount that.

Contents of my shutdown_check.sh from the Pro, are posted below (Please bear in mind that at this time I have SortMyQPKGs in a working state, AFAIK):

Code: Select all

#!/bin/sh

# check if the HAL subsystem exist
if [ -x /sbin/hal_app ]; then
    BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
else
    BOOT_DEV="/dev/sdx"
fi

FLASH_RFS1=${BOOT_DEV}2
FLASH_RFS2=${BOOT_DEV}3
FLASH_TMP="/flashfs_tmp"
FLASH_TMP1="/flashfs_tmp1"
BOOT_CONF=`/bin/cat /etc/default_config/BOOT.conf 2>/dev/null`
SHUTDOWNLOCK=/var/lock/NAS/shutdown_check.lock

# check x86 boot device existence
if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ ! -f /var/qfunc/rcK ]; then
    /bin/dd if=${BOOT_DEV} of=/dev/null bs=512 count=1 2>/dev/null
    if [ $? != 0 ]; then
     # perform error recovery
       /sbin/rmmod ehci-hcd.ko
        /sbin/insmod /lib/modules/misc/ehci-hcd.ko
        sleep 3
        if [ -x /sbin/hal_app ]; then
            BOOT_DEV=$(/sbin/hal_app --get_boot_pd port_id=0)
        fi
    fi
fi

check_sum()
{
	if [ ! -f $1 ] || [ ! -f $2 ];then
		echo "${1} or ${2} not found."
		return 1
	fi
	
	local file_cksum=`/sbin/cksum $1`
	local file_crc=`echo $file_cksum | cut -d ' ' -f 1`
	local file_size=`echo $file_cksum | cut -d ' ' -f 2`

	local cksum_cksum=`cat $2`
	local cksum_crc=`echo $cksum_cksum | cut -d ' ' -f 1`
	local cksum_size=`echo $cksum_cksum | cut -d ' ' -f 2`

	if [ $file_crc = $cksum_crc ] && [ $file_size = $cksum_size ]; then
		return 0
	fi
	return 1
}

check_flash_files()
{
	local ckflag=0
	check_sum "${1}/boot/bzImage" "${1}/boot/bzImage.cksum"
	[ $? = 0 ] || ckflag=1
	check_sum "${1}/boot/initrd.boot" "${1}/boot/initrd.boot.cksum"
	[ $? = 0 ] || ckflag=1
	check_sum "${1}/boot/rootfs2.bz" "${1}/boot/rootfs2.bz.cksum"
	[ $? = 0 ] || ckflag=1
	check_sum "${1}/boot/rootfs_ext.tgz" "${1}/boot/rootfs_ext.tgz.cksum"
	[ $? = 0 ] || ckflag=1
	
	if [ $ckflag = 1 ]; then
		[ x"${1}" = x"${FLASH_TMP}" ] && /sbin/write_log "The first boot area on the flash is corrupted." 1
		[ x"${1}" = x"${FLASH_TMP1}" ] && /sbin/write_log "The second boot area on the flash is corrupted." 1
		return 1
	fi
	
	return 0
}

check_flash()
{
	[ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP
	/bin/mount ${FLASH_RFS1} $FLASH_TMP -o ro
	if [ $? != 0 ]; then
		/sbin/write_log "Flash read error." 1
	else
		check_flash_files $FLASH_TMP
	fi
	/bin/umount $FLASH_TMP
	/bin/sync
	/bin/mount ${FLASH_RFS2} $FLASH_TMP -o ro
	if [ $? != 0 ]; then
		/sbin/write_log "Flash read error." 1
	else
		check_flash_files $FLASH_TMP
	fi
	/bin/umount $FLASH_TMP
	/bin/sync	
	
	return 0
}

check_restore_flash()
{
	local status1=0
	local status2=0
	
	/bin/echo "Check/Restore Flash..."
	[ -d $FLASH_TMP ] || /bin/mkdir $FLASH_TMP
	[ -d $FLASH_TMP1 ] || /bin/mkdir $FLASH_TMP1
	/bin/mount ${FLASH_RFS1} $FLASH_TMP -o ro
	if [ $? != 0 ]; then
		/bin/umount ${FLASH_RFS1} 1>>/dev/null 2>>/dev/null
		/sbin/write_log "The first boot area on the flash is corrupted." 1
		status1=1
	else
		check_flash_files $FLASH_TMP
		[ $? = 0 ] || status1=1
	fi
	/bin/umount $FLASH_RFS1
	
	/bin/mount ${FLASH_RFS2} $FLASH_TMP1 -o ro
	if [ $? != 0 ]; then
		/bin/umount ${FLASH_RFS2} 1>>/dev/null 2>>/dev/null
		/sbin/write_log "The second boot area on the flash is corrupted." 1
		status2=1
	else
		check_flash_files $FLASH_TMP1
		[ $? = 0 ] || status2=1
	fi
	/bin/umount $FLASH_RFS2
	
	if [ $status1 = 0 ] && [ $status2 = 1 ]; then
		/bin/mount ${FLASH_RFS1} ${FLASH_TMP} -o ro
		/sbin/mke2fs -m0 -F -b 1024 -I 128 -L QTS_BOOT_PART3 ${FLASH_RFS2}
		/bin/sync
		sleep 1
		/bin/mount ${FLASH_RFS2} ${FLASH_TMP1}
		if [ $? = 0 ]; then
			/bin/cp -a ${FLASH_TMP}/. ${FLASH_TMP1}
			[ $? = 0 ] && /sbin/write_log "The second boot area on the flash has been recovered." 2
		fi
		/bin/umount ${FLASH_RFS2}
		/bin/umount ${FLASH_RFS1}
	elif [ $status1 = 1 ] && [ $status2 = 0 ]; then
		/bin/mount ${FLASH_RFS2} ${FLASH_TMP1} -o ro
		/sbin/mke2fs -m0 -F -b 1024 -I 128 -L QTS_BOOT_PART2 ${FLASH_RFS1}
		/bin/sync
		sleep 1
		/bin/mount ${FLASH_RFS1} ${FLASH_TMP}
		if [ $? = 0 ]; then
			/bin/cp -a ${FLASH_TMP1}/. ${FLASH_TMP}
			[ $? = 0 ] && /sbin/write_log "The first boot area on the flash has been recovered." 2
		fi
		/bin/umount ${FLASH_RFS1}
		/bin/umount ${FLASH_RFS2}
	fi

	[ ! -d $FLASH_TMP1 ] || /bin/rmdir $FLASH_TMP1
	
	return 0
}


check_ver_build()
{
	# check if version is the same between flash/disk
	FLASH_BUILD_NUM=`/sbin/getcfg System "Build Number" -d 0000 -f /etc/default_config/uLinux.conf`
	FLASH_VERSION=`/sbin/getcfg System "Version" -d 1.0.0 -f /etc/default_config/uLinux.conf`
	DISK_BUILD_NUM=`/sbin/getcfg System "Build Number" -d 0000 -f /etc/config/uLinux.conf`
	DISK_VERSION=`/sbin/getcfg System "Version" -d 1.0.0 -f /etc/config/uLinux.conf`
	if [ $FLASH_BUILD_NUM != $DISK_BUILD_NUM ]; then
		/sbin/write_log "The firmware versions of the system built-in flash ($FLASH_VERSION Build $FLASH_BUILD_NUM) and the hard drive ($DISK_VERSION Build $DISK_BUILD_NUM) are not consistent. It is recommended to update the firmware again for higher system stability." 2
	fi
}

write_dhcp_tftp_logs()
{
	# check if version is the same between flash/disk
	RET_UPDATECONFIG=`/sbin/getcfg "" "ret_updateconfig" -d "2" -f "/tmp/dhcp_tftp.log"`
	RET_TFTPSRVADDR=`/sbin/getcfg "" "ret_tftpsrvaddr" -d "2" -f "/tmp/dhcp_tftp.log"`
	RET_TFTPSRVNAME=`/sbin/getcfg "" "ret_tftpsrvname" -d "2" -f "/tmp/dhcp_tftp.log"`
	RET_TFTPBROADCAST=`/sbin/getcfg "" "ret_tftpbroadcast" -d "2" -f "/tmp/dhcp_tftp.log"`
	RET_BACKUPDRV=`/sbin/getcfg "" "ret_backupdrv" -d "2" -f "/tmp/dhcp_tftp.log"`
	
	if [ $RET_TFTPSRVNAME = 0 ] || [ $RET_TFTPSRVADDR = 0 ] || [ $RET_TFTPBROADCAST = 0 ] || [ $RET_BACKUPDRV = 0 ]; then
		/sbin/write_log "Download system configuration from TFTP server succeeded." 4
	else
		/sbin/write_log "Failed to download system configuration from TFTP server." 2
	fi
	if [ $RET_UPDATECONFIG = 0 ]; then
		/sbin/write_log "Update system configuration succeeded." 4
	else
		/sbin/write_log "Failed to update system configuration." 2
	fi
}

sync_power_recovery()
{
	ACTION=$1
	POWER_RESUME=`/sbin/getcfg Misc Power_Recovery_Mode -d 0`
	MMC_POWER_RESUME=`/bin/dd if=/dev/mmcblk0 bs=1c skip=8388608 count=1 | /usr/bin/hexdump -e '1/1 "%x"'` # read Power Recovery Status from eMMC 0x800000

	if [ $POWER_RESUME = 0 ]; then
		if [ $ACTION = "start" ] && [ $MMC_POWER_RESUME != 1 ]; then
			/bin/echo -en '\x01' | /bin/dd of=/dev/mmcblk0 seek=8388608 bs=1c count=1 # write Power Recovery Status into eMMC 0x800000
		fi
		if [ $ACTION = "stop" ] && [ $MMC_POWER_RESUME != 0 ]; then
			/bin/echo -en '\x00' | /bin/dd of=/dev/mmcblk0 seek=8388608 bs=1c count=1 # write Power Recovery Status into eMMC 0x800000
		fi
    elif [ $POWER_RESUME = 1 ]; then
        if [ $ACTION = "start" ] && [ $MMC_POWER_RESUME != 0 ]; then
            /bin/echo -en '\x00' | /bin/dd of=/dev/mmcblk0 seek=8388608 bs=1c count=1 # write Power Recovery Status into eMMC 0x800000
        fi
        if [ $ACTION = "stop" ] && [ $MMC_POWER_RESUME != 1 ]; then
            /bin/echo -en '\x01' | /bin/dd of=/dev/mmcblk0 seek=8388608 bs=1c count=1 # write Power Recovery Status into eMMC 0x800000
        fi
	elif [ $POWER_RESUME = 2 ] && [ $MMC_POWER_RESUME != 0 ]; then
		/bin/echo -en '\x00' | /bin/dd of=/dev/mmcblk0 seek=8388608 bs=1c count=1 # write Power Recovery Status into eMMC 0x800000
	fi

	MMC_POWER_RESUME=`/bin/dd if=/dev/mmcblk0 bs=1c skip=8388608 count=1 | /usr/bin/hexdump -e '1/1 "%x"'` # read Power Recovery Status from eMMC 0x800000
	if [ $MMC_POWER_RESUME = 0 ]; then
		/sbin/pic_raw 73
	else
		/sbin/pic_raw 72
	fi

	#EuP will cut off NAS Power after normal shutdowning
	if [ $ACTION = "stop" ]; then
		/bin/echo -en '\x00' | /bin/dd of=/dev/mmcblk0 seek=8388608 bs=1c count=1 # write Power Recovery Status into eMMC 0x800000
	fi
}

sync_eup()
{
	ACTION=$1
	EUP_STATUS=`/sbin/getcfg System "EUP Status" -d 1`
	MMC_EUP_STATUS=`/bin/dd if=/dev/mmcblk0 bs=1c skip=8388609 count=1 | /usr/bin/hexdump -e '1/1 "%x"'` # read EuP Status from eMMC 0x800001

	if [ $EUP_STATUS != $MMC_EUP_STATUS ]; then
		if [ $EUP_STATUS = 0 ]; then
			/bin/echo -en '\x00' | /bin/dd of=/dev/mmcblk0 seek=8388609 bs=1c count=1 # write EuP Status into eMMC 0x800001
		else
			/bin/echo -en '\x01' | /bin/dd of=/dev/mmcblk0 seek=8388609 bs=1c count=1 # write EuP Status into eMMC 0x800001
		fi
	fi

	if [ $EUP_STATUS = 0 ]; then
		/sbin/pic_raw 244
	else
		/sbin/pic_raw 245
	fi
}

sync_wol()
{
	ACTION=$1
	WOL_STATUS=`/sbin/getcfg Misc "Wake On Lan" -u -d TRUE`
	MMC_WOL_STATUS=`/bin/dd if=/dev/mmcblk0 bs=1c skip=8388610 count=1 | /usr/bin/hexdump -e '1/1 "%x"'` # read WoL Status from eMMC 0x800002

	if [ $MMC_WOL_STATUS = 0 ]; then
		MMC_WOL_STATUS="FALSE"
	else
		MMC_WOL_STATUS="TRUE"
	fi

	if [ $WOL_STATUS != $MMC_WOL_STATUS ]; then
		if [ $WOL_STATUS = "FALSE" ]; then
			/bin/echo -en '\x00' | /bin/dd of=/dev/mmcblk0 seek=8388610 bs=1c count=1 # write WoL Status into eMMC 0x800002
		else
			/bin/echo -en '\x01' | /bin/dd of=/dev/mmcblk0 seek=8388610 bs=1c count=1 # write WoL Status into eMMC 0x800002
		fi
	fi
}

Internal_Model=`/sbin/getcfg System "Internal Model"`

ha_handle_abnormal_shutdown()
{
    ha_conf_path="/etc/config/ha/qha.conf"
    if [ -f $ha_conf_path ]; then
        ha_enable=`/sbin/getcfg "Global" "ha_enabled" -d "no" -f $ha_conf_path`
        if [ "x$ha_enable" = "xyes" ]; then
            host_1_ip=`/sbin/getcfg Host1 wan_ip -f $ha_conf_path`
            wan_nic=`/sbin/getcfg Global nic_wan -f $ha_conf_path`
            my_ip=`/sbin/getcfg $wan_nic 'IP Address'`
            host_id="Host1"
            if [ "$host_1_ip" != "$my_ip" ]; then
                host_id="Host2"
            fi
            machine_state=`/sbin/getcfg $host_id machine_state -f $ha_conf_path`
            if [ "$machine_state" != "poweroff_a" -a "$machine_state" != "poweroff_s" -a "$machine_state" != "reboot_a" -a "$machine_state" != "reboot_s" ]; then
                /sbin/setcfg $host_id abnormal_shutdown yes -f $ha_conf_path
            fi
        fi
    fi
}

case "$1" in
    start)
	STARTED=`/sbin/getcfg Misc "System Started" -u -d FALSE`
	if [ $STARTED = TRUE ]; then
		echo "Last system shutdown process is incomplete."
		if [ -x /usr/local/sbin/notify ]; then
			/usr/local/sbin/notify send -A "A007" -C "C001" -l "warning" -t 1 -M "19" "[{0}] The system was not shut down properly last time." "%V015%"
		else
			/sbin/log_tool -t 1 -a "The system was not shut down properly last time."
		fi
		/sbin/daemon_mgr
		/sbin/daemon_mgr.nvr
	else
		/sbin/setcfg Misc "System Started" TRUE
	fi
	if [ -x /usr/local/sbin/notify ]; then
		/usr/local/sbin/notify send -A "A007" -C "C001" -l "info" -t 1 -M "18" "[{0}] System started." "%V015%"
	else
		/sbin/log_tool -t 0 -a "System started."
	fi
    RESULT=$?
	check_ver_build
	if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ "x$Internal_Model" != "xTS-269H" ] && [ "x$Internal_Model" != "xHS-200" ]; then
		check_restore_flash
	fi 
	[ -f /tmp/dhcp_tftp.log ] && write_dhcp_tftp_logs
    if [ -x /sbin/hal_event ]; then
        /sbin/hal_event --retrieve_booting_event
    else
        /sbin/kerrd
    fi
    # write Power Recovery flag into eMMC
    if [ "x$Internal_Model" = "xTS-269H" ] || [ "x$Internal_Model" = "xHS-200" ]; then
		sync_power_recovery start
		sync_eup start
    fi
	/usr/bin/readlink /mnt/HDA_ROOT/update 1>/dev/null 2>&1
	[ $? != 0 ] || rm -f /mnt/HDA_ROOT/update

    /etc/init.d/ipmi_check &
    ;;
    stop)
	[ -f $SHUTDOWNLOCK ] && exit 0
	/bin/date > $SHUTDOWNLOCK 2>&1
	/sbin/setcfg Misc "System Started" FALSE
    ha_handle_abnormal_shutdown
	if [ -x /usr/local/sbin/notify ]; then
		now_time=`/bin/date`
		/usr/local/sbin/notify send -A "A007" -C "C001" -l "info" -t 1 -M "17" "[{0}] System shut down on {1}." "%V015%" "${now_time}"
	else
		/sbin/log_tool -t 0 -a "System was shut down on `/bin/date`."
	fi
#wokes set rtc alarm    
	/sbin/gen_next_alarm 2
	cat /proc/acpi/alarm >  /etc/config/rtc_last_save
	cat /proc/driver/rtc >> /etc/config/rtc_last_save
#####   
	if [ -f /lib/libnetworkinterface.so ]; then
	    /usr/local/sbin/qsh NetworkService.wlan.sta.stop
	else
	    /etc/init.d/wireless.sh stop 1>/dev/null 2>/dev/null
	fi
	/bin/kill -9 `/bin/pidof daemon_mgr` 2>>/dev/null
	/bin/rm -f /etc/daemon_mgr.conf; /bin/touch /etc/daemon_mgr.conf
	pid=`pidof picd`
	[ "$pid" = "" ] || /bin/kill -9 $pid 2>>/dev/null
	pid=`pidof gpiod`
	[ "$pid" = "" ] || /bin/kill -9 $pid 2>>/dev/null
	pid=`pidof hwmond`
	[ "$pid" = "" ] || /bin/kill -9 $pid 2>>/dev/null
	pid=`pidof acpid`
	[ "$pid" = "" ] || /bin/kill -9 $pid 2>>/dev/null
	pid=`pidof gen_bandwidth`
	[ "$pid" = "" ] || /bin/kill -9 $pid 2>>/dev/null
	pid=`pidof qLogEngined`
	if [ "$pid" != "" ]; then
		/bin/kill -INT $pid 2>>/dev/null
		sleep 1
		/bin/kill -9 $pid 2>>/dev/null
	fi
	pid=`pidof qpkgd`
	if [ "$pid" != "" ]; then
		/bin/kill -INT $pid 2>>/dev/null
		sleep 1
		/bin/kill -9 $pid 2>>/dev/null
	fi
	pid=`pidof qNoticeEngined`
	if [ "$pid" != "" ]; then
		/bin/kill -INT $pid 2>>/dev/null
		sleep 1
		/bin/kill -9 $pid 2>>/dev/null
	fi
	
	pid=`pidof qsyslogd`
	if [ "$pid" != "" ]; then
		CMS_ENABLE=`/sbin/getcfg CMS Enable -d FALSE -f /etc/config/uLinux.conf`
		[ "x${CMS_ENABLE}" != xTRUE ] && /bin/kill -INT $pid 2>>/dev/null
		[ "x${CMS_ENABLE}" != xTRUE ] && sleep 1
		[ "x${CMS_ENABLE}" != xTRUE ] && /bin/kill -9 $pid 2>>/dev/null
	fi
	pid=`pidof qShield`
	if [ "$pid" != "" ]; then
		/bin/kill -INT $pid 2>>/dev/null
		sleep 1
		/bin/kill -9 $pid 2>>/dev/null
	fi

    if [ "x$Internal_Model" = "xTS-X41" ] || [ "x$Internal_Model" = "xTS-531P" ] || [ "x$Internal_Model" = "xTS-X32" ] || [ "x$Internal_Model" = "xTS-X32U" ]; then
        if [ `/sbin/getcfg "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then
            nic_num=`/sbin/getcfg "Network" "Interface Number" -d "1"`
            for (( i=0; i<$nic_num; i=i+1 ))
            do
                if [ "x`/bin/cat /sys/class/net/eth$i/carrier 2> /dev/null`" = "x" ]; then
                    /sbin/ifconfig "eth$i" up >/dev/null 2>&1
                    /usr/sbin/ethtool -s eth$i wol g >/dev/null 2>&1
                    sleep 1
                    /sbin/ifconfig "eth$i" down >/dev/null 2>&1
                else
                    /usr/sbin/ethtool -s eth$i wol g >/dev/null 2>&1
                fi
            done
        fi
    fi

	if [ "x$Internal_Model" = "xTS-119" ] || [ "x$Internal_Model" = "xTS-219" ] || [ "x$Internal_Model" = "xTS-419" ]; then
        if [ -x /sbin/hal_app ]; then
            if [ `/sbin/getcfg "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then
                /usr/sbin/ethtool -s eth0 wol d
                /usr/sbin/ethtool -s eth0 wol g
            fi
        else
            CPU_MODEL=""
            [ ! -f /proc/tsinfo/cpu_model ] || CPU_MODEL=`/bin/cat /proc/tsinfo/cpu_model | cut -d ' ' -f 1 2>/dev/null`
            if [ "x${CPU_MODEL}" = "x88F6282" ]; then
                if [ `/sbin/getcfg "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then
                    /usr/sbin/ethtool -s eth0 wol d
                    /usr/sbin/ethtool -s eth0 wol g
                fi
            fi
        fi            
	fi
	# write Power Recovery flag into eMMC
	if [ "x$Internal_Model" = "xTS-269H" ] || [ "x$Internal_Model" = "xHS-200" ]; then
		sync_power_recovery stop
		sync_eup stop
		sync_wol stop
	fi

    # Fix TS-509/TS-809 can't WOL
	if [ "x$Internal_Model" = "xTS-509" ] || [ "x$Internal_Model" = "xTS-809" ]; then
        /sbin/ifconfig eth0 down
        /sbin/ifconfig eth1 down
	fi

	/etc/init.d/sort-my-qpkgs.sh autofix
#backup logs
	[ ! -f /etc/logs/qsys.log ] || /bin/mv /etc/logs/qsys.log /etc/logs/qsys.log.1 2>/dev/null
	[ ! -f /etc/.qsys.log ] || /bin/mv /etc/.qsys.log /etc/logs/qsys.log 2>/dev/null

	#remove NVS qpke section
	[ ! -f /var/.remove_nvs_flag ] || /sbin/rmcfg netmgr -f /etc/config/qpkg.conf 2>/dev/null
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    *)
	echo "Usage: /etc/init.d/shutdown_check.sh {start|stop|restart}"
	exit 1
esac
Regards,

Gib.
"Si vis pacem para bellum!"
NAS1: QNAP TS453-Pro (8GB, 4x4TB WD-Red), NAS2: QNAP TS453-Mini (8GB, 4x2TB WD-Red).
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] SortMyQPKGs

Post by OneCD »

There are a few differences, mostly new additions. I compared yours (which QTS version?) with mine from QTS 4.2.6 #20190730:

Code: Select all

--- 4.2.6 shutdown_check.sh
+++ gib's shutdown_check.sh
@@ -295,13 +295,21 @@
 	STARTED=`/sbin/getcfg Misc "System Started" -u -d FALSE`
 	if [ $STARTED = TRUE ]; then
 		echo "Last system shutdown process is incomplete."
-		/sbin/log_tool -t 1 -a "The system was not shut down properly last time."
+		if [ -x /usr/local/sbin/notify ]; then
+			/usr/local/sbin/notify send -A "A007" -C "C001" -l "warning" -t 1 -M "19" "[{0}] The system was not shut down properly last time." "%V015%"
+		else
+			/sbin/log_tool -t 1 -a "The system was not shut down properly last time."
+		fi
 		/sbin/daemon_mgr
 		/sbin/daemon_mgr.nvr
 	else
 		/sbin/setcfg Misc "System Started" TRUE
 	fi
-	/sbin/log_tool -t 0 -a "System started."
+	if [ -x /usr/local/sbin/notify ]; then
+		/usr/local/sbin/notify send -A "A007" -C "C001" -l "info" -t 1 -M "18" "[{0}] System started." "%V015%"
+	else
+		/sbin/log_tool -t 0 -a "System started."
+	fi
     RESULT=$?
 	check_ver_build
 	if [ "x${BOOT_CONF}" = "xTS-NASX86" ] && [ "x$Internal_Model" != "xTS-269H" ] && [ "x$Internal_Model" != "xHS-200" ]; then
@@ -328,13 +336,22 @@
 	/bin/date > $SHUTDOWNLOCK 2>&1
 	/sbin/setcfg Misc "System Started" FALSE
     ha_handle_abnormal_shutdown
-	/sbin/log_tool -t 0 -a "System was shut down on `/bin/date`."
+	if [ -x /usr/local/sbin/notify ]; then
+		now_time=`/bin/date`
+		/usr/local/sbin/notify send -A "A007" -C "C001" -l "info" -t 1 -M "17" "[{0}] System shut down on {1}." "%V015%" "${now_time}"
+	else
+		/sbin/log_tool -t 0 -a "System was shut down on `/bin/date`."
+	fi
 #wokes set rtc alarm
 	/sbin/gen_next_alarm 2
 	cat /proc/acpi/alarm >  /etc/config/rtc_last_save
 	cat /proc/driver/rtc >> /etc/config/rtc_last_save
 #####
-	/etc/init.d/wireless.sh stop 1>/dev/null 2>/dev/null
+	if [ -f /lib/libnetworkinterface.so ]; then
+	    /usr/local/sbin/qsh NetworkService.wlan.sta.stop
+	else
+	    /etc/init.d/wireless.sh stop 1>/dev/null 2>/dev/null
+	fi
 	/bin/kill -9 `/bin/pidof daemon_mgr` 2>>/dev/null
 	/bin/rm -f /etc/daemon_mgr.conf; /bin/touch /etc/daemon_mgr.conf
 	pid=`pidof picd`
@@ -380,6 +397,23 @@
 		/bin/kill -9 $pid 2>>/dev/null
 	fi

+    if [ "x$Internal_Model" = "xTS-X41" ] || [ "x$Internal_Model" = "xTS-531P" ] || [ "x$Internal_Model" = "xTS-X32" ] || [ "x$Internal_Model" = "xTS-X32U" ]; then
+        if [ `/sbin/getcfg "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then
+            nic_num=`/sbin/getcfg "Network" "Interface Number" -d "1"`
+            for (( i=0; i<$nic_num; i=i+1 ))
+            do
+                if [ "x`/bin/cat /sys/class/net/eth$i/carrier 2> /dev/null`" = "x" ]; then
+                    /sbin/ifconfig "eth$i" up >/dev/null 2>&1
+                    /usr/sbin/ethtool -s eth$i wol g >/dev/null 2>&1
+                    sleep 1
+                    /sbin/ifconfig "eth$i" down >/dev/null 2>&1
+                else
+                    /usr/sbin/ethtool -s eth$i wol g >/dev/null 2>&1
+                fi
+            done
+        fi
+    fi
+
 	if [ "x$Internal_Model" = "xTS-119" ] || [ "x$Internal_Model" = "xTS-219" ] || [ "x$Internal_Model" = "xTS-419" ]; then
         if [ -x /sbin/hal_app ]; then
             if [ `/sbin/getcfg "Misc" "Wake On Lan" -u -d TRUE` = TRUE ]; then
@@ -410,9 +444,13 @@
         /sbin/ifconfig eth1 down
 	fi

-	#backup logs
+	/etc/init.d/sort-my-qpkgs.sh autofix
+#backup logs
 	[ ! -f /etc/logs/qsys.log ] || /bin/mv /etc/logs/qsys.log /etc/logs/qsys.log.1 2>/dev/null
 	[ ! -f /etc/.qsys.log ] || /bin/mv /etc/.qsys.log /etc/logs/qsys.log 2>/dev/null
+
+	#remove NVS qpke section
+	[ ! -f /var/.remove_nvs_flag ] || /sbin/rmcfg netmgr -f /etc/config/qpkg.conf 2>/dev/null
     ;;
     restart)
     $0 stop
But, as you mentioned, the hook is there and should be working properly.

If this is only happening when upgrading the QTS firmware, I wonder if the "live" version of [/etc/init.d/shutdown_check.sh] is replaced by the upgrade process before rebooting? Or maybe the firmware upgrade just doesn't execute this script? This would prevent QPKG sorting on shutdown. When the NAS starts-up and re-integrates each QPKG, SortMyQPKGs would restablish its hook. But then, no sorting would be performed until the next shutdown. This is as close as I can get to a possible explanation. :lol:

Something you might try when upgrading QTS again is:
  1. perform the upgrade via QTS UI (or CLI if that's your preference), but don't shutdown or reboot afterward,
  2. Then, find the App Center, 'stop' then 'restart' the SortMyQPKGs package, this will ensure the hook is reinstated,
  3. Then shutdown or reboot. Any change?
If this works, I'll need to adjust the hook insertion timing.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
gibxxi
Know my way around
Posts: 180
Joined: Mon Mar 30, 2015 11:15 pm
Contact:

Re: [QPKG] SortMyQPKGs

Post by gibxxi »

Hi OneCD,

Roger that m8. I'll follow your instructions on one NAS, do a standard upgrade (with a reboot) on the other, then save the respective shutdown_check.sh files, and see if I can see any notable differences. I'll PM you both as well, because I may not notice something you might do.

My firmware version, on both NAS devices, is: 4.3.6.0993 (20190704).
"Si vis pacem para bellum!"
NAS1: QNAP TS453-Pro (8GB, 4x4TB WD-Red), NAS2: QNAP TS453-Mini (8GB, 4x2TB WD-Red).
User avatar
gibxxi
Know my way around
Posts: 180
Joined: Mon Mar 30, 2015 11:15 pm
Contact:

Re: [QPKG] SortMyQPKGs

Post by gibxxi »

...Obviously, that will have to wait till the next release, whenever that occurs.

I'm not part of the QTS Beta program, so it will be a standard release firmware when I do.

Regards,

Gib.
"Si vis pacem para bellum!"
NAS1: QNAP TS453-Pro (8GB, 4x4TB WD-Red), NAS2: QNAP TS453-Mini (8GB, 4x2TB WD-Red).
nibbles2bits
Getting the hang of things
Posts: 50
Joined: Fri Aug 23, 2019 10:17 am

Re: [QPKG] SortMyQPKGs

Post by nibbles2bits »

I have a TS-451+ with QTS 4.3.6.1040 on my LAN behind a NAT router with internet access and Plex. I decided to add QVPN on my NAS so that it would be a client to my ISP's VPN server. The QVPN link becomes my NAS default gateway. By doing that, the Plex metadata traffic comes from a more generic location. This worked great, but I noticed QVPN was starting almost last. After running that way for a few weeks, I added SABnzbd, and was reminded I wanted to adjust the boot order. So I then found SMQ which looks exciting. Thanks for making it.

I installed SMQ. The ALPHA.default has Plex load before QVPN which isn't what I was after, but I left it on defaults. My result is as follows: after running ./sortmyqpkgs.sh fix and getting a good result, I rebooted the NAS. It lost network connectivity. QVPN can't connect. Stopping and starting the QVPN service has no positive affect. Because QVPN was previously my default gateway, and because QVPN won't run with when SMQs is installed, I'm left with a cascade of problems stemming from a lack of default gateway. The main problem is that without internet access App Center won't show me your app at all so that I can remove or stop the service. To get around being unable to stop/remove your app, I stopped QVPN and rebooted. That gave me a connection to the internet I could trust, after which I was able to stop SortMyQPKGs, start QVPN, and reboot my system again into a running state.

Some things I tried: I figured because I usually see QVPN starting so late that it might want to live in Omega. I put it just before SABnzbd, which is certainly very late, but no joy there. I still get a messed up network where QVPN can't load.

I'm really sorry about this post lacking quantitative data, but If you could direct me to the logs I need to find, I can make a gist.
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] SortMyQPKGs

Post by OneCD »

Hi and welcome to the forum. :)
nibbles2bits wrote: Fri Aug 23, 2019 8:06 pm I have a TS-451+ with QTS 4.3.6.1040 on my LAN behind a NAT router with internet access and Plex. I decided to add QVPN on my NAS so that it would be a client to my ISP's VPN server. The QVPN link becomes my NAS default gateway. By doing that, the Plex metadata traffic comes from a more generic location. This worked great, but I noticed QVPN was starting almost last.
Your suggestion sounds quite similar to the idea discussed in this post.

You might want to try creating a [ALPHA.custom] file from the existing [ALPHA.default] file, then edit [ALPHA.custom] and move all the VPN apps to load before the media-servers. Reboot. Any change?
nibbles2bits wrote: Fri Aug 23, 2019 8:06 pm Because QVPN was previously my default gateway, and because QVPN won't run with when SMQs is installed, I'm left with a cascade of problems stemming from a lack of default gateway.
Important: SortMyQPKGs only changes the QPKG launch-order. It doesn't alter the operation of installed packages in any way. It's entirely possible to get the same effect as that created by SortMyQPKGs by installing your QPKGs in a specific order. The purpose of SortMyQPKGs is to ensure your installed QPKGs are launched in a way that is most beneficial and with the least problems without needing to install each QPKG in a specific order.

However, the default order won't suit everyone in every situation, so it also supports custom lists where the user can re-arrange the launch order to suit their requirements. Which also means: custom lists can create more problems than they solve. :DD
nibbles2bits wrote: Fri Aug 23, 2019 8:06 pm I'm really sorry about this post lacking quantitative data, but If you could direct me to the logs I need to find, I can make a gist.
SortMyQPKGs creates a log file that records a QPKG list 'before' and 'after' sorting, but not much else. Any other logging would need to be performed by your individual QPKGs.

Can you post the full contents of your SortMyQPKGs log? If you have GUI access, find the SortMyQPKGs icon in your App Center, then click 'open'.

If you don't have GUI access, SSH into your NAS as the 'admin' user and check [/home/httpd/SortMyQPKGs.log]

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
nibbles2bits
Getting the hang of things
Posts: 50
Joined: Fri Aug 23, 2019 10:17 am

Re: [QPKG] SortMyQPKGs

Post by nibbles2bits »

I made a detailed reply but the forum banned me for spam.
I tried 9 custom ways of moving things, but none worked, mostly just qvpn to the near end.
Eventually I removed SMQs. At some point I will remove QVPN and SABnzbd and test again.
Thanks for your help.

EDIT: this might be only cosmetic, but I'll mention before I forget:
When doing ls -l the owner:group wasn't admin:administrators
I'm guessing it got your UID:GID of 100:100 or similar.
On my NAS, the group 100 isn't assigned by default.
Even though on my system the files were owned by a strange user and unknown group,
they were 644. So I didn't think it mattered.
A gist of my SMQ log

Cheers
User avatar
gibxxi
Know my way around
Posts: 180
Joined: Mon Mar 30, 2015 11:15 pm
Contact:

Re: [QPKG] SortMyQPKGs

Post by gibxxi »

Hi OneCD,

Got a prompt today to update noth NASes to firmware 4.3.6 build 1050 (20190830). I updated the TS453-Pro as per your posted instructions, and the TS453-Mini the way I usually do (i.e: allow the auto-reboot, post firmware update). I've saved the resulting "shutdown-check.sh" files from both, and will email you the files shortly, for comparison.

Curiously enough, I just tried a run of the app on both NASes, and it came up with the right date in the "Autofix Requested" message, so it seems to be working properly on both after *this* firmware update, but the time (BST) is one hour behind. The NAS itself is reporting the correct time (On the QTS desktop). The problem I previously reported may therefore be a non-issue at this stage. I can however confirm it's never worked after a firmware update prior to this one, without uninstall / re-install of the add-on.

I'll give it a few days and try another launch and see what happens then. These NASes are on 24/7 and are rarely rebooted unless absolutely required. It may just be the case that the requisite files have not been edited / re-written as part of this update, where in the past they might have been, who knows.

Dan / Gib.
"Si vis pacem para bellum!"
NAS1: QNAP TS453-Pro (8GB, 4x4TB WD-Red), NAS2: QNAP TS453-Mini (8GB, 4x2TB WD-Red).
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] SortMyQPKGs

Post by OneCD »

gibxxi wrote: Tue Sep 10, 2019 3:29 am Got a prompt today to update noth NASes to firmware 4.3.6 build 1050 (20190830). I updated the TS453-Pro as per your posted instructions, and the TS453-Mini the way I usually do (i.e: allow the auto-reboot, post firmware update). I've saved the resulting "shutdown-check.sh" files from both, and will email you the files shortly, for comparison.
Got 'em. Thank you. :geek:

Interestingly, the TS-453 Pro does not show an entry to run SortMyQPKGs, whilst the TS-453 mini does. This is completely backwards to what I thought would happen. :lol:

I'll need to ponder this when I'm a bit more awake.
gibxxi wrote: Tue Sep 10, 2019 3:29 am I'll give it a few days and try another launch and see what happens then. These NASes are on 24/7 and are rarely rebooted unless absolutely required. It may just be the case that the requisite files have not been edited / re-written as part of this update, where in the past they might have been, who knows.
Okiedoke, sounds good. Fingers crossed! :D

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
gibxxi
Know my way around
Posts: 180
Joined: Mon Mar 30, 2015 11:15 pm
Contact:

Re: [QPKG] SortMyQPKGs

Post by gibxxi »

OneCD wrote: Tue Sep 10, 2019 4:08 am ...

Interestingly, the TS-453 Pro does not show an entry to run SortMyQPKGs, whilst the TS-453 mini does. This is completely backwards to what I thought would happen. :lol:

I'll need to ponder this some more.

...
Equally dumbfounded m8. Like you, I expected exactly the opposite. I am 110% sure I've done the updates in the way described in the previous post (disclaimer: Not got the best short-term mermory). I'll report back in a few days as to the status of a new launch. I have to do another reboot on both to enforce the changes SortMyQpkgs has made (if any) from the last run anyhow, at some point.

:)

Dan / Gib.
"Si vis pacem para bellum!"
NAS1: QNAP TS453-Pro (8GB, 4x4TB WD-Red), NAS2: QNAP TS453-Mini (8GB, 4x2TB WD-Red).
User avatar
OneCD
Guru
Posts: 12037
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: [QPKG] SortMyQPKGs

Post by OneCD »

gibxxi wrote: Tue Sep 10, 2019 4:14 am I have to do another reboot on both to enforce the changes SortMyQpkgs has made (if any) from the last run anyhow, at some point.
Have you installed any new QPKGs since the firmware update? If not, the QPKG list order will remain the same as when SortMyQPKGs was last run.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Post Reply

Return to “Community Apps”