You can tear down and start up the network interface using:
sudo ifconfig en0 down
sudo ifconfig en0 up
Lack of network access after disconnecting from a VPN can be a symptom of a routing issue. If your VPN client doesn't disconnect cleanly, the gateway that directs your traffic to the virtual network can sometimes be left in place, effectively routing your traffic to a dead end.
I'd suggest bringing your interfaces down, flushing the routing table of gateway entries, and bringing them up again:
Bring your network interfaces down:
for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://'); do sudo ifconfig "$i" down; done
Flush the routing table: .sudo route -n flush
Bring your interfaces back up again: (repeat step 1 with instead of up).down
If you want a reusable Bash function for this that you can drop into your .bashrc (or wherever), you could save the following:
resetroute () {
echo "Flushing routes...";
for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://');
do
sudo ifconfig "$i" down;
done;
sudo route -n flush;
for i in $(ifconfig | egrep -o "^[a-z].+\d{1}:" | sed 's/://');
do
sudo ifconfig "$i" up;
done
}
Just type in the command:
exec bash -l
I guess that should do it.
For ,zsh
exec zsh -l
This is needed because every shell on by default is a login shell.macOS
Justing writing would replace the current shell with a non-login shell which is not the same effect as closing and re-opening the terminal.exec bash
would make new exec process replace the current shell. If bash -l is not used, exec would spawn a new shell over the current shell incrementing the bash -l.$SHLVL
Once you've logged in via ssh then you need to use with the shutdown flag (for restart):-r
$ ssh username@ip-address
$ sudo /sbin/shutdown -r now
Or, to do it all in one command:
$ ssh username@ip-address sudo /sbin/shutdown -r now
It is strange to see the questions between "windows migrated" and "default mac" users. :) Windows migrated users usually want "somewhat tweak" the system. Default Mac users - simply "using it".
I'm using MAC much years, and never needed to use the launchctl command. If mean never, mean in normal usage, of course sometimes needed use it when installing somethings from the macports - for onetime load of startup files or so.
I'm wondering, why you need start/stop/restart services with launchctl? Asking because if you not an experienced OS X users you probably will screw the system "harmony" :). So, in this case - IMHO - better to ask the specific problem, so ask how to start/stop the specific service.
As the answer - check first System preferences. Most common services are in the "Sharing" pane" - like web-server, sshd, CD sharing and so on...
Some third party dmg files with GNU stuff comes with own preference pane too. For example, you can install precompiled MYSQL server with a preference pane, what allow you start-restart the server.
If you don't find the wanted service in prefs, be more precise. What service you need start/stop? The "launchctl" command works as needed to work, ActivityMonitor too. You ofc can use "ps axuwww" or "top" commands from the Terminal too.
Remember, your now in the UNIX world, so nearly anything can be done from the command-line, but usually thats mean really much learning.. ;)
EDIT:
try:
sudo kill -1 204
^-process number
from the terminal, or simply kill the daemon from the ActivityMonitor. The watchdog should restart it.
Have you any lighthttpd file in the /Library/LaunchDaemons/*? So, any output form the command:
ls /Library/LaunchDaemons | grep -i light
if yes, you can use the:
sudo launchctl unload /Library/LaunchDaemons/filename.plist
sudo launchctl load /Library/LaunchDaemons/filename.plist
command for stop/start.
You can do that using the following command:
sudo nvram "recovery-boot-mode=unused"
sudo reboot
This sets a firmware variable in nvram indicating that you want to start in Recovery mode on the next boot, and then reboots the machine.
When done in Recovery mode, run the following from the Terminal in Recovery mode:
nvram -d recovery-boot-mode
This deletes the firmware variable so that the next boot is a normal boot.
If Recovery boot fails and you cannot progress, you could also remove the firmware variable by holding down the keys Command, Option, P, and R during boot. This resets the nvram and thus the firmware variable.
The command you are after is shutdown. This informs all users that the machine is going to be shutdown and tells all apps to close files etc.
The command takes a parameter , -h or -r to shut down, restart or sleep the Mac.-s
The command has to be run as root so you need to use .sudo
e.g. to reboot the machine immediately
sudo shutdown -r now
e.g. to shutdown the machine in 60 minutes
sudo shutdown -h +60
From comments there are two things to be addressed
How shutdown works is by sending a sigterm to all processes which should then deal with that e.g. save open files etc. If they don't exit then they will get sent a SIGKILL which forces them to die with no chance to respond. The signals are not sent via the normal key message queue so Apps have to deal with this separately to the code that gets called from quit on the menu. A good app should call common code from both.
This other answer shows how to shutdown as if you hit the menu options. But note that apps can cancel this shutdown