1073N/A/*
1073N/A * CDDL HEADER START
1073N/A *
1073N/A * The contents of this file are subject to the terms of the
1073N/A * Common Development and Distribution License, Version 1.0 only
1073N/A * (the "License"). You may not use this file except in compliance
1073N/A * with the License.
1073N/A *
1073N/A * You can obtain a copy of the license at
1073N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
1073N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1073N/A * See the License for the specific language governing permissions
1073N/A * and limitations under the License.
1073N/A *
1073N/A * When distributing Covered Code, include this CDDL HEADER in each
1073N/A * file and include the License file at
1073N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1073N/A * add the following below this CDDL HEADER, with the fields enclosed
1073N/A * by brackets "[]" replaced with your own identifying information:
1073N/A * Portions Copyright [yyyy] [name of copyright owner]
1073N/A *
1073N/A * CDDL HEADER END
1073N/A *
1073N/A *
3215N/A * Copyright 2006-2008 Sun Microsystems, Inc.
6238N/A * Portions copyright 2012-2013 ForgeRock AS.
1073N/A */
1073N/A
1073N/Apackage org.opends.quicksetup;
1073N/A
5918N/Aimport static org.opends.server.util.ServerConstants.SERVER_LOCK_FILE_NAME;
5918N/Aimport static org.opends.server.util.ServerConstants.LOCK_FILE_SUFFIX;
1570N/Aimport org.opends.server.core.LockFileManager;
5918N/Aimport org.opends.quicksetup.util.Utils;
1570N/A
1073N/Aimport java.io.File;
1073N/A
1073N/A/**
1073N/A * This class represents the current state of a particular installation.
1073N/A */
1073N/Apublic class Status {
1073N/A
1073N/A private Installation installation;
1073N/A
1073N/A /**
1073N/A * Creates a status instance of the installation indicated by the
1073N/A * input parameter.
1073N/A * @param installation physical installation
1073N/A */
1073N/A public Status(Installation installation) {
1073N/A this.installation = installation;
1073N/A }
1073N/A
1073N/A /**
1073N/A * Returns if the server is running on the given path.
1073N/A * NOTE: this method is to be called only when the OpenDS.jar class has
1073N/A * already been loaded as it uses classes in that jar.
1073N/A *
1570N/A * LIMITATIONS:
1570N/A * If the locks directory does not exist the mechanism fails if the server is
1570N/A * stopped. However if the server.lock does not exist AND the server is not
1570N/A * running the mechanism should work most of the times (see failing case 3).
1570N/A *
1570N/A * The cases where this mechanism does not work are:
1570N/A *
1570N/A * 1. The user deletes/renames the locks directory.
1570N/A * 2. The user deletes/renames the server.lock file AND the server is running.
1570N/A * 3. The server is not running but the user that is running the code does not
1570N/A * have file system access rights.
1570N/A * 4. The server is not running and another process has a lock on the file.
1073N/A * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE>
1570N/A * otherwise.
1073N/A */
1570N/A public boolean isServerRunning() {
1073N/A boolean isServerRunning;
5918N/A String lockFileName = SERVER_LOCK_FILE_NAME + LOCK_FILE_SUFFIX;
5918N/A String lockFile =
5918N/A Utils.getPath(new File(installation.getLocksDirectory(),
5918N/A lockFileName));
1073N/A StringBuilder failureReason = new StringBuilder();
1073N/A try {
1570N/A if (LockFileManager.acquireExclusiveLock(lockFile,
1073N/A failureReason)) {
1570N/A LockFileManager.releaseLock(lockFile,
1073N/A failureReason);
1073N/A isServerRunning = false;
1073N/A } else {
1073N/A isServerRunning = true;
1073N/A }
1073N/A }
1073N/A catch (Throwable t) {
1570N/A // Assume that if we cannot acquire the lock file the
1570N/A // server is running.
1073N/A isServerRunning = true;
1073N/A }
1073N/A return isServerRunning;
1073N/A }
1073N/A}