Friday, October 30, 2009

OpenVPN keepalive option cannot work with DDNS after remote peer ip is changed.

In my notebook, which is running Gentoo 2008 with openvpn,
Keepalive(ping,ping-restart)+redirect-gateway in openvpn client config file causes routing problem after remote peer ip is changed, though man page said that ping-restart will reestablish the tunnel as the ping failed . The vpn tunnel just stop tunneling when remote server's ip is changed, and stracing it reveals that openvpn keeps trying to connect to the newly updated ip, and cannot return.

After investigting the routing table, I found that the ip route show shows something like the following:

old remote-ip via original gateway
default via tun0

Therefore, the route to the newly upgraded remote-ip cannot be found since it has no gateway information in the routing table (which is kept by openvpn session before remote peer's ip was changed), and will use the default via tun0. However, tun0 has been downed and cannot forward traffic anymore.

The solution to this issue is to add the following command to configuration file

remap-usr1 SIGHUP

which indicates openvpn to treat the SIGUSR1 as SIGHUP, and therefore, it will force openvpn to "completely" restart/reload the tunnel/routing table.


Wednesday, August 26, 2009

git+svn一起用

用過svk/bzr/mercurial/git-svn等等可以存取svn server的dvcs tools,
每次不是checkout時會出問題就commit時秀出一堆看不懂的訊息, 然後不知道怎麼resolve

svk在碰到partial respoitory access時會爛掉, bzr好像改好了, 不過龜到爆,
mercurial的svn patch要假設svn是branches/trunk/tag的deployment, 完全不實用
git-svn看起來是最穩定的, 不過還是偶爾會當掉, 而且開個branch後不能dcommit回去了, git-svn的manaul
有警告user.

重點是整個repository clone回來後, PL發個issue, 給我個copy branch, 我就得再重新整個
再clone回來, 每次clone都得花上一個上午, 所以用dvcs的計劃宣告失敗

最近靈機一動, 想出用svn+git的方式, 用起來果然很方便

可以達成我用dvcs的夢想.

方法是:
先svn co 回來, 先不要build.
然後再root裡放一個.gitignore

cd $WORKING_COPY
echo .svn > .gitignore
git init .
git add .
git commit -m "[XXX]Init of my mirrored project."
然後就可以享用git帶來的好處, 而不用去管白痴svn了, 回家也可以commit code, 超方便, 也可以自己開branch亂寫一堆會crash的功能.

等到PL來追殺時, 再git checkout master && svn comit -m "[XXX] yyyyyyy"就好了

科科科科.

反正還是不要妄想有人會寫一個很好用的dvcs tools讓你可以用它來Access 老古董 svn server...
自己搞創意比較快...

Sunday, January 18, 2009

Hibernation with lvm-based root

最近常常把工作帶回宿舍, 每次回到宿舍總要重新setup一次環境, 非常麻煩.
於是我想起了之前曾經用過的Linux的休眠方法,
但聽說initrd+休眠會非常的危險, 所以我拿另一台也是Linux
但只是拿來測試iperf或Chariot用的Notebook來試, 目前看來沒問題, 至少filesystem沒有跟我說要check fs,
所以寫了這篇記錄一下, 不保証會Work.

Hibernation is not that simple with just doing echo disk into /sys/power/state if you use lvm on root.

Using lvm on root requires initrd.
In accordance with the swsusp documentation, it's very dangerous to use initrd with hibernation.
The most important thing is, don't mount any filesystem that is under hibernation.

Someone may abandon doing extra work just for using lvm as root.
However, using lvm as root has many advantages.
For example, backing up the root fs without shutdowning the system using lvm snapshot capability.
Enrypting your partition using AES to protect your private data, or even create raid-device under the lvm device
for the sake of performance/stability.

This note describes how I achieved hibernation on a lvm-root.

I won't guarantee that these should work, and it might cause data loss.
But it works for me, and there is no data loss so far.
At least the kernel filesystem module won't complain at mouting.

The following script is the init script of my initrd and it resumes from /dev/hda2.

#!/bin/nash
echo "Loading dm-mod.ko module"
insmod /lib/dm-mod.ko
echo Mounting /proc filesystem
mount -t proc /proc /proc
mount -t sysfs /sys /sys
echo Creating block devices
mkdevices /dev
echo Creating root device
echo 0xFE00 > /proc/sys/kernel/real-root-dev
mkrootdev /dev/root
lvm vgscan --ignorelockingfailure
lvm vgchange -ay --ignorelockingfailure
lvm lvscan --ignorelockingfailure
lvm lvchange -ay --ignorelockingfailure /dev/backup_vg/backup_lv
echo 3:2 > /sys/power/resume
echo Mounting root filesystem
mount -o noatime --ro -t ext3 /dev/root /sysroot
pivot_root /sysroot /sysroot/initrd
umount /initrd/proc
# Please refert to initrd.txt in kernel documentation.
# This is the different instruction from the origianl documentation in the preliminary section.
exec /sbin/init 3

Note that the 3:2 means the major number and minor number of the /dev/hda2.
It might be different in your environment.
You could use the following instruction to figure out your own number pair.

ls -l `fdisk -l 2> /dev/null | grep "Linux swap" | awk '{print $1}'` | awk '{print $5 $6}'

For instance, in my environment , it will output the following number pair:

3,2

Sunday, December 28, 2008

MFC寫的網路俄羅斯方塊

最近清理硬碟時,
發現以前修丁老大MFC的課時寫的作業網路俄羅斯方塊,
因為早就幾百年不用Windows了,

用Wine試試看
什麼都不用改就可以動了,
但是中文不見了, 可能是Wine沒有中文字形的關係
自己玩得不亦樂乎...

雖然Linux裡面就內建俄羅斯方塊了, 作得也比我的好太多, 但是玩自己寫的
就是比較有趣味啊...而且還有雙方互相陷害的功能(就是自己堆起來超過3層的會跑到對手那邊去)

From Public




下載位置

兩個人擠在電腦前也可以玩,
用網路的話
如果TCP RTT很短的話還可以玩
但是如果TCP RTT 時間太長的話,
可能會照成兩個人都怪怪的情況
懶得修了, 反正只是個作業

當年寫完這個作業後本來想繼續寫Server版的,
但是Compiler課太操了...
寫完期末作業後就開始準備研究所考試了
所以就沒再寫下去了

現在年紀大了
反而對寫程式一點熱情都沒有, 尤其是寫不會賺錢自己寫爽的程式

年輕果然是本錢啊, 尤其是閒閒大學生...

這個程式的前身是Java俄羅斯方塊, 也是Java程式期末作業,
我還load到老師的電腦裡面Demo, 在老師面前玩俄羅斯, 開了四個視窗
玩了好久還沒辦法把垃圾丟到另外一邊, 越玩越緊張, 老師最後就給我分數叫我不要再玩下去了, Orz...

From Public


不知道為什麼, 每次老師出沒有主題的期末作業, 我就只想到俄羅斯方塊....

Wednesday, November 12, 2008

這真是一隻不屈服於主人淫威之下的好狗啊~

還會用台語三字經罵主人~