Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha v2 #3

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4eb2d1a
Added a base script to send diskstatus to kernel (now only for sdc)
sergi-casbas Jan 24, 2016
e17fa7a
Added a base script to blink lights on disk activity.
sergi-casbas Jan 24, 2016
b137d2c
Improved fan-daemon script in order to extract as constants as possib…
sergi-casbas Jan 24, 2016
30535f6
Added a entry in the changlog for the v2 alpha.
sergi-casbas Jan 24, 2016
3d4d00e
Removed .deb file. When v2 becomes a relese i make the correspondent …
sergi-casbas Jan 24, 2016
31fd105
Added the library script to control diskstatus. The function have onl…
sergi-casbas Jan 24, 2016
7725668
Created library to handle hdd leds.
sergi-casbas Jan 25, 2016
0e30c54
Removed debig code line
sergi-casbas Jan 26, 2016
de27316
Replaced individual scripts for only one scripts that put everything …
sergi-casbas Jan 26, 2016
aa2fc6e
Recoded script based on Jamie Lentin work. Basically is the same but …
sergi-casbas Jan 26, 2016
5bcb28b
Improved default variables validation.
sergi-casbas Jan 26, 2016
89e2d69
Rename to fit debain name policy.
sergi-casbas Jan 26, 2016
c6d74f7
Change hdd-leds name to fit debian policy.
sergi-casbas Jan 26, 2016
968805e
Change variable names to lowercase.
sergi-casbas Jan 26, 2016
f12d8a3
Added a /etc/dns-nas-utils.conf
sergi-casbas Jan 26, 2016
fcddf25
Daemons reestructuration, and new name assignment.
sergi-casbas Jan 27, 2016
078492b
Added copyright entries for each version.
sergi-casbas Jan 27, 2016
782735c
Update config files to fit new names.
sergi-casbas Jan 27, 2016
a18cc9f
Updated contorl file with new description and mantainer for version 2
sergi-casbas Jan 27, 2016
f862efb
Added new version informations to changelog.
sergi-casbas Jan 27, 2016
e51ffbe
Added new section explaining new external configuration file.
sergi-casbas Jan 27, 2016
940aa5c
Rename old daemon into the new library.
sergi-casbas Jan 27, 2016
6a6a83f
Remove relative paths to solve problems when the main script is calle…
sergi-casbas Mar 8, 2017
454090d
Automatically remove tmppath if exists before to start.
sergi-casbas Mar 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ thus::
wget https://github.com/lentinj/dns-nas-utils/raw/master/dns-nas-utils.deb
dpkg -i dns-nas-utils.deb

Configuration
=============

Some devices or users must need different configuraiton parameters in the daemon.
Available parameters are in a config file in etc/dns-nas-utils.conf. Check it for
more information.

Temperature
===========

Expand All @@ -18,12 +25,16 @@ Reads temperature (either via. I2C or ttyS1) and returns in degC. For example::
# dns_temp
38

Fan Control
===========
NAS utils daemon
================

A small shell-based daemon to control the fan based on NAS temperature. In
theory it can measure temperature of HDDs too, however hddtemp counts as
activity as far as the HDDs are concerned, so won't spin down.
activity as far as the HDDs are concerned, so won't spin down. It informs kernel
log on changes to easily track them if required.

It controls too hdd leds, to make it to blink on disk activity and send harddrive
power state information (idle/sleep/active) to the kernel.

Building package
================
Expand Down
6 changes: 6 additions & 0 deletions changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
dns-nas-utils (2.0-1)
* Added a new daemon to control all others from only one routine.
* Added HDD status to send messages to kernel about disk state (standby/active)
* Added messages to kernel for the fan daemon to inform about changes.
* Added hdd/usb leds blink on hdd/usb changes.

dns-nas-utils (1.5-1)
* Force lang to C in order to prevent UTF-8 multibyte error (thanks KiLMaN)

Expand Down
Binary file removed dns-nas-utils.deb
Binary file not shown.
2 changes: 1 addition & 1 deletion dns-nas-utils/DEBIAN/conffiles
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/etc/init.d/fan-daemon
/etc/init.d/dns-nas-utils-daemon
8 changes: 5 additions & 3 deletions dns-nas-utils/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
Package: dns-nas-utils
Version: 1.5
Version: 2.0
Section: admin
Priority: optional
Architecture: all
Installed-Size: 64
Maintainer: Jamie Lentin <[email protected]>
Maintainer: Sergi Casbas <[email protected]>
Description: Miscallaneous scripts for D-Link NASes, DNS-325 and DNS-320
This package contains:-
fan-daemon: Controls the fan based on hdd and board temperature
dns-nas-utils: Controls fan based on hdd and board temperature, send
kernel messages about system temp and hdd status and
handle hdd leds.
dns_temp: Fetches the temperature of the NAS, either via I2C or serial

4 changes: 2 additions & 2 deletions dns-nas-utils/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh -e

if [ -x "/etc/init.d/fan-daemon" ]; then
update-rc.d fan-daemon defaults >/dev/null
invoke-rc.d fan-daemon start || exit $?
update-rc.d dns-nas-utils-daemon defaults >/dev/null
invoke-rc.d dns-nas-utils-daemon start || exit $?
fi
2 changes: 1 addition & 1 deletion dns-nas-utils/DEBIAN/postrm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh -e

if [ "$1" = "purge" ] ; then
update-rc.d fan-daemon remove >/dev/null
update-rc.d dns-nas-utils-daemon remove >/dev/null
fi
18 changes: 18 additions & 0 deletions dns-nas-utils/etc/dns-nas-utils.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Use uncommented lines to change daemon configuration.

# High frequency sleep time (low frequency is high*10)
#frequency=0.75

# Fan hysteresis, low and high thresholds.
#low_thresh=45
#high_thresh=50
#hysteresis=2

# Temporary path for some file exchanges between different calls.
#tmppath="/run/dns-nas-utils"

# Default fan device
#fan_device="/sys/devices/gpio_fan/hwmon/hwmon0/fan1_target"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 My DNS has different path to the fan. It is great that I can configure it from here!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dobiatowski What's the path? Adding various paths to search for is probably a good idea. Or it could be the default is just wrong nowadays.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys,

In my DNS320 (old version) this path is the correct, but probably in the newer version or others the path is different.

I'm thinkint onto create a dialog assistant to configure with dpkg the dns-nas-utils.conf

What do you think about this?


# Pattern to found light device note '$1' special pattern.
#led_device="/sys/devices/gpio-leds/leds/dns320:orange:\$1/brightness"
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: fan-daemon
# Provides: dns-nas-utils
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fan daemon
# Description: Start the fan-controlling daemon for a DNS-325
# Short-Description: Special dlink hardware daemon.
# Description: Start DNS-320/325 daemon to control some hardware.
### END INIT INFO

# Author: Jamie Lentin <[email protected]>
# Modified by Sergi Casbas <[email protected]> to be a substitute for dns-nas-utils.

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="DNS-325 fan daemon"
NAME=fan-daemon
DESC="DNS-320/325 fan daemon"
NAME=dns-nas-utils
DAEMON=/usr/sbin/$NAME
DAEMON_ARGS=""
PIDFILE=/var/run/$NAME.pid
Expand Down
35 changes: 35 additions & 0 deletions dns-nas-utils/usr/lib/diskstatus
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
#
# Send diskstatus information to the kernel log (dmesg)
#
# Copyright (C) 2016 Sergi Casbas <[email protected]>
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.

# Set default value for local variables if not exists.
if [ -z "$tmppath" ]; then tmppath="/tmp"; fi
tmp_diskstatus="$tmppath/diskstatus"

# Clean and initialize temporary path.
mkdir -p $tmp_diskstatus
touch "$tmp_diskstatus/sda"
touch "$tmp_diskstatus/sdb"
touch "$tmp_diskstatus/sdc"

# Function to handle diskstatus.
function diskstatus ()
{
# It only works if the device exists, obviuously.
if [ -e "/dev/$1" ];then
# Read disk current status.
curr_status="$(hdparm -C /dev/$1 | grep state)"

# If the status has been changed, save new state and send message.
if [ "$curr_status" != "$(cat $tmp_diskstatus/$1)" ]; then
echo "$curr_status" > $tmp_diskstatus/$1
echo -e "nas-diskstatus ($1):\033[0m$curr_status" > /dev/kmsg
fi
fi
}
48 changes: 48 additions & 0 deletions dns-nas-utils/usr/lib/fanspeed
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
#
# Control diskstation fan
#
# v1-Copyright (C) 2012 Jamie Lentin <[email protected]>
# v2-Copyright (C) 2016 Sergi Casbas <[email protected]>
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.

# Set default value for local variables if not exists.
if [ -z "$low_thresh" ]; then low_thresh=45=; fi
if [ -z "$high_thresh" ]; then high_thresh=50; fi
if [ -z "$hysteresis" ]; then hysteresis=2; fi
if [ -z "$fan_device" ]; then fan_device="/sys/devices/gpio_fan/hwmon/hwmon0/fan1_target"; fi

# Set fan to maxium speed for safety. If the script crash at least the fan runs at max.
speed=6000
echo $speed > $fan_device

function set_fanspeed
{
# Search the highest temperature in dns_temp output.
temp=0
for t in "$(/usr/bin/dns_temp)"; do
[ $temp -lt $t ] && temp=$t
done

# Choose right fan speed base on maxium temperature.
if [ $temp -lt $((low_thresh - hysteresis)) ]; then
speed=0
elif [ $temp -lt $low_thresh ]; then
[ $speed -gt 3000 ] && speed=3000
elif [ $temp -lt $((high_thresh - hysteresis)) ]; then
speed=3000
elif [ $temp -lt $high_thresh ]; then
[ $speed -lt 3000 ] && speed=3000
else
speed=6000
fi

# If the current speed is not equal to the desired speed, change it an send message to kernel.
if [ $speed -ne "$(cat $fan_device)" ]; then
echo $speed > $fan_device
echo -e "fan-daemon:\033[0m Current temp is $temp degrees(C) set fan to: $speed RPM" > /dev/kmsg
fi
}
49 changes: 49 additions & 0 deletions dns-nas-utils/usr/lib/hdd-leds
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
#
# Routines to automatically or manually enable hdd leds.
#
# Copyright (C) 2016 Sergi Casbas <[email protected]>
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.

# Set default value for local variables if not exists.
if [ -z "$tmppath" ]; then tmppath="/tmp"; fi
if [ -z "$led_device" ]; then led_device="/sys/devices/gpio-leds/leds/dns320:orange:\$1/brightness"; fi
tmp_ledstatus="$tmppath/leds"

# Prepare temporary folders and files
mkdir -p $tmp_ledstatus
touch "$tmp_ledstatus/sda"
touch "$tmp_ledstatus/sdb"
touch "$tmp_ledstatus/sdc"

# Set a led value. ($1 is the device, $2 the value)
function set_led
{
echo $2 > "$(eval echo $led_device)"
}

# Light a led if required ($1 is the block device sd?, $2 is the led device).
function blink_led
{
# Only execute the routine if the device exists.
if [ -e "/dev/$1" ]; then
# Compare current status with saved status, if are different blink de light.
if [ "$(cat /sys/block/$1/stat)" != "$(cat $tmp_ledstatus/$1)" ]; then
cat /sys/block/$1/stat > $tmp_ledstatus/$1
set_led $2 255
else
set_led $2 0
fi
fi
}

# Do all leds to blink if required
function set_leds
{
blink_led sda l_hdd &
blink_led sdb r_hdd &
blink_led sdc usb &
}
50 changes: 50 additions & 0 deletions dns-nas-utils/usr/sbin/dns-nas-utils
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Daemon to control some hardware of dns-320/325
# For now it handle fanspeed, diskstatus and hdd-leds
#
# Copyright (C) 2016 Sergi Casbas <[email protected]>
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.

# Daemon default values (can be overrided by config file)
frequency=0.75
low_thresh=45
high_thresh=50
hysteresis=2
tmppath="/run/dns-nas-utils/"

# Default devices (are for a dns320).
fan_device="/sys/devices/gpio_fan/hwmon/hwmon0/fan1_target"
led_device="/sys/devices/gpio-leds/leds/dns320:orange:\$1/brightness"

# Load configuration variables
source /etc/dns-nas-utils.conf

# Include code of external libraries
source ../lib/diskstatus
source ../lib/hdd-leds
source ../lib/fanspeed

# Main bucle to process different tools in different frequencies.
# There is a bucle with a frequency 10 times higher than low frequency.
while true;
do
# Low frequency iteration.
# Show diskstatus when required in kernel messages.
diskstatus sda
diskstatus sdb
diskstatus sdc

# Check system temp and set fan speed.
set_fanspeed

# High frequency bucle iteration.
for i in `seq 1 10`;
do
set_leds # set hdd leds if required.
sleep $frequency
done
done
39 changes: 0 additions & 39 deletions dns-nas-utils/usr/sbin/fan-daemon

This file was deleted.

3 changes: 2 additions & 1 deletion dns-nas-utils/usr/share/doc/dns-nas-utils/copyright
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dns-nas-utils

Copyright 2011 Jamie Lentin <[email protected]>
v1-Copyright 2011 Jamie Lentin <[email protected]>
v2-Copyright 2016 Sergi Casbas <[email protected]>

The home page of dns-nas-utils is at:
https://github.com/lentinj/dns-nas-utils
Expand Down