About Author

Hyon-Young Choi
blog: http://commani.net
twitter: @
github:

Engineering mind always..

  • Research Professor at Korea University
  • Internet, Mobile Network, Handover, QoS, ns-3, C++, Qt

About this Article

Date Released:
Wednesday, November 13 2013 8:33 AM

Customized service configuration with Optware.

1. Install Optware

On QTS, App Center -> Developer Tools -> Optware IPKG

Click Add to QTS

Optware

Once installed, you can install packages supported by Optware using ipkg command or web-ui. I prefer the command line tool.

1.1 Package list update

Connect using ssh:

# ssh admin@<your nas' IP>

run ipkg update command:

# ipkg update

1.2 Modify Optware initial script

You have to modify the initial script because the PATH is not set properly.

Find the file Optware.sh in /opt directory:

# cd /opt
# ls -l Optware.sh

If you could not find Optware.sh in /opt, you have to try the absolute path.

# cd /share/HDA_DATA/.qpkg/Optware

Note: HDA_DATA can be changed upon your installed hard disk settings like MD0_DATA, HDB_DATA, HDC_DATA, and so on.

Modify script using vi

# vi Optware.sh

You can find PATH environment variable setting to /etc/profile as bellow:

# adding Ipkg apps into system path ...
/bin/cat /etc/profile | /bin/grep "PATH" | /bin/grep "/opt/bin" 1>>/dev/null 2>>/dev/null
[ $? -ne 0 ] && /bin/echo "export PATH=\$PATH":/opt/sbin:/opt/bin >> /etc/profile

Change the order of path by putting Optware's path in front of existing path like this:

[ $? -ne 0 ] && /bin/echo "export PATH=/opt/sbin:/opt/bin:\$PATH" >> /etc/profile

2. Setup Qpkg-based service

The packages installed by ipkg include services such as ssh, apache, etc. However, these services do not start automatically at boot time. So, we need something to launch these services at boot. The site introduces the method using QPkg configuration.

At first, add new qpkg configuration by editing qpkg.conf:

# vi /etc/config/qpkg.conf

Append new QPkg setting on the end of qpkg.conf

[MySettings]
Name = MySettings
Version = 0.1
Author = neongas
Date = 2013-11-13
Shell = /share/HDA_DATA/.qpkg/MySettings/MySettings.sh
Install_Path = /share/HDA_DATA/.qpkg/MySettings
QPKG_File = MySettings.qpkg
Enable = TRUE

Note: HDADATA can be replaced to MD0DATA, HDB_DATA, etc.

Create a directory inside .qpkg directory:

# cd /share/HDA_DATA/.qpkg
# mkdir MySettings

Make initial script file:

# cd MySettings
# vi MySettings.sh

The content is as followed:

#!/bin/bash

PATH=/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

case "$1" in
  start)
    echo "Start MySettings.."

    ;;

  stop)
    echo "Stop MySettings.."

    ;;

  restart)
    $0 stop
    $0 start
    ;;

  *)
    echo "Usage: $0 {start|stop|restart}"
esac

Give execute permission to the file:

# chmod +x MySettings.sh

Now, you can add any command by putting between start) and ;; like this:

  start)
    echo "Start MySettings.."

    rm -f /root/.profile /root/.bashrc
    ;;

3. Customize the services depending on your own preference

In NAS, there are many services provided by default such as ssh, telnet, apache, mysql. You may want to turn off some services or replace the built-in service to improved another service from Optware ipkg or source code.

Some services can be turned off using QTS system, but some cannot. Most of system services cannot be replaced just by modifying some files, e.g., removing a file in /etc/rcS.d/S* in order not to start the service, because system files are refreshed from firmware on boot.

The newly added MySettings.sh is a solution for this. We can put any actions on boot for turning a service off or modifying or removing some files.

3.1 How to turn off built-in services

Most of important system services are monitored by daemon_mgr. Just killing the process like killall apache_proxy is not enough.

The graceful method is using the scripts in /etc/init.d. For example, to turn off Web service, run,

# /etc/init.d/Qthttpd.sh stop

It is slow. Inside the script, daemon_mgr is used to start/stop the service. Hence, we can run daemon_mgr directly, like this:

daemon_mgr Qthttpd stop Qthttpd

It is faster than the script in /etc/init.d. The first "Qthttpd" is service name. The second argument is command "start" or "stop". The third parameter is the path of the service. In case of stopping, it can be dummy parameter I guess.

OK. Let's put the command into MySettings.sh:

case "$1" in
  start)
    echo "Start MySettings.."

    # turn off Web service
    daemon_mgr Qthttpd stop Qthttpd
    ;;

All clue is provided.

3.2 Turning off basic Web server

You can turn the web service off in QTS. However, there might be a bug in firmware 4.0.2. Web service is never turning off. Just putting following command into MySettings.sh is enough:

daemon_mgr Qthttpd stop Qthttpd

3.3 Enabling user login by replacing sshd

I perfer to use SFTP for my user account. Default sshd only permits admin login.

using ipkg command, install openssh and openssh-sftp:

# ipkg install openssh openssh-sftp-server

You can check the installed files using ipkg files command:

# ipkg files openssh
Package openssh (5.9p1-1) is installed on root and has the following files:
/opt/etc/init.d/S40sshd
/opt/etc/default/openssh
/opt/etc/openssh/sshd_config
/opt/bin/openssh-ssh
/opt/etc/openssh/ssh_config
/opt/bin/ssh-keyscan
/opt/bin/ssh-agent
/opt/bin/openssh-scp
/opt/bin/slogin
/opt/libexec/ssh-pkcs11-helper
/opt/etc/openssh/moduli
/opt/bin/ssh-add
/opt/bin/ssh-keygen
/opt/sbin/sshd
/opt/bin/sftp
/opt/libexec/ssh-keysign

Successfully terminated.
#

The configuration file sshd_config is placed on /opt/etc/openssh/ and the binary sshd is on /opt/sbin/. To provide consistency of sshd when it restarts by daemonmgr automatically after recovery from accidental failure, we copy the executable and configuration files to default sshd locations. we start daemonmgr with the exact same parameter of daemon_mgr.conf as well.

Put these commands into MySettings.sh:

#stop default sshd
daemon_mgr sshd stop sshd

# copy daemon and configuration
mv /usr/sbin/sshd /usr/sbin/sshd_orig
cp /opt/sbin/sshd /usr/sbin/sshd
cp /opt/etc/openssh/* /etc/ssh/

# run daemon as the same with daemon_mgr.conf
daemon_mgr sshd start "/usr/sbin/sshd -f /etc/ssh/sshd_config -p 22"

3.4 Turning off QTS

Be Careful Do not apply 3.3 and 3.4 simultaneously. If something is wrong for both QTS web and ssh, there is no way to fix it except reset configuration or factory default setting. I recommend to try 3.3 first, then 3.4 as sure of working ssh.

The built-in QTS Web-interface for configuration has many bugs, especially FileManager which is taking 100% CPU usage. I decided not to use any services provided by QTS (FileManger, Photo/Music/Media stations, etc).

You may need to use QTS for changing some system setting. However, QTS web does not need to be alway on. You can turn it on by simple command via ssh when you need something to be configured using QTS, then turn it off again after finish.

For this, just add following commands to MySettings.sh:

daemon_mgr _thttpd_ stop _thttpd_
daemon_mgr apache_proxy stop apache_proxy
daemon_mgr apache_proxys stop apache_proxys

blog comments powered by Disqus