winlauncher.c revision 1300
961N/A* The contents of this file are subject to the terms of the 961N/A* Common Development and Distribution License, Version 1.0 only 961N/A* (the "License"). You may not use this file except in compliance 961N/A* You can obtain a copy of the license at 961N/A* See the License for the specific language governing permissions 961N/A* and limitations under the License. 961N/A* When distributing Covered Code, include this CDDL HEADER in each 961N/A* file and include the License file at 961N/A* add the following below this CDDL HEADER, with the fields enclosed 961N/A* by brackets "[]" replaced with your own identifying information: 961N/A* Portions Copyright [yyyy] [name of copyright owner] 961N/A* Portions Copyright 2007 Sun Microsystems, Inc. 826N/A// ---------------------------------------------------- 826N/A// Generates the pid file name for a given instanceDir. 826N/A// Returns TRUE if the command name could be initiated and 826N/A// FALSE otherwise (buffer overflow because the resulting 826N/A// string is bigger than maxSize). 826N/A// ---------------------------------------------------- 1298N/A debugError(
"Unable to get the PID file name because the path was too long.");
826N/A// ---------------------------------------------------- 826N/A// Tells whether a file exists or not. If the file exists 826N/A// returns TRUE and FALSE otherwise. 826N/A// ---------------------------------------------------- 826N/A// ---------------------------------------------------- 826N/A// Deletes the pid file for a given instance directory. 826N/A// If the file could be deleted (or it does not exist) 826N/A// returns TRUE and FALSE otherwise. 826N/A// ---------------------------------------------------- 961N/A // Sometimes the lock on the system in windows takes time to be released. 1298N/A debug(
"Failed to remove the PID file. Sleeping for a bit. Will try %d more time(s).",
nTries);
826N/A// ---------------------------------------------------- 826N/A// Returns the pid stored in the pid file for a given server 826N/A// instance directory. If the pid could not be retrieved 826N/A// ---------------------------------------------------- 1298N/A char *
msg =
"File %s could not be opened.\nMost likely the server has already stopped.\n\n";
826N/A// ---------------------------------------------------- 826N/A// Kills the process associated with the provided pid. 826N/A// Returns TRUE if the process could be killed or the 826N/A// process did not exist and false otherwise. 826N/A// ---------------------------------------------------- 961N/A // process already dead 961N/A // failed to terminate the process 1298N/A debug(
"Successfully began termination process for (pid=%d).",
pid);
1298N/A // wait for the process to end. 961N/A // process is still alive, let's wait 1 sec and loop again 1298N/A debug(
"Process (pid=%d) has not yet exited. Sleeping for 1 second and will try %d more time(s).",
pid,
nTries);
826N/A// ---------------------------------------------------- 826N/A// Creates the pid file for a given instance directory. 826N/A// If the file could be created returns TRUE and FALSE 826N/A// ---------------------------------------------------- 1298N/A debugError(
"Couldn't create the pid file because the pid file name could not be constructed.");
826N/A// ---------------------------------------------------- 826N/A// Elaborate the command line: "cmd arg1 arg2..." 826N/A// If an arg contains white space(s) then add " " to protect them 826N/A// but don't do it for option (an option starts with -). 826N/A// Returns TRUE if the command name could be initiated and 826N/A// FALSE otherwise (buffer overflow because the resulting 826N/A// string is bigger than maxSize). 826N/A// ---------------------------------------------------- 1298N/A debug(
"Constructing full command line from arguments:");
961N/A // there is a quote: no need to add extra quotes 961N/A // no begining quote and white space inside => add quotes 961N/A // no white space or quotes detected, keep the arg as is 1298N/A debugError(
"Failed to construct the full commandline because the buffer wasn't big enough.");
826N/A// ---------------------------------------------------- 826N/A// Function called when we want to start the server. 826N/A// This function expects the following parameter to be passed: 826N/A// the directory of the server we want to start and the 826N/A// command line (and its argumets) that we want to execute (basically the java 826N/A// command that we want to start the server). The main reasons 826N/A// to have the command line passed are: 826N/A// 1. Keep the native code as minimal as possible. 826N/A// 2. Allow the administrator some flexibility in the way the 826N/A// server is started by leaving most of the logic in the command-line. 826N/A// This approach makes things to be closer between what is proposed 826N/A// in windows and in UNIX systems. 826N/A// If the instance could be started the code will write the pid of the process 826N/A// of the server in file that can be used for instance to stop the server 826N/A// Returns the pid of the process of the instance if it could be started and -1 826N/A// ---------------------------------------------------- 1298N/A debugError(
"Couldn't start the child process because the full command line could not be constructed.");
826N/A// ---------------------------------------------------- 826N/A// Function called when we want to stop the server. 826N/A// This code is called by the stop-ds.bat batch file to stop the server 826N/A// This function expects just one parameter to be passed 826N/A// to the executable: the directory of the server we want 826N/A// If the instance could be stopped the pid file 826N/A// is removed. This is done for security reasons: if we do 826N/A// not delete the pid file and the old pid of the process 826N/A// is used by a new process, when we call again this executable 826N/A// the new process will be killed. 826N/A// sets the pid file to be deleted on the exit of the process 826N/A// the file is not always deleted. 826N/A// Returns 0 if the instance could be stopped using the 826N/A// pid stored in a file of the server installation and 826N/A// ---------------------------------------------------- 1298N/A debug(
"Could not stop the server running at root '%s' because the pid could not be located.",
instanceDir);
826N/A// ---------------------------------------------------- 826N/A// Function called when we want to launch simply a process without attaching 826N/A// it to any command prompt (the difference with start is basically that here 826N/A// we create no pid file). 826N/A// This code is called for instance by the statuspanel.bat batch file to launch 826N/A// the status panel on windows. 826N/A// The goal of these methods is: 826N/A// Be able to launch batch files with double-click and not having a 826N/A// prompt-window associated with it. 826N/A// Launch batch files from the prompt that generate a java process that does not 826N/A// block the prompt and that keeps running even if the prompt window is closed. 826N/A// This function expects the following parameter to be passed: 826N/A// the directory of the server we want to start and the 826N/A// command line that we want to execute (basically the java 826N/A// command that we want to display the status panel). The main reasons 826N/A// to have the command line passed are: 826N/A// 1. Keep the native code as minimal as possible. 826N/A// 2. Allow the administrator some flexibility in the way the 826N/A// server is started by leaving most of the logic in the command-line. 826N/A// Returns the pid of the process associated with the command if it could be 826N/A// launched and -1 otherwise. 826N/A// ---------------------------------------------------- 1298N/A debugError(
"Couldn't launch the child process because the full command line could not be constructed.");
826N/A// ---------------------------------------------------- 826N/A// main function called by the executable. This code is 826N/A// called by the start-ds.bat, stop-ds.bat and statuspanel.bat batch files. 826N/A// The code assumes that the first passed argument is the subcommand to be 826N/A// executed and the second argument the directory of the server. The rest 826N/A// of the arguments are the arguments specific to each subcommand (see the 826N/A// comments for the functions start, stop and launch). 826N/A// ---------------------------------------------------- 1298N/A char *
msg =
"Expected command line args of [subcommand] [server directory], but got %d arguments.\n";
1298N/A char *
msg =
"Unknown subcommand: [%s]\n";