Skip to content

Commit

Permalink
Merge pull request #341 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored Aug 15, 2024
2 parents 6a7546e + c7f0132 commit 1c9fcc3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v3.5.98
- Changed to automatically download and install dtc if all of the following 4 conditions are met:
1. dtc is not already installed.
2. /bin/dtc or dtc are not in the same folder as the script.
3. The script needs dtc.
4. The script is running from task scheduler.
- Bug fix for "Enable write_mostly on slow internal drives so DSM runs from the fast internal drive(s)." Issue #340
- Improved output to make it clear which drive(s) have most_writely set.

v3.5.97
- Changed silently skip empty .db.new files with showing an error. Issue #175
- Changed to warn if db file is 0 bytes.
Expand Down
55 changes: 44 additions & 11 deletions syno_hdd_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# /var/packages/StorageManager/target/ui/storage_panel.js


scriptver="v3.5.97"
scriptver="v3.5.98"
script=Synology_HDD_db
repo="007revad/Synology_HDD_db"
scriptname=syno_hdd_db
Expand Down Expand Up @@ -1564,6 +1564,33 @@ EOM2D17
fi
}

is_schedule_running(){
# $1 is script's filename. e.g. syno_hdd_db.sh etc
local file="/usr/syno/etc/esynoscheduler/esynoscheduler.db"
local rows offset task status pid result

# Get number of rows in database
rows=$(sqlite3 "${file}" <<ECNT
SELECT COUNT(*) from task;
.quit
ECNT
)
# Check if script is running from task scheduler
offset="0"
while [[ $rows != "$offset" ]]; do
task=$(sqlite3 "$file" "SELECT operation FROM task WHERE rowid = (SELECT rowid FROM task LIMIT 1 OFFSET ${offset});")
if echo "$task" | grep -q "$1"; then
status=$(sqlite3 "$file" "SELECT status FROM task WHERE rowid = (SELECT rowid FROM task LIMIT 1 OFFSET ${offset});")
pid=$(echo "$status" | cut -d"[" -f2 | cut -d"]" -f1)
if [[ $pid -gt "0" ]]; then
result=$((result +pid))
fi
fi
offset=$((offset +1))
done
[ -n "$result" ] || return 1
}

install_binfile(){
# install_binfile <file> <file-url> <destination> <chmod> <bundled-path> <hash>
# example:
Expand All @@ -1580,6 +1607,8 @@ install_binfile(){
# Download binfile
if [[ $autoupdate == "yes" ]]; then
reply=y
elif is_schedule_running "$(basename -- "$0")"; then
reply=y
else
echo -e "\nNeed to download ${1}"
echo -e "${Cyan}Do you want to download ${1}?${Off} [y/n]"
Expand Down Expand Up @@ -1701,31 +1730,36 @@ done
set_writemostly(){
# $1 is writemostly or in_sync
# $2 is sata1 or sas1 or sda etc
local model
# Show drive model
model="$(cat /sys/block/"${2}"/device/model | xargs)"
echo -e "${Yellow}$model${Off}"

if [[ ${1::2} == "sd" ]]; then
# sda etc
# md0 DSM system partition
echo "$1" > /sys/block/md0/md/dev-"${2}"1/state
# Show setting
echo -n "$2 DSM partition: "
echo -n " $2 DSM partition: "
cat /sys/block/md0/md/dev-"${2}"1/state

# md1 DSM swap partition
echo "$1" > /sys/block/md1/md/dev-"${2}"2/state
# Show setting
echo -n "$2 Swap partition: "
echo -n " $2 Swap partition: "
cat /sys/block/md1/md/dev-"${2}"2/state
else
# sata1 or sas1 etc
# md0 DSM system partition
echo "$1" > /sys/block/md0/md/dev-"${2}"p1/state
# Show setting
echo -n "$2 DSM partition: "
echo -n " $2 DSM partition: "
cat /sys/block/md0/md/dev-"${2}"p1/state

# md1 DSM swap partition
echo "$1" > /sys/block/md1/md/dev-"${2}"p2/state
# Show setting
echo -n "$2 Swap partition: "
echo -n " $2 Swap partition: "
cat /sys/block/md1/md/dev-"${2}"p2/state
fi
}
Expand All @@ -1736,7 +1770,7 @@ if [[ $ssd == "yes" ]]; then

if [[ $ssd_restore == "yes" ]]; then
# Restore all internal drives to just in_sync
echo -e "\nRestoring internal drive's state:"
echo -e "\nRestoring internal drive's state"
for idrive in "${internal_drives[@]}"; do
#if ! grep -q "write_mostly"; then
set_writemostly -writemostly "$idrive"
Expand All @@ -1745,7 +1779,7 @@ if [[ $ssd == "yes" ]]; then

elif [[ ${#ssds_writemostly[@]} -gt "0" ]]; then
# User specified their fast drive(s)
echo -e "\nSetting slow internal HDDs state to write_mostly:"
echo -e "\nSetting slow internal HDDs state to write_mostly"
for idrive in "${internal_drives[@]}"; do
if [[ ! ${ssds_writemostly[*]} =~ $idrive ]]; then
set_writemostly writemostly "$idrive"
Expand All @@ -1756,13 +1790,12 @@ if [[ $ssd == "yes" ]]; then
# Get list of internal HDDs and qty of SSDs
internal_ssd_qty="0"
for idrive in "${internal_drives[@]}"; do
internal_drive="$(echo "$idrive" | awk '{printf $4}')"
if synodisk --isssd "$internal_drive" >/dev/null; then
if synodisk --isssd /dev/"${idrive:?}" >/dev/null; then
# exit code 0 = is not SSD
# exit code 1 = is SSD

# Add internal HDDs to array
internal_hdds+=("$internal_drive")
internal_hdds+=("$idrive")
else
# Count number of internal 2.5 inch SSDs
internal_ssd_qty=$((internal_ssd_qty +1))
Expand All @@ -1772,7 +1805,7 @@ if [[ $ssd == "yes" ]]; then
# Set HDDs to writemostly if there's also internal SSDs
if [[ $internal_ssd_qty -gt "0" ]] && [[ ${#internal_hdds[@]} -gt "0" ]]; then
# There are internal SSDs and HDDs
echo -e "\nSetting internal HDDs state to write_mostly:"
echo -e "\nSetting internal HDDs state to write_mostly"
for idrive in "${internal_hdds[@]}"; do
set_writemostly writemostly "$idrive"
done
Expand Down

0 comments on commit 1c9fcc3

Please sign in to comment.