Activation and Deactivation of Daemons in Fonz fun_plug 0.7

After installing Fonz’ fun_plug (see tutorial on this), you will probably want work with like NFS or Torrent. This tutorial will show you how to do this.

The commands below are ONLY for fun_plug Version 0.7

Continue reading Activation and Deactivation of Daemons in Fonz fun_plug 0.7

store-passwd.sh for the D-Link DNS-320 Sharecenter Pulse

The D-Link DNS-320 needs a different store-passwd.sh than the one supplied with Fonz fun_plug. Basically it is very simple if you look at the contents:

#!/ffp/bin/sh
 
echo "Saving Userdata to /usr/local/config/"
cp -f /etc/passwd /usr/local/config/
cp -f /etc/group /usr/local/config/
cp -f /etc/shadow /usr/local/config/
cp -f /etc/samba/smbpasswd /usr/local/config/

Run the following command to download it to the NAS:

wget http://wolf-u.li/u/172/ -O /ffp/sbin/store-passwd.sh

Then proceed with the installation of Fonz fun_plug.

Firmwareupgrade Procedure for NAS-Devices with fun_plug

Configuration interface for upgrading firmware
This procedure allows you to upgrade (or downgrade) the version of the firmware running on the NAS. Although backups are always nice (if you have that option), the data stored on the NAS is not affected. Similarly, any servers (daemons) running under fun_plug are also unaffected (although they are temporarily turned off and later turned on again).

Note that this somewhat elaborate procedure is needed if you are running fun_plug. If you do not have fun_plug installed, or it is no running, you can should use the simpler instructions provided by Conceptronic with the firmware file.

Checking the firmware version

You can tell which firmware version you are running by using a web browser:

  • browse to the CH3SNAS using an IP address (default is http://192.168.0.20) or a network name (maybe http://CH3SNAS)
  • If this brings you to a web page you created yourself, you are likely running fun_plug and have the lighttpd HTTP server running on port 80 and need to use port 81 to reach the configuration screen (e.g. using http://192.168.0.20:81). If you don’t know what funplug is, you are not using it and you can ignore this comment.
  • login as admin
  • Then go to: ”Configuration” >> ”Tools” >> ”Firmware”

This should get you to the screen shown in the picture.

Downloading firmware versions

An overview of the current stable version, any more recent beta (or “Release Candidate”) versions, or older versions can be found here.
The page contains links to sites where the firmware can be downloaded. After downloading the required version you will need to unzip or unrar it.

Installation if you don’t use funplug

If you are not running fun_plug, you can simplify things by following the instructions in the PDF readme file supplied with the downloaded firmware rather than following the fancier instructions below which assume you may be running various special servers and running with special settings.
So, in the following, we assume that you are running fun_plug.

Temporarily reactivate Telnet

If you are running funplug, it is likely that you enabled ssh (Secure Shell) and disabled telnet for security reasons. After the reboot, all modifications to /etc/passwd and /etc/group are gone, which is why we need to temporarily reactivate telnet to ensure that we can login after the upgrade:

  • run ssh (e.g. using PuTTY)
  • activate the telnet daemon so you can easily login later:
    cd /ffp/start
    ls -al telnetd.sh
    chmod a+x telnetd.sh
    ls -al telnetd.sh

    This means that on the next reboot telnet should be enabled.

Notes on CH3SNAS Firmware 1.05 regarding the fan

If you are upgrading from a pre-1.0.5 firmware version to version 1.0.5 or later, you may decide to replace the special fan control script “fanctl” from Fonz (see the fan control tutorial) with the standard fan control feature built into the Conceptronic firmware.

Which option is better? The firmware version 1.0.5 has a very simple fan control algorithm. The fan only runs when the internal temperature is 43°C or higher. This is a bit high. Furthermore, the fan speed does not depend on the temperature: the fan is either on or off. Fonz’ solution instead increases the fan speed as the temperature rises. This avoids the fan repeatedly turning on and off when the fan needs to spin, but doesn’t need to run at full speed.

If you decide to try the firmware’s solution, you can deactivate Fonz’ control program using:

cd /ffp/start
sh fanctl.sh status
ls -al fanctl.sh
chmod a-x fanctl.sh
ls -al fanctl.sh

The 2nd line reports whether the fanctl utility is running. The chmod a-x causes the special fan script to be disabled on the next reboot.

Temporarily disable funplug

Rename the file fun_plug to fun_plug.bak to deactivate ffp on the next boot. You can easily do this using e.g. Windows Explorer or using the command shell:

cd /mnt/HD_a2
ls fun_plug*
mv fun_plug fun_plug.bak
ls fun_plug*

Saving settings

Write down any special configurations you have set up in the system.

The main place to look is in the ”Advanced” tab of the Configuration web page. Write down a reminder to set any particular settings such as ”’users”’ who have access, ”’groups”’ you may have created, ”’ftp access”’ you may have given to groups, etc. If you forget to reconfigure these, you will find out later when e.g. an ftp account doesn’t work. Unfortunately there is no simple way to save these settings and later reload them: you will, for example, have to reenter or define new passwords.

The other setting worth saving is any non-default IP address or network name of your CH3SNAS.

Installing new firmware

Update the firmware via the web interface (see picture above). During the update, you will get a progress bar. Then, after confirmation, the CH3SNAS will reboot.

Next reset the CH3SNAS firmware settings to the factory defaults (the new firmware may interpret settings stored in Flash memory differently that the previous version). This step is mandatory to ensure correct operation!

  • Open the configuration page
  • Goto: Tools >> System >> Restore To Factory Default Settings

This will cause another reboot during which the IP address, group/user information, user privileges will be lost. Your browser may not find the device again if you use a non-default name. Try the default “http://CH3SNAS/” or using Conceptronic’s “Easy Search Utility” to find your NAS in the network.

Basic configuration

At this point, the administrator password is empty, so you can log onto the Config web page as admin with an empty password. Then you need to run Setup >> Run Wizard to get the basic settings correct again. These include

  • the admin password
  • timezone and daylight savings time setting
  • IP address (if set to static)
  • the network workgroup
  • the network name of the CH3SNAS

This will lead to a restart after which you will also be able to see the CH3SNAS under its original name on the network and the stored data should be accessible.

Fun_plug

At this point you cannot access the CH3SNAS via either telnet or ssh because an out-of-the-box CH3SNAS does not enable either daemon:

  • rename fun_plug.bak back to fun_plug using SAMBA (e.g. using Windows Exporer)
  • reboot the CH3SNAS (e.g. using the Configuration page: Tools >> System >> Restart).
    Note that before the reboot, your Config page is on port 80. It may be on port 81 after the reboot. From this point on telnet should work again.
  • Login with telnet and set the root password again using this procedure. This ends with running store-passwd.sh to save the password information.
  • deactivate telnet again (first be sure ssh is running!) using an ssh session on PuTTY:
    cd /ffp/start
    ls -al telnetd.sh
    chmod a-x telnetd.sh
    ls -al telnetd.sh
    sh telnetd.sh stop

    The final line stops the telnet daemon, so from this point on you (only) have access via the much more secure ssh.

User settings

You can now redefine any required user- and group settings (e.g. for ftp users).

Note that after updating the firmware, the NAS will spend a few hours reindexing the hard disks (searching for movies and audio-files) for the itunes and UPnP-services. You can stop this activity by deactivating the respective services.

Store-Passwd.sh for the DNS-343 and Acer easystore NAS

Fonz Version of the store-passwd.sh-Script for the DNS-343 and the Acer easystore NAS can be downloaded like this:

wget http://wolf-u.li/u/121 -O /ffp/sbin/store-passwd.sh

The Content of this script is the following:

#!/ffp/bin/sh
 
PATH=/ffp/sbin:/ffp/bin:$PATH
 
echo "Mounting flash ..."
mount -t minix /dev/mtdblock0 /sys/mtd1
mount -t minix /dev/mtdblock1 /sys/mtd2
 
echo "Updating files ..."
for d in /sys/mtd1 /sys/mtd2 /mnt/HD_a4/.systemfile/AccountFile /mnt/HD_b4/.systemfile/AccountFile; do
    if [ -d "$d" ]; then
	for f in /etc/passwd /etc/group /etc/shadow /etc/samba/smbpasswd; do
	    b=$(basename $f)
	    if [ -e "$d/$b" ]; then
		echo "  $d/$b"
		cp -f $f $d
	    fi
	done
    fi
done
 
echo "Unmounting ..."
sync
umount /sys/mtd1
umount /sys/mtd2
 
echo "Done."

Inspired by this Thread, i (Uli) did a rewrite of the store-passwd.sh-script. You need to use BASH for this to execute. Better use the Script above if you are not sure!

#!/ffp/bin/sh
# This script was written by Ulrich Wolf <ffp [a] wolf-u [dot] li>
# Inspired by the original Scripts of fonz and OneArmedMan
 
# Defining the various locations for these files:
BACKUPLOCATION[0]="/sys/mtd1"
BACKUPLOCATION[1]="/sys/mtd2"
BACKUPLOCATION[2]="/mnt/HD_a4/.systemfile/AccountFile"
BACKUPLOCATION[3]="/mnt/HD_b4/.systemfile/AccountFile"
 
# Defining the backup-locations of the files
BACKUPFILE[0]="/etc/shadow"
BACKUPFILE[1]="/etc/group"
BACKUPFILE[2]="/etc/passwd"
BACKUPFILE[3]="/etc/samba/smbpasswd"
# Inactive Files
#BACKUPFILE[4]="/etc/ftp_tbl"
#BACKUPFILE[5]="/etc/ftpgroup"
 
# Mounting the internal DRAM
mount -t minix /dev/mtdblock0 /sys/mtd1
mount -t minix /dev/mtdblock1 /sys/mtd2
 
# Iterate through the files for backup of the files
for BUFILESEQ in $(seq 0 $((${#BACKUPFILE[@]} - 1)))
do
	# Iterate through the backup-locations of the files
	for BULOCSEQ in $(seq 0 $((${#BACKUPLOCATION[@]} - 1)))
	do
		if [ -e ${BACKUPLOCATION[$BULOCSEQ]}/${BACKUPFILE[$BUFILESEQ]##*/} ]; then
			# File exists, copy the original one
			echo -n "${BACKUPFILE[$BUFILESEQ]##*/} found in ${BACKUPLOCATION[$BULOCSEQ]}, copying"
			cp -f ${BACKUPFILE[$BUFILESEQ]} ${BACKUPLOCATION[$BULOCSEQ]}/. 2> /dev/null && echo "done" || echo "failed"
		else
			# File does not exist, skip
			echo "${BACKUPFILE[$BUFILESEQ]##*/} not found in ${BACKUPLOCATION[$BULOCSEQ]}, skipping"
		fi
	done
done
 
 
echo -n "Flushing unwritten filesystem I/O buffers..."
sync && echo "done" || echo "failed"
 
# Unmount the internal DRAM
umount /sys/mtd1
umount /sys/mtd2
 
echo "Backup complete"
exit 0

Installation and Configuration of PHP on Fonz fun_plug 0.5

This tutorial is deprecated and should only be used with fonz fun_plug 0.5!
Please check the tutorial page for updated tutorials on this topic!

PHP is a server-side scripting language that is widely used for developing dynamic web sites. PHP allows custom software to run on the server (in our case the NAS) hosting the web site.

PHP scripts are typically embedded in HTML pages. When a browser requests such a HTML page, the scripts are executed by the PHP add-in module of the HTTP server (here: lighttpd). Usually the PHP code inserts some additional HTML content into the version of the HTML page that gets sent to the browser. The browser (“client”) itself thus doesn’t see the scripts which were executed on the server.

In this tutorial we assume that the lighttpd HTTP server is already installed on the NAS (see tutorial on installing lighttpd On bigger systems, PHP is sometimes used in combination with an Apache server (instead of the leaner lighttpd) and an SQL database. This widely-used bundle of software tools is sometimes known as LAMP: Linux, Apache, MySQL, PHP. The installation of MySQL on the NAS is covered in another tutorial.

Contents

PHP uses

With regular HTML pages, your web server can only provide static content: all users see the same set of pages and the pages don’t change until someone (e.g. manually) updates the stored HTML pages. A server-side scripting language like PHP helps if you need to add dynamic content, such as a visitor counter (see example code below) or maybe news-of-the-day.
Public domain as well as proprietary PHP software is available for various applications including:

Setting up PHP

Installation

Uli kindly provided a packaged version of php for the NAS in his repository.

PHP is not installed as part of fun_plug by default, but you should already have downloaded a copy as part of the general tutorial on how to download, install and upgrade packages. Let’s make sure you still have the latest version (as Uli upgrades his repository regularly). Note that the rsync command could take a while because it can download multiple packages depending on what is already in your /ffp/pkg/packages directory. Also note that you have to install curl additionally! As of PHP 5.2.17 you also have to install libiconv which is in fonz repository.

cd /ffp/pkg
funpkg -i /ffp/pkg/additional/dev-lang/php-*.tgz
funpkg -i /ffp/pkg/additional/net-misc/curl-*.tgz
funpkg -i /ffp/pkg/packages/libiconv-*.tgz

If you have a version of php installed that is outdated, you will need to run in upgrade mode instead (see here for help). Still, make sure you have curl and libiconv installed!

funpkg -u /ffp/pkg/additional/dev-lang/php-*.tgz
funpkg -u /ffp/pkg/additional/net-misc/curl-*.tgz
funpkg -u /ffp/pkg/packages/libiconv-*.tgz

Configuring PHP

PHP is configured with a file called php.ini. You thus need to copy one of the example-files from /ffp/etc/examples/ to /ffp/etc/ while renaming it to php.ini:

cp /ffp/etc/examples/php.ini-wolfuli /ffp/etc/php.ini

Configuring Lighttpd

To use PHP with the lighttpd-webserver, you have to use another configuration file as explained in the section on config files in the tutorial.

If you have a NAS other than the DNS-320, you execute the following:

cp /ffp/etc/examples/lighttpd.conf-with-php /ffp/etc/lighttpd.conf

If you have a DNS-320, you execute:

cp /ffp/etc/examples/lighttpd.conf-dns320 /ffp/etc/lighttpd.conf

Activation

Restart lighttpd to load the new configuration – including the PHP module. This can be done by rebooting the entire NAS or using

cd /ffp/start
sh lighttpd.sh restart

Testing PHP

You can test your installation of PHP by placing a file called index.php in the server.document-root directory (e.g. /mnt/HD_a2/www/pages) with the following content:

<H1>This is normal HTML</H1>
But the <U>following table</U> is generated by PHP:
<?php
phpinfo();
?>

PHP configuration information
Now go to the website on your NAS using the configured address and e.g. http://CH3SNAS:80. You should see a long page with configuration information for the PHP server as shown in the picture). This output is generated by the function call “phpinfo()“.

Using PHP

Let us now go back to a somewhat less intimidating and possibly even boring example: the standard “Hello World” in PHP. Copy and paste the following text to a file named helloworld.php and store it in the server.document-root:

<?php
echo "Hello World";
?>

Then go to the website on your NAS using the configured address and port and add /helloworld.php (the address may look like this: http://CH3SNAS/helloworld.php).

The following example shows a more complete web page (adapted from the lighttpd tutorial). It adds 3 features:

  • visitors are greeted using their IP address (using the $_SERVER['REMOTE_ADDR'])
  • any viewing of the web page triggers updates to a file (counter.txt) stored on the NAS
  • the web site uses counter.txt to show how often the page has been viewed

This requires three fragments of PHP code, each enclosed between and ?> tokens:

 
<?php
$fname = "counter.txt";             // The file where the number of hits gets stored
if(!file_exists($fname)) {          // If file doesn't exist..
    $countfile=fopen($fname,"a");   // .. create it
    $counter=0;                     // .. and initialize hit counter to zero
}
else {
    $countfile=fopen($fname,"r+");  // Open for read and write
    $counter=fgets($countfile,100); // Load number of hits by reading first 100 bytes
    rewind($countfile);             // Reset the file pointer to overwrite old counter value
}
$counter++;                         // Increment counter by one
fputs($countfile,$counter);         // Write the new value to the file
fclose($countfile);                 // Close the File
?>
 
<html>
    <head>
        <title>Hello PHP World!</title>
        <style type="text/css">
        <!--
                        h1 {text-align:center; font-family:Arial, Helvetica, Sans-Serif;}
                        h2 {text-align:center;}
                        p  {text-indent:20px;}
        -->
        </style>
    </head>
 
    <body bgcolor = "#ffffcc" text = "#0000ff">
        <h1>Welcome, <?php echo $_SERVER['REMOTE_ADDR']; ?>, <BR>to the PHP world</h1>
        <h2>This page was viewed <?php echo $counter; ?> times</h2>
        <p><A HREF="page1.html">Link to page1</A></p>
        <p><A HREF="page2.html">Link to page2</A></p>
        <p><A HREF="https://nas-tweaks.net/">external link</A></p>
    </body>
</html>

Output of final example
HTML output as visible using the browser's View Source feature

The first and by far the longest PHP section looks to see if a file name counter.txt exists in the server.document-root If it doesn't exist, it creates it and decides there have been zero hits so far ($counter=0). Note that variables in PHP do not need to be declared and start with a $ and that no clear distinctions are made between numeric and string variables: conversions are done on demand.

If the file already exists, the first 100 bytes (should be enough for a decent number) are copied into $counter. Then $counter is incremented, written to the counter.txt file and the file is closed.

The remaining HTML code is similar to the code in the lighttpd tutorial. In the level one header (H1), a string is generated by a PHP echo command which prints the IP address of the remote client. In the level two header the value of $counter that was previously computed is used.

Optional: Using shared extensions

PHP allows the use of additional modules, so called "shared extensions". E.g. there is calendar for calendar-related functions. The modules are stored in /ffp/lib/php/extensions/no-debug-non-zts-20060613/.

Available modules

You can list the available modules using:

ls -al /ffp/lib/php/extensions/no-debug-non-zts-20060613/*.so

As of version php-5.2.6-3 the following modules are available:

Module Description Requires installation of ffp package
calendar functions related to days/months/years and Unix timestamps -
ctype character type checking -
ftp File Transfer Protocol -
gd image processing libjpeg, libpng
mbstring manipulation of non-ASCII strings (e.g. unicode) -
mysql MySQL database access mysql
pdo PHP data objects -
pdo_mysql PDO interface to the MySQL database mysql
pdo_sqlite PDO interface to the SQLlite database -
sqlite SQLlite database access -
tokenizer access to PHP tokens found by the lexical analyzer -
zlib .gz file compression -

Editing php.ini

If you want to add one or more modules, you need to edit the file /ffp/etc/php.ini.
Open php.ini and find:

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;

And add below the extension you want. E.g. to enable the calendar extension, you add:

; Linux extensions
extension=calendar.so
;extension=ctype.so
;extension=ftp.so

Afterwards you have to restart lighttpd to load the changes.

Demo of calendar extension

To see whether or not calendar was indeed loaded, you could run the PHPinfo.php script shown above.
Or run a script calendar.php containing:

<?php
for ($year=2000;$year<2011;$year++) {
    $days = cal_days_in_month(CAL_GREGORIAN,2,$year);
    echo "February in $year has $days days <BR>";
}
?>

Notes

PHP and HTML

A page with PHP code is generally stored on disk as HTML code with one or more fragments of embedded PHP. When the HTTP sends delivers the actual page to the browser ("client") the PHP sections have been interpreted and removed. In general they have been replaced by additional HTML code (see the counter example above). The receiving client thus does not see the PHP code and cannot even directly know whether PHP has been used to generate the served page.

Short open tag

If you want to use "<?" instead of "<?php" to mark the start of PHP code fragments, you need to change change the value of "short_open_tag" (line 131) in /ffp/etc/php.ini file to On:

short_open_tag = On

This is a matter of taste and convenience. When you distribute PHP code for use in other servers, you need to keep in mind that they may be set to short_open_tag = Off.

File extensions and default file names

HTML pages containing PHP code should have a .php extension. This tells the lighttpd server to pass the code via the PHP preprocessor before sending it across the network.

When you access the lighttpd server without providing a specific file name, it successively checks for files in the server.document-root directory(typically /srv/www/pages/) named

  • index.php
  • index.html
  • index.htm
  • default.htm

This is defined in a parameter called index-file.names in the lighttpd.conf file. As the list suggests, if you have both an index.php file and an index.html file in the same directory, the index.php file has precedence. If you explicitly ask for index.html, however, you will get that file instead of index.php.

Stateless

Note that after a page has been processed, when a new request for the same page is made by the same or another client, all computation starts from scratch: PHP is "stateless" in the sense that variables such as $counter are all lost after the page request has been completed. So the only way to track state in a PHP server is to store information in a file (as in counter.txt above), to store information in a database (another tutorial), or to assume the client maintains any relevant information between one page request and the next one.

Learning the PHP language

There are numerous books (printed and online) on PHP. See for example php.net.

Dealing with PHP errors

PHP syntax errors messages are appended to the Lighttpd error.log file. So if you are experimenting with- or developing PHP code, it can help to keep an eye on that file.

Installation and Configuration of fanctl for Fonz fun_plug

This tutorial is deprecated and should only be used with fonz fun_plug 0.5!
Please check the tutorial page for updated tutorials on this topic!

The CH3SNAS, as well as other small nas devices, has a small fan at the back. This fan is necessary because the NAS can generate significant amounts of heat when one or two drives are used heavily.

CH3SNAS fan
Although the fan is speed-controlled through software provided by Conceptronic, the fan never switches off completely. Some people find this too noisy for quiet environments like bedrooms or even some offices. An obvious solution is to turn the CH3SNAS off entirely when it is not in use (e.g. at night), but this is very inconvenient and it gives problems when the CH3SNAS may be accessed occasionally by remote (Internet) users.

Thanks to the fun_plug, the user can change the fan control algorithm to reduce noise, save a bit of power and reduce wear on the fan itself.

Contents

  1. Replacing the default fan control software
    1. The standard fan control solution
    2. Using shell scripts versus using binaries
  2. Installation
    1. Installing fanctl
    2. Activating fanctl
  3. How fanctl works
    1. Warning!
    2. The graph
    3. Temperatures
    4. Fan speed
    5. Changing fanctl.conf
  4. Notes
    1. A CH3SNAS in a hot room
    2. Shut down on overheating
    3. Logging the temperature
    4. Deinstallation

Replacing the default fan control software

The standard fan control solution

By default, the fan is controlled by a program embedded within the CH3SNAS called fancontrol. This program adjusts the fan speed depending on the temperature measured inside the CH3SNAS.

Conceptronic also provides two other utilities which are helpful to control the fan:

  • temperature – shows the actual temperature (on some devices in Fahrenheit and on others in Celsius) by entering the command "temperature g 0"
  • fanspeed – returns the current fan speed when you enter "fanspeed g". It can also set a new fan speed by entering the command "fanspeed w YourFanSpeed" (where YourFanSpeed is the desired speed in Rotations Per Minute).

Using shell scripts versus using binaries

There are different ways to control the fan. In any case the new software needs to stop (“kill”) the built-in fancontrol program provided by Conceptronic before it takes over control.

One approach is to use the programs temperature and fanspeed within a simple bash script that repeatedly measures the temperature and adjusts the fan speed accordingly. Such a script can even choose to turn off the fan entirely below a certain temperature. But a script-based approach, which, compared to a compiled C program, uses more (valuable) memory and CPU cycles.

Fortunately Fonz, the author of fun_plug, has written a small and efficient binary program named fanctl. It controls the fan without relying on the temperature and fanspeed) programs and without using the bash shell. This efficiency is nice as the program is intended to run as long as the CH3SNAS is powered up. By default, fanctl adjusts the fan speed every 30 seconds if needed.

Installation

Installing fanctl

Uli has created a package to simplify installation of fanctl.

In this tutorial we assume that the fun_plug is already installed on the NAS and that you synchronized Uli’s repository (see here for instructions on how to do this). Afterwards install the package (see detailed instructions here):

funpkg -i /ffp/pkg/additional/ffp-misc/fanctl-*.tgz
cp /ffp/etc/examples/fanctl.conf /ffp/etc/fanctl.conf

The final steps copies default configuration settings to the appropriate directory.

Activating fanctl

Please make sure, that no other scripts than the original fancontroller are active! You can check this by:

ps aux|grep fan

This should show the following output (the process identification numbers will vary):

1431 root fancontrol
12620 root grep fan

These are all the running processes (ps) which were filtered (grep) on whether they include the text fan somewhere in their name. Despite appearances, [http://en.wikipedia.org/wiki/Ps_(Unix)#Options aux] is not a command or name, but 3 separate options for ps with a missing “-” this time.

Now test the first run of the fanctl script by entering the following command on the command line:

sh /ffp/start/fanctl.sh start

After entering the above command, the fan will run with a audible noise for a few seconds. You can check the correct opertion of fanctl now:

ps aux|grep fan

This should show the following output (again the PID numbers will vary):

12628 root     /ffp/sbin/fanctl /ffp/etc/fanctl.conf
12635 root     grep fan

This shows that the fancontrol process disappeared and was replaced by the fanctl process (with its configuration file).

As the last step, you can activate the daemon permanently:

chmod a+x /ffp/start/fanctl.sh

How fanctl works

To understand or to adjust the behaviour of fanctl, you may want to inspect its configuration file /ffp/etc/fanctl.conf. If you use the nanoeditor:

nano /ffp/etc/fanctl.conf

Under normal circumstances the defaults should be fine.

Warning!

Do not change these values unless you completely understand the consequences.
Overheated hard drives can lead to data loss or early drive failure. So if you want to change the settings in the configuration file, please study the following documentation carefully and test any modifications you make carefully.

The graph

The graph (by Uli) explains how the program adjusts the fan speed. It assumes the default settings (which you won’t change unless you need to and know what you are doing – right?). Room temperature is typically about 20 degrees Celcius (68 degrees Fahrenheit).

Fanctl adjusts the fan speed depending on the measured temperature

When you boot the CH3SNAS, but hardly use the drives the temperature should increase a few degrees, but stay well below 40 degrees. In that case, the fan follows the blue line: it stays off because there is no real need to cool the CN3SNAS yet. However, when you use the drives a lot, the temperature can rise above 40 degrees. Especially if the room temperature also happens to be hot. This causes the fan to switch on. The fan speed (in RPM) follows the curved slope (part of a parabolic curve). The maximum fan speed is limited by default to 6300 RPM (called pwm_hi). Like the original software, there is a actually a safety threshold as well: above 51 degrees, the CN3SNAS is turned off. The latter shouldn’t normally happen unless something goes very wrong (like a broken drive, or operating your CH3SNAS in the sauna).

Now assume that the CH3SNAS has become relatively hot (say 45 degrees Celcius), but the drives now enter a period of infrequent access. This causes the drive motors to automatically shut down, reducing heat production and causing the temperature to drop. Every 30 seconds, a drop in temperature will cause the fan to slow down. When the temperature drops below 40 degrees (called temp_hi) the fan speed stabilizes for a while. When the temperature then drops below 37 degrees (called temp_lo), the fan is turned off.

Note that turning the fan on and off occur at different temperatures. This is called (hysteresis). This reduces the chance that at some temperature the fan repeatedly runs for 30 seconds, then turns off for 30 seconds, and then turns on again.

Temperatures

If you want to change the temperatures (e.g. if the fan never switches off completely (NAS too warm) or you want to cool it down to a certain level), there are various values in the script for configuring these. All values have to be set in Celsius*1000! E.g. 40°C would be 40000

There are four different values:

  • temp_stop: If the temperature decreases below this value, the fan is set to the speed, which is configured as the variable pwm_stop (normally this will be zero and thus stops the fan). If the temperature rises about this temperature, nothing happens (hysteresis). Default is 37 degrees Celcius.
  • temp_lo: If the temperature rises above this temperature, pwm_start will be set for one second (Starts the fan). After this, the fan speed will be adjusted somewhere beween pwm_lo and pwm_hi – depending on the measured temperature. If the temperature drops below this temperature, the fan runs at pwm_lo (hysteresis). Default is 40 degrees Celcius.
  • temp_hi: If the temperature rises above this value, pwm_hi is set as fan speed. Default is 50 degrees Celcius.
  • temp_crit: If the temperature rises above this value, the CH3SNAS is shut down to prevent damage. Default is 51 degrees Celcius. Be extra careful with this value.

Fan speed

If you want to change the fan speed (e.g. if you think, the fan turns too slowly or if you want the fan to idle and not to stop), there are various values in the script for configuring these.

  • pwm_stop: This is the speed which is set below temp_stop. If set to zero, the fan will halt. It may not be a good idea to use really low non-zero values here (difficult to run the fan smoothly at these speeds).
  • pwm_start: This is the speed which is set for one second if pwm_stop was set and the temperature rises above temp_lo again. (Default: 3200 rpm)
  • pwm_lo: This is the speed which is set at temp_lo. (Default: 2700 rpm)
  • pwm_hi: This is the speed which is set at temp_hi. (Default: 6300 rpm)

Between pwm_lo and pwm_hi the fan speed will be interpolated according to the following formula:

RPM = (pwm_hi - pwm_lo) * (temp - temp_lo) / (temp_hi - temp_lo) * (temp - temp_lo) / (temp_hi - temp_lo) + pwm_lo

Changing fanctl.conf

Again, editing fanctl.conf should be done with care. Just editing the file will not cause the new values to be used immediately because the running program reads the file once when it starts. One safe way to reload a modified /ffp/etc/fanctl.conf file is to simply reboot the CH3SNAS. When the program is started, it will load the modified /ffp/etc/fanctl.conf file. Another way is to use

cd /ffp/start
sh fanctl.sh status
sh fanctl.sh restart
sh fanctl.sh status

The sh fanctl.sh retart stops and restarts the fan. Actually between the stop and the restart, fancontrol is briefly run.

Notes

A CH3SNAS in a hot room

According to the graph, if you put the CH3SNAS in a very hot environment (e.g. 38 degrees Celcius), the fan will turn on – even when the hard disks are not being used. Turning the fan on wouldn’t help lower the device temperature: it will only get the device temperature closer to room temperature. Currently the software cannot distinguigh this condition (but this obviously also applies to the default fancontrol software which never turns the fan off).

Shut down on overheating

In exceptional conditions, the CH3SNAS will shut down if it ever reaches temp_crit (typically 51′ Celcius). When it shuts down, it will create a file named OVERHEAT in the root directory. By checking for this file and its creation or modification time, you can get confirmation about the cause of the shutdown.

See the file /ffp/etc/fanctl.conf for more details how this works.

Logging the temperature

From an E-mail exchange with fonz (this hasn’t been tested):

PeterH> Other features might be more fun (e.g. log of temperature?).

That’s pretty easy. Just change /ffp/start/fanctl.sh and replace

/ffp/sbin/fanctl $fanctl_config >/dev/null 2>/dev/null </dev/null &

with

/ffp/sbin/fanctl $fanctl_config >/mnt/HD_a2/fan.log 2>&1 </dev/null &

You can plot nice graphs from the log file using gnuplot:

gnuplot> set timefmt "%Y-%m-%d %H:%M:%S"
gnuplot> set xdata time
gnuplot> plot '< grep fan /path/to/fan.log' u 1:4 w st, '' u 1:8 w st

Deinstallation

If you deinstall fanctl using

funpkg -r /ffp/pkg/additional/fanctl-2-1.tgz

and reboot your CH3SNAS, you will find using

ps aux|grep fan

that the original fancontrol appication automatically reappears. This is because fanctl is activated via a script (/ffp/start/fanctl.sh) that stops the default fancontrol process before starting the fanctl program.

This implies that deinstalling funplug and rebooting will also return fan behaviour back to the default behavior and default mechanisms provided by Conceptronic.

Installing and Uninstalling Packages and Activation and Deactivation of Daemons in Fonz fun_plug 0.5

After installing Fonz’ fun_plug (see tutorial on this), you will probably want additional packages or Daemons like NFS or Torrent.

The commands below are ONLY for fun_plug Version 0.5
Please check here for newer tutorials!

Continue reading Installing and Uninstalling Packages and Activation and Deactivation of Daemons in Fonz fun_plug 0.5

Installation of nano on fun_plug 0.5 for CH3SNAS, CH3MNAS, DNS-323 and many more

This tutorial is deprecated and should only be used with fonz fun_plug 0.5!
Please check the tutorial page for updated tutorials on this topic!

After the installation of the fun_plug the only available editor is “vi”, which is not really considered a “newbie“-friendly editor. The nano editor is much easier to use and largely self-explanatory. If you nevertheless want more information on the GNU nano editor, see its home page.

Installation

In this tutorial we assume that the fun_plug is already installed on the NAS and that you synchronized Uli’s repository (see here for instructions on how to do this). Afterwards install the package (see detailed instructions here):

funpkg -i /ffp/pkg/additional/app-editors/nano*.tgz

Move the configuration-file nanorc from /ffp/etc/examples/ to /ffp/etc/ to get syntax highlighting.

mv /ffp/etc/examples/nanorc /ffp/etc/

Usage

Screenshot of nano running in a PuTTY window
Simply enter “nano ” on the commandline (replacing "" with the name of the file you want to edit).

Basic commands

The commands are shown at the bottom of the nano screen. The main commands are:

  • CTRL + G => Get Help
  • CTRL + O => WriteOut (“Save”)
  • CTRL + W => Where Is (Search for a string in the file)
  • CTRL + C => Cur Pos (Shows the line & column number of the current cursor-position)
  • CTRL + X => Exit (Self explanatory)
  • CTRL + T => Spell checking (if aspell is installed)

Syntax highlighting

To have syntax highlighting for a certain language you have to uncomment it in /ffp/etc/nanorc. Example for PHP:
Search:

## PHP
#include "/ffp/share/nano/php.nanorc"

And remove the comment like this:

## PHP
include "/ffp/share/nano/php.nanorc"

Fixing the NTP Time Synchronization with Fonz funPlug 0.5 for CH3SNAS, CH3MNAS, DNS-323 and many more

This tutorial is deprecated and should only be used with fonz fun_plug 0.5!
Please check the tutorial page for updated tutorials on this topic!

The CH3SNAS has two internal clocks:

  • a real-time hardware clock, which is similar to the chip in a wristwatch. It is powered by a battery inside the CH3SNAS and thus never stops.
  • a software clock, which runs only when the NAS is turned on.

Unfortunately, the software clock drifts from the hardware clock and after a few hours the drift get noticeable (e.g., 16s/hour = 4444 parts per million) and the NAS will show incorrect times for e.g. file modifications. But thanks to NTP (the Network Time Protocol) the clock can be synchronized to one of the atomic clocks on the Internet. The resulting absolute error will be only a fraction of a second (e.g. 10 ms; because of packet delays across the Internet) and the drift will essentially become zero.

Note that this tutorial requires an installed Fonz fun_plug!

Background Information

The time in the Linux Kernel is a standardized value. One day equals 10000 “ticks”, so one tick = 8.64 s. Most of the CH3SNAS drift about 16s/hour, wich equals a drift of 384 seconds or 44.444 ticks/day. This value has to be subtracted from the 10000 Ticks of the Kernel and has to be set as the new number of ticks per day. In our case this 10000-44.444 = ~ 9956 Ticks. As you can see, this value is only an estimation because the drift is an estimation. As it will take a lot of time to get the exact value for the ticks, you can simply estimate them and synchronize periodically with a timeserver to reduce the clock drift.

As you can see below, there are two choices for the synchronization. Regular synchronization via Cron should be chosen over using the NTP-Daemon as the latter seems to cause the following two lines in dmesg reappearing over and over again until the device gets restarted:

kernel: TWSI: mvTwsiStartBitSet ERROR - Start Clear bit TimeOut .
kernel: TWSI: mvTwsiStopBitSet ERROR - Stop bit TimeOut .

The Procedure

Time-Synchronization via Cron

Simply add the following lines to /ffp/etc/fun_plug.local, e.g. with nano:

# This removes firmware cronjobs that interfere with ntpd.
crontab -l | grep -vw '/usr/sbin/daylight' | grep -vw '/usr/sbin/rtc' | crontab -
#Now start the ntp every hour
echo "1 * * * * /usr/sbin/sntp -r -P no de.pool.ntp.org" >> /var/spool/cron/crontabs/root
# force a cronjob update
echo "root" >> /var/spool/cron/crontabs/cron.update

Reboot the device.

Sidemark: If the NTP-Service has been deactivated before the restart.

NTP-Daemon

As described above, this method seems to cause the TWSI-problems and is here only for historical reasons. Probably due to the concurrent access to this Two-Wire-Serial-Interface by the ntp-daemon and the fancontrol.

Activating the Service

Mark the service ntpd as excutable:

chmod +x /ffp/start/ntpd.sh

Configuration of the Service

Copy the Example-Configuration from /ffp/etc/examples to /ffp/etc/:

cp /ffp/etc/examples/fun_plug.local /ffp/etc/fun_plug.local
cp /ffp/etc/examples/ntp.conf /ffp/etc/ntp.conf

Edit the /ffp/etc/ntp.conf to change the time servers to servers which are geographically close. You can search for them here.
Quick possibility: Change them to general ones:

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

With this configuration both clocks get adjusted to the German timezone. If you want to change the timezone, you have to edit the /ffp/etc/fun_plug.local.
The string for Germany is (also change the timeserver, as this one is for Germany):

timezone="CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00"
timeserv=de.pool.ntp.org

Change it according to your Timezone. You can find possible ones in the appendix

Start the Service

You can now start the service manually or you can perform a reboot (it will be started during the bootup):

/ffp/start/ntpd.sh start

Finetuning

After a few hours you can find a file called /ffp/etc/npd.drift on you CH3SNAS. If the Value is +500 or -500, you have to adjust the number of ticks in the file /ffp/etc/fun_plug.local. fonz has set this to ”tick=9965”, which may be right for your device. If not, try reducing or incrementing this value to reduce the drift.

Appendix: Example Timezone Strings

Country City String
Australia Melbourne,Canberra,Sydney EST-10EDT-11,M10.5.0/02:00:00,M3.5.0/03:00:00
Australia Perth WST-8
Australia Brisbane EST-10
Australia Adelaide CST-9:30CDT-10:30,M10.5.0/02:00:00,M3.5.0/03:00:00
Australia Darwin CST-9:30
Australia Hobart EST-10EDT-11,M10.1.0/02:00:00,M3.5.0/03:00:00
Europe Amsterdam,Netherlands CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Athens,Greece EET-2EEST-3,M3.5.0/03:00:00,M10.5.0/04:00:00
Europe Barcelona,Spain CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Berlin,Germany CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Brussels,Belgium CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Budapest,Hungary CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Copenhagen,Denmark CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Dublin,Ireland GMT+0IST-1,M3.5.0/01:00:00,M10.5.0/02:00:00
Europe Geneva,Switzerland CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Helsinki,Finland EET-2EEST-3,M3.5.0/03:00:00,M10.5.0/04:00:00
Europe Kyiv,Ukraine EET-2EEST,M3.5.0/3,M10.5.0/4
Europe Lisbon,Portugal WET-0WEST-1,M3.5.0/01:00:00,M10.5.0/02:00:00
Europe London,GreatBritain GMT+0BST-1,M3.5.0/01:00:00,M10.5.0/02:00:00
Europe Madrid,Spain CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Oslo,Norway CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Paris,France CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Prague,CzechRepublic CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Roma,Italy CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
Europe Moscow,Russia MSK-3MSD,M3.5.0/2,M10.5.0/3
Europe St.Petersburg,Russia MST-3MDT,M3.5.0/2,M10.5.0/3
Europe Stockholm,Sweden CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
New Zealand Auckland, Wellington NZST-12NZDT-13,M10.1.0/02:00:00,M3.3.0/03:00:00
USA & Canada Hawaii Time HAW10
USA & Canada Alaska Time AKST9AKDT
USA & Canada Pacific Time PST8PDT
USA & Canada Mountain Time MST7MDT
USA & Canada Mountain Time (Arizona, no DST) MST7
USA & Canada Central Time CST6CDT
USA & Canada Eastern Time EST5EDT
Atlantic Atlantic Time AST4ADT
Asia Jakarta WIB-7
Asia Jerusalem GMT+2
Asia Singapore SGT-8
Asia Ulaanbaatar, Mongolia ULAT-8ULAST,M3.5.0/2,M9.5.0/2
Central and South America Brazil,Sao Paulo BRST+3BRDT+2,M10.3.0,M2.3.0
Central and South America Argentina UTC+3
Central and South America Central America CST+6
Exit mobile version