refactoring deploy/restart scripts to be cleaner and more flexible