add init.d script and fix exception handling bug