I'm looking for a command to stop all services running and probably restart them after. Any help would be appreciated.
2 Answers
assuming you are using ubuntu 16.04 you can use systemctl to control services.
to get a list of services and their status
systemctl | grep service
to control an individual service , replace service with the service name
systemctl status service
systemctl stop service
systemctl start service
in older version of ubuntu services can be controlled via init scripts which live in /etc/init.d , these work in a similar way
to get a list of services
ls -l /etc/init.d/
to contrl and individual service
/etc/init.d/service status
/etc/init.d/service stop
/etc/init.d/service start

- 5,246
Although I highly recommend rebooting the machine instead, you can write a command to achieve this:
Note: This may force a machine reboot halfway through at which point this effort is profitless.
for s in `systemctl | grep service | cut -d '.' -f 1`; do sudo systemctl restart $s; done
I would instead list all currently running services, identify the ones I want to stop, then manually restart each service:
Note: restart internally calls start + stop so you won't have to perform them separately.
List currently running services:
systemctl | grep running
Restart each service by typing:
systemctl restart <service>