the vagrant ssh command accepts an option (-c or --command) which allows you to pass in a single command to the virtual machine.

vagrant ssh --command 'sudo service apache restart'