You are here

QNAP NAS

Enable running things at boot time

# mount -t ext2 /dev/sdx6 /tmp/config
# vi /tmp/config/autorun.sh
# mount -t ext2 /dev/sdx6 /tmp/config
# vi /tmp/config/autorun.sh
# mount -t ext2 /dev/sdx6 /tmp/config # vi /tmp/config/autorun.sh # mount -t ext2 /dev/sdx6 /tmp/config # vi /tmp/config/autorun.sh
Make /tmp/config/autorun.sh look like this #!/bin/sh /share/MD0_DATA/.qpkg/autorun/autorun.sh
# chmod +x /tmp/config/autorun.sh # umount /tmp/config # vi /share/MD0_DATA/.qpkg/autorun/autorun.sh
My /share/MD0_DATA/.qpkg/autorun/autorun.sh looks a bit like this

#!/bin/sh # autorun.sh - start stuff automatically on boot ## Less is more /bin/echo "export PAGER='/opt/bin/less -r '" >> /root/.profile ## Crontab /share/MD0_DATA/chrisp/bin/chrispcrontab onboot ## DNSmasq /share/MD0_DATA/chrisp/bin/dnsmasqctl start

# chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
chrispcrontab.sh #!/bin/sh # /share/MD0_DATA/chrisp/bin/chrispcrontab.sh # Modify the crontab, which will survive a QNAP reboot originalfile=/share/MD0_DATA/chrisp/etc/crontab_original.cron customfile=/share/MD0_DATA/chrisp/etc/crontab_custom.cron myfile=/share/MD0_DATA/chrisp/etc/crontab_chrisp.cron # restart crontab - probably not required for 'crontab' alterations #/etc/init.d/crond.sh restart case "${1-}" in onboot) ## Save original crontab /usr/bin/crontab -l >$originalfile ## Generate custom crontab /bin/cat $myfile >$customfile ## Append original content to custom crontab /bin/cat $originalfile >>$customfile ## Load crontab from file crontab $customfile ;; regen) ## Regenerate custom crontab /bin/vi $myfile /bin/cat $myfile >$customfile ## Append original content to custom crontab /bin/cat $originalfile >>$customfile /bin/echo '' >>$customfile ## Load crontab from file crontab $customfile ;; restore) ## Load crontab from original file crontab $originalfile ;; *) /bin/echo "" /bin/echo "Usage: $0 {onboot|regen|restore}" /bin/echo "" /bin/echo "'onboot' should only ever be run at boot - backs up the original & generates a custom crontab" /bin/echo '' /bin/echo "'regen' generates a custom crontab from $myfile and $originalfile" /bin/echo '' /bin/echo "'restore' will restore the crontab from $originalfile" /bin/echo '' ;; esac
This makes my crontab look a lot like this # crontab for root #SHELL=/bin/sh #PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin #MAILTO= #HOME=/ # .---------------- minute (0-59) # | .-------------- hour (0-23) # | | .------------ day of month (1 - 31) # | | | .---------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .-------- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * /full/path/and/command_to_be_executed ## Rotate the dnsmasq logs 00 00 * * * /share/MD0_DATA/chrisp/bin/dnsmasqctl rotate ## Original/default/system crontab entries 0 4 * * * /sbin/hwclock -s 0 3 * * * /sbin/vs_refresh 30 4 * * * /etc/init.d/Qthttpd.sh restart 1>>/dev/null 2>>/dev/null 0 3 * * * /bin/rm -rf /mnt/HDA_ROOT/twonkymedia/twonkymedia.db/cache/* 30 7 * * 1 /sbin/qsmart -t short -d 1 0 5 1 * * /sbin/qsmart -t extend -d 1 30 7 * * 1 /sbin/qsmart -t short -d 2 0 5 1 * * /sbin/qsmart -t extend -d 2 30 7 * * 1 /sbin/qsmart -t short -d 3 0 5 1 * * /sbin/qsmart -t extend -d 3 30 7 * * 1 /sbin/qsmart -t short -d 4 0 5 1 * * /sbin/qsmart -t extend -d 4 */60 * * * * /usr/bin/logChecker 0-59/15 * * * * /usr/bin/qcmd DUSG 5 * * * * /usr/bin/qcmd rec_report 0 3 * * * /etc/init.d/ImRd.sh bgThGen

dnsmasq

# ipkg install dnsmasq

dnsmasqctl

This came form Don @ QNAP NAS Community Forum but with some alteration to suit me.

dnsmasqctl #!/bin/sh # Script to: # stop/start/restart dnsmasq # refresh - certain files # rotate - dnsmasq log file # dump - dump statistics into the log file set -u declare -r SIGHUP=1 # Hangup (POSIX) declare -r SIGUSR1=10 # User defined signal 1 (POSIX) declare -r SIGUSR2=12 # User defined signal 2 (POSIX) configfile="/share/MD0_DATA/chrisp/etc/dnsmasq.conf" # configuration file pid=`/bin/pidof dnsmasq` # process id daystokeep=6 case "${1-}" in start) if [ "$pid" != "" ]; then /bin/echo "dnsmasq is already running" else /bin/echo "starting dnsmasq" /sbin/daemon_mgr dnsmasq start "/opt/sbin/dnsmasq --conf-file='$configfile' 2> /dev/nul 1> /dev/nul" fi ;; stop) if [ "$pid" = "" ]; then /bin/echo "dnsmasq is not running" else /bin/echo "stopping dnsmasq" $0 dump /sbin/daemon_mgr dnsmasq stop "/opt/sbin/dnsmasq --conf-file='$configfile' 2> /dev/nul 1> /dev/nul" fi ;; restart) $0 stop /bin/sleep 2 $0 start ;; refresh) if [ "$pid" != "" ]; then /bin/kill -$SIGHUP $pid /bin/echo "dnsmasq has been refreshed" else /bin/echo "dnsmasq is not running" fi ;; rotate) if [ "$pid" != "" ]; then logfile=`/sbin/getcfg "" "log-facility" -f "$configfile"` "$0" dump fn=`/usr/bin/basename $logfile` dn=`/usr/bin/dirname $logfile` mydate=`date '+%Y%m%d_%H%M%S'` mv "$logfile" "$logfile.$mydate" /bin/kill -$SIGUSR2 $pid /bin/echo "dnsmasq logs have been rotated" else /bin/echo "dnsmasq is not running" fi /usr/bin/find "$dn" -mtime +$daystokeep -name 'dnsmasq*' | while read filename do [ -f "$filename" ] && rm "$filename" done ;; dump) if [ "$pid" != "" ]; then /bin/kill -$SIGUSR1 $pid /bin/echo "dnsmasq has dumped statistics into the log file" else /bin/echo "dnsmasq is not running" fi ;; *) /bin/echo "" /bin/echo "Usage: $0 {start|stop|restart|refresh|rotate|dump}" /bin/echo "" ;; esac