CreateRCScript.java revision 4e4b322332130bf466e3bdbd9cd7c4ca832d1049
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2010-2015 ForgeRock AS.
*/
/**
* This program provides a tool that may be used to generate an RC script that
* can be used to start, stop, and restart the Directory Server, as well as to
* display its current status. It is only intended for use on UNIX-based
*/
public class CreateRCScript
{
/**
* Parse the command line arguments and create an RC script that can be used
* to control the server.
*
* @param args The command-line arguments provided to this program.
*/
{
if (exitCode != 0)
{
}
}
/**
* Parse the command line arguments and create an RC script that can be used
* to control the server.
*
* @param args The command-line arguments provided to this program.
* @param outStream The output stream to which standard output should be
* directed, or {@code null} if standard output should be
* suppressed.
* @param errStream The output stream to which standard error should be
* directed, or {@code null} if standard error should be
* suppressed.
*
* @return Zero if all processing completed successfully, or nonzero if an
* error occurred.
*/
{
if (! OperatingSystem.isUnixBased())
{
return 1;
}
if (serverRoot == null)
{
return 1;
}
try
{
false, true, INFO_PATH_PLACEHOLDER.get(),
true, INFO_USER_NAME_PLACEHOLDER.get(),
null,
null,
}
catch (ArgumentException ae)
{
return 1;
}
try
{
}
catch (ArgumentException ae)
{
return 1;
}
if (argParser.usageOrVersionDisplayed())
{
return 0;
}
// Determine the path to the Java installation that should be used.
{
if (!f.exists() || !f.isDirectory())
{
return 1;
}
javaHomeDir = f.getAbsolutePath();
}
else
{
}
{
if (! f.exists())
{
{
}
}
EscQuote1 = "";
EscQuote2 = "\"";
}
// Start writing the output file.
try
{
PrintWriter w = new PrintWriter(f);
w.println("#");
{
}
w.println("# chkconfig: 345 95 5");
w.println("# description: Control the " +
SHORT_NAME + " Directory Server");
w.println();
w.println();
w.println("export INSTALL_ROOT");
w.println();
w.println("cd ${INSTALL_ROOT}");
w.println();
if (javaHomeDir != null)
{
w.println("# Specify the path to the Java installation to use");
w.println("export OPENDJ_JAVA_HOME");
w.println();
}
{
w.println("# Specify arguments that should be provided to the JVM");
w.println("export OPENDJ_JAVA_ARGS");
w.println();
}
w.println("# Determine what action should be performed on the server");
w.println("case \"${1}\" in");
w.println("start)");
w.println(" exit ${?}");
w.println(" ;;");
w.println("stop)");
w.println(" exit ${?}");
w.println(" ;;");
w.println("restart)");
w.println(" exit ${?}");
w.println(" ;;");
w.println("*)");
w.println(" echo \"Usage: $0 { start | stop | restart }\"");
w.println(" exit 1");
w.println(" ;;");
w.println("esac");
w.println();
w.close();
}
catch (Exception e)
{
return 1;
}
// If we've gotten here, then everything has completed successfully.
return 0;
}
}