Refactor init script and add support for debian

These changes are currently tested only on debian. Fixes for redhat will
surely come.