[HOWTO] Simulate a restart for testing purposes

gatorparrots

~departed~
Your uptime can be as long as your machine has physical power (providing you have no errant kernel extensions or something else that causes a kernel panic). Simply learn the power of SystemStarter

You can leave the kernel and core operating system running and just restart the various StartupItems material [the scripts in /System/Library/StartupItems and /Library/StartupItems] without actually restarting the Darwin OS itself.

This from the man page:
Code:
DESCRIPTION
     The SystemStarter utility may be used to start, stop, and restart the
     system services which are described in the /Library/StartupItems/ and
     /System/Library/StartupItems/ paths.

     The optional action argument specifies which action SystemStarter per-
     forms on the startup items.  The optional service argument specifies
     which startup items to perform the action on.  If no service is speci-
     fied, all startup items will be acted on; otherwise, only the item pro-
     viding the service, any items it requires, or any items that depend on it
     will be acted on.

     During boot SystemStarter is invoked by rc (see rc(8)) and is responsible
     for starting all startup items in an order that satisfies each item's
     requirements.

For example, to restart a specific daemon such as NetInfo:
sudo SystemStarter restart NetInfo

Or issue a blanket command that restarts all of the core services*:
sudo SystemStarter restart
In many cases, this will be as effective as a reboot (since this is what rc invokes anyway).

*One caveat is that all the start, stop, and restart options do is pass the prescribed argument to the various startup scripts. If the syntax issued is incorrect for that daemon, nothing happens. An example is AppServices, which controls coreservicesd. Sending stop or restart to this script has no effect.
 
That's a really great command. Very very useful. :) Thanks for sharing that!

Now, why can't installers just do this command? :p
 
To perform an actual full restart of a machine, just SSH in and issue this command:
sudo shutdown -r now

The point of this thread, however, is to point out that in many situations, a full restart is unnecessary. In most cases, you won't need to bring the whole machine down and back up.
 
sudo shutdown -r now

don't forget the "-r" .. i did that today. kind of neat actually.. the gui disapeared and it dropped me into my shell, but then blew a bootstrap error before being able to shutdown all the way so i was temporarily stuck there.
 
I've known this for some time, never thought to share it though, it is quite useful. And it looks funny when the OS X boot screen pops up on top of your desktop (use -g).
And why would you use 'sudo shutdown -r now' when you can just type 'sudo reboot'...using shutdown with the -r option just calls reboot anyways. Save yourself some typing :D
As for starting the rest of OS X from the command-line (single-user mode I'm assuming?) make sure to mount your volumes read/write and then just run 'SystemStarter -g' (without the quotes obviously...the -g is for graphical startup)

(edit)
Well I just tested the method I described above for starting the rest of OS X from single-user mode and it seems to just leave my iBook trapped on the generic blue desktop after starting all the system services... I know it worked on previous versions of OS X, I guess they changed it in 10.2 so it doesn't work... :rolleyes: :confused: Then again they've changed a lot of things you can and can't do from single-user... I could change your root password to whatever I want from single user without having to know what it was originally on 10.0.x....ahh the good old days ;) :p
 
huh. that might be good info to find ..

as for the reboot/shutdown ... i'm not sure about os x, but in other bsd's (freeBSD, openBSD) if you try a "reboot -n" it will shut down your computer without unmounting the drives, and then you have to mount them again from single user (total pain in the culo) before it will boot again. so i stick to using shutdown .. i mean it's not that much more typing.
 
Shutdown Commands
This will shut down your system in five minutes:
sudo shutdown +5

This will reboot your system in five minutes:
sudo shutdown -r +5

This will reboot your system now:
sudo shutdown -r now
or
sudo reboot

This will reboot your system in five minutes and pass on a warning message to all logged in shell users and then reboot into OS 9:
sudo shutdown -r +5 'need Mac OS 9' ; bless -folder9 '/System Folder' -setOF
 
Two other options
You can also restart individual daemons with this syntax:
sudo kill -HUP `cat /var/run/lookupd.pid`
(This example shows how to restart lookupd.)
This type of command will work for any of the processes listed in /var/run/:
Code:
AppleFileServer.pid
autodiskmount.pid
automount.pid
configd.pid
cron.pid
davlocks
httpd.pid
inetd.pid
lookupd.pid
mDNSResponder.pid
netinfo_local.pid
ntpd.pid
sshd.pid
syslog.pid
xinetd.pid
Also, /System/Library/SystemConfiguration/Kicker.bundle/Resources/ contains graceful methods for restarting the listed services. They are largely just "nicer" versions of a sudo kill -HUP `cat /var/run/whatever.pid`. Still, they are more elegant and have better error handling routines, so it may be the preferred methodology for restarting those processes in the list.
Code:
/System/Library/SystemConfiguration/Kicker.bundle/Resources/
total 32k
drwxr-xr-x   10 root     wheel         340 Jul 27 01:39 .
drwxr-xr-x    4 root     wheel         136 Jul 27 01:39 ..
-rw-r--r--    1 root     wheel         787 Jul 17 21:30 Info-macos.plist
-rw-r--r--    1 root     wheel        2.2k Jul 11 19:07 Kicker.xml
-rwxr-xr-x    1 root     wheel         503 Jun 25 20:39 enable-network

-rwxr-xr-x    1 root     wheel        2.7k May 12  2002 restart-AppleTalk

-rwxr-xr-x    1 root     wheel        2.3k Feb 22  2002 restart-NetInfo

-rwxr-xr-x    1 root     wheel         725 Mar 29  2001 restart-lookupd

-rwxr-xr-x    1 root     wheel        1.1k Jul 17 17:32 set-hostname
-rw-r--r--    1 root     wheel         429 Jul 27 01:39 version.plist
SystemStarter is an alternative method for restarting specific processes, but can be used for a blanket restart command. (Your mileage may vary however, on whether the daemons will respond well or at all to the restart command.) One very good use for SystemStarter: it is handy for testing StartupItems or is an option for those whose uptime is the paramount concern [servers or otherwise]. Like any tool, it has its place and time for use.
 
Originally posted by gatorparrots
Shutdown Commands
This will shut down your system in five minutes:
sudo shutdown +5

This will reboot your system in five minutes:
sudo shutdown -r +5

This will reboot your system now:
sudo shutdown -r now
or
sudo reboot

This will reboot your system in five minutes and pass on a warning message to all logged in shell users and then reboot into OS 9:
sudo shutdown -r +5 'need Mac OS 9' ; bless -folder9 '/System Folder' -setOF

So, if you make them negative numbers, will the computer shut down or reboot 5 minutes ago? :p
 
Back
Top