Added some checks and fixes to the agent's init script for ubuntu/debian and centos/red-hat.