#include "nsd.h"Functions | |
| int | Ns_Main (int argc, char **argv, Ns_ServerInitProc *initProc) |
| int | Ns_WaitForStartup (void) |
| void | Ns_StopServer (char *server) |
| int | NsTclShutdownObjCmd (ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj **objv) |
| int Ns_Main | ( | int | argc, | |
| char ** | argv, | |||
| Ns_ServerInitProc * | initProc | |||
| ) |
----------------------------------------------------------------------
Ns_Main --
The AOLserver startup routine called from main(). Startup is somewhat complicated to ensure certain things happen in the correct order.
Results: Returns 0 to main() on final exit.
Side effects: Many - read comments below.
----------------------------------------------------------------------
Initialize libnsd.
Mark the server stopped until initialization is complete.
Set up configuration defaults and initial values.
AOLserver requires file descriptor 0 be open on /dev/null to ensure the server never blocks reading stdin.
Parse the command line arguments.
NB: Ignored.
Find the absolute config pathname and read the config data before a possible chroot().
Verify the uid/gid args.
In the case where uarg isn't a username, we set it to NULL, causing supplementary groups to be ignored later.
Pre-bind any sockets now, before a possible setuid from root or chroot which may hide /etc/resolv.conf required to resolve name-based addresses.
Chroot() if requested before setuid from root.
If root, determine and change to the run time user and/or group.
Set or clear supplementary groups.
Fork into the background and create a new session if running in daemon mode.
Finally, block all signals for the duration of startup to ensure any new threads inherit the blocked state.
Initialize Tcl and eval the config file.
Ensure servers were defined.
If a single server was specified, ensure it exists and update the pointer to the config string (the config server strings are considered the unique server "handles").
Set the procname used for the pid file.
Verify and change to the home directory.
Update core config values.
Open the log file now that the home directory and runtime user id have been set.
Log the first startup message which should be the first output to the open log file unless the config script generated some messages.
Log the current open file limit.
Create the pid file used.
Initialize the virtual servers.
Load non-server modules.
Run pre-startups and start the servers.
Signal startup is complete.
Run any post-startup procs.
Start the drivers now that the server appears ready and then close any remaining pre-bound sockets.
Once the drivers listen thread is started, this thread will just endlessly wait for Unix signals, calling NsRunSignalProcs() whenever SIGHUP arrives.
Print a "server shutting down" status message, set the nsconf.stopping flag for any threads calling Ns_InfoShutdownPending(), and set the absolute timeout for all systems to complete shutown.
First, stop the drivers and servers threads.
Next, start simultaneous shutdown in other systems and wait for them to complete.
Finally, execute the exit procs directly. Note that there is not timeout check for the exit procs so they should be well behaved.
Remove the pid maker file, print a final "server exiting" status message and return to main.
| void Ns_StopServer | ( | char * | server | ) |
----------------------------------------------------------------------
Ns_StopSerrver --
Shutdown a server.
Results: None.
Side effects: Server will begin shutdown process.
----------------------------------------------------------------------
| int Ns_WaitForStartup | ( | void | ) |
----------------------------------------------------------------------
Ns_WaitForStartup --
Blocks thread until the server has completed loading modules, sourcing Tcl, and is ready to begin normal operation.
Results: NS_OK/NS_ERROR
Side effects: None.
----------------------------------------------------------------------
This dirty-read is worth the effort.
| int NsTclShutdownObjCmd | ( | ClientData | dummy, | |
| Tcl_Interp * | interp, | |||
| int | objc, | |||
| Tcl_Obj ** | objv | |||
| ) |
----------------------------------------------------------------------
NsTclShutdownObjCmd --
Implements ns_shutdown as obj command.
Results: Tcl result.
Side effects: See docs.
----------------------------------------------------------------------
1.5.1