Tested on Ubuntu 16.04 Docker container. The Dockerfile is a single line FROM ubuntu:16.04.
NOTE: stopping services didn't work for me for some reason. That's why there is pidof <service name> | xargs kill after each failed service <service name> stop to kill it.