2013-05-18

QNAP Subversion newest Firmware (3.8.3 Build 20130426) fixed Autorun.sh problem


Step 1:
find /share -name "Optware.sh"

vi /etc/config/qpkg.conf

press a to edit

Add the following lines to the end of /etc/config/qpkg.conf:
[Optware_Autorun]
Name = Optware_Autorun
Version = 1.0
Enable = TRUE
Shell = /share/MD0_DATA/.qpkg/Optware/autorun.sh
Install_Path = /share/MD0_DATA/.qpkg/Optware
Author = Geoff Clements
Date = 2012-06-18

Press esc key
And key in :wq then enter
chmod +x /etc/config/qpkg.conf

Step 2:

vi /opt/autorun.sh

press a to edit

paste the code follow:
#!/bin/bash

shopt -u nullglob

# Change these to adjust the timeout
# timeout(secs) = (maxtries - count) * delay
count=0
declare -r delay=5 maxtries=12

# Default action is "start" as this file is called with
# no parameters on NAS startup but you can, for
# example, do a "./autorun.sh stop" to stop all Optware
# services
action=${1:-start}

LOG=/sbin/log_tool

${LOG} -t 0 -a "Starting Optware_Autorun."

# Wait for /opt to come online
# use ipkg as a test
while [ ! -f /opt/bin/ipkg ]
do
  if ((count++ >= maxtries))
  then
    ${LOG} -t 1 -a "Optware_Autorun time out."
    exit 1
  fi
  sleep ${delay}
done

# Run all executables beginning with S in /opt/init.d/Optware/
for f in /opt/etc/init.d/Optware/S*
do
  [ -x ${f} ] && ${f} ${action}
done

exit 0

Press esc key
And key in :wq then enter
chmod +x /opt/autorun.sh


Step 3:
mkdir /opt/etc/init.d/Optware/
chmod +x /opt/etc/init.d/Optware/
vi /opt/etc/init.d/Optware/S10svnserve

paste the code follow:
#!/bin/bash

# Full path to executable
runfile=/opt/bin/svnserve

# Parameters to pass to runfile
params="-d --listen-port=3690"

# Need exactly one parameter
((${#} == 1)) || exit 1

# Must have a runfile
[ -z "${runfile}" ] && exit 1

service=$(basename "${runfile}")

LOG=/sbin/log_tool
DMGR=/sbin/daemon_mgr

waitfor () {
  # $1 = service
  # $2 = maximum time to wait (secs) - default 30

  local pid=$(pidof ${1})
  local count=${2:-30}
  while [ -n "${pid}" ]
  do
    sleep 1
    if ((--count <= 0))
    then
      return 1
    fi
    pid=$(pidof ${1})
  done

  return 0
}

start () {
  ${LOG} -t 0 -a "Starting ${service}."
  pid=$(pidof ${service})
  if [ -z "${pid}" ]
  then
    ${DMGR} ${service} start "${runfile} ${params}"
    pid=$(pidof ${service})
    if [ -n "${pid}" ]
    then
      ${LOG} -t 0 -a "${service} started."
    else
      ${LOG} -t 2 -a "${service} failed to start."
    fi
  else
    ${LOG} -t 1 -a "${service} already running."
  fi
}

stop () {
  ${LOG} -t 0 -a "Stopping ${service}."
  pid=$(pidof ${service})
  if [ -n "${pid}" ]
  then
    ${DMGR} ${service} stop "${runfile}"
    if waitfor ${service}
    then
      ${LOG} -t 0 -a "${service} stopped."
    else
      ${LOG} -t 2 -a "Cannot stop ${service}."
    fi
  else
    ${LOG} -t 1 -a "${service} already stopped."
  fi
}

case "${1}" in
  start)
    start
    ;;
  
  stop)
    stop
    ;;
  
  restart)
    stop
    start
    ;;
  
  reload)
    pid=$(pidof ${service})
    [ -n "${pid}" ] && kill -s SIGHUP ${pid}
    ;;
esac

exit 0

Press esc key
And key in :wq then enter

chmod +x /opt/etc/init.d/Optware/S10svnserve
/opt/autorun.sh start

0 comments: