2011/11/13(Sun)QNAP TS-219P+を設定完了 (6) サーバ起動時にやること

はてブ数 2011/11/13 12:45 計算機な日記::ボクと計算機 つーさ

サーバ起動時になんか処理させたい。

適当に startup.sh とかをどっかに作る。

#!/opt/bin/bash

# ldconfig
/opt/bin/sed -i '1i /opt/lib' /etc/ld.so.conf
/sbin/ldconfig

# ipkgで入れたopensshのsshdを起動する。
/etc/init.d/login.sh stop
/opt/bin/sed -i 's!SSH=/usr/sbin/sshd!SSH=/opt/sbin/sshd!' /etc/init.d/login.sh
/opt/bin/sed -i 's/AllowUsers .*$/AllowUsers */' /etc/ssh/sshd_config
/etc/init.d/login.sh start

# 自分でインストールした apache2 を起動する。
/bin/rm -f /php.ini
/etc/init.d/Qthttpd.sh stop
/opt/local/apache2/bin/apachectl -k start

#memcached
/opt/bin/memcached -d -u httpdusr

# crontab
# ファイルはramdrive上に作った方がいいのだろうな。
/usr/bin/crontab -l > /tmp/crontab.tmp
/bin/echo "*/5 * * * * /share/admin/ddns/update_ddns.sh" >> /tmp/crontab.tmp
/bin/echo "0 */3 * * * /share/admin/mysql_backup/backup.sh" >> /tmp/crontab.tmp
/usr/bin/crontab /tmp/crontab.tmp

2013.10.06 追記。

↓オブソ。firmware 3.8.2以降では動作しない。方法が変わった。
フラッシュメモリにautorun.shを書いておくと、起動完了時に実行してくれる。
autorun.sh から、さっき作った startup.sh を呼ぶようにする。
http://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup

mount -t ext2 /dev/mtdblock5 /tmp/config
echo "#!/bin/bash" >> /tmp/config/autorun.sh
echo "/share/admin/startup.sh" >> /tmp/config/autorun.sh
umount /tmp/config

↑オブソ。新しい方法↓

qpkg.confを書き換えて、
ダミーのqpkgがインストールされてるように見せかけることで、
起動時にスクリプトを実行してもらう。

/etc/config/qpkg.conf

に追記。

[autorun]
Name = autorun_dummy
Version = 0.1
Author = watashi-chan
Date = 2013-10-06
Shell = /share/home/tu-sa/conf/startup.sh
Install_Path = /share/home/tu-sa/conf
QPKG_File = autorun_dummy.qpkg
Enable = TRUE

Shell のとこに書いたのが実行される。他はおおむねどうでもよい。


QNAPediahttp://wiki.qnap.com/wiki/Main_Page と、フォーラムhttp://forum.qnap.com/ は便利。
フォーラムの方はログインすると検索機能が使えるようになるので、是非ユーザ登録すべし。