cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcken...@apache.org
Subject git commit: Fix installing as service on Windows
Date Wed, 22 Oct 2014 17:14:37 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 c774ea346 -> 51b27f207


Fix installing as service on Windows

Patch by Josh McKenzie; reviewed by Philip Thompson for CASSANDRA-8115


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/51b27f20
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/51b27f20
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/51b27f20

Branch: refs/heads/cassandra-2.1
Commit: 51b27f2078b08f3f3ede298cd04c6f78d282af66
Parents: c774ea3
Author: Joshua McKenzie <jmckenzie@apache.org>
Authored: Wed Oct 22 12:09:12 2014 -0500
Committer: Joshua McKenzie <jmckenzie@apache.org>
Committed: Wed Oct 22 12:09:12 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt            |   1 +
 bin/cassandra.bat      |  51 ++++++++++++++--------
 bin/cassandra.ps1      | 103 +++++++++++++++++++++++++++-----------------
 conf/cassandra-env.ps1 |   5 +++
 4 files changed, 103 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/51b27f20/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 4dfb81d..24e0d36 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.2
+ * Fix installing as service on Windows (CASSANDRA-8115)
  * Fix CREATE TABLE for CQL2 (CASSANDRA-8144)
  * Avoid boxing in ColumnStats min/max trackers (CASSANDRA-8109)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/51b27f20/bin/cassandra.bat
----------------------------------------------------------------------
diff --git a/bin/cassandra.bat b/bin/cassandra.bat
index 1606dcc..31a0235 100644
--- a/bin/cassandra.bat
+++ b/bin/cassandra.bat
@@ -51,7 +51,8 @@ echo Starting with legacy startup options
 if NOT DEFINED CASSANDRA_MAIN set CASSANDRA_MAIN=org.apache.cassandra.service.CassandraDaemon
 if NOT DEFINED JAVA_HOME goto :err
 
-REM ***** JAVA options *****
+REM -----------------------------------------------------------------------------
+REM JVM Opts we'll use in legacy run or installation
 set JAVA_OPTS=-ea^
  -javaagent:"%CASSANDRA_HOME%\lib\jamm-0.2.6.jar"^
  -Xms2G^
@@ -70,7 +71,6 @@ set JAVA_OPTS=-ea^
  -Dlogback.configurationFile=logback.xml
 
 REM ***** CLASSPATH library setting *****
-
 REM Ensure that any user defined CLASSPATH variables are not used on startup
 set CLASSPATH="%CASSANDRA_HOME%\conf"
 
@@ -82,31 +82,28 @@ goto okClasspath
 set CLASSPATH=%CLASSPATH%;%1
 goto :eof
 
+REM -----------------------------------------------------------------------------
 :okClasspath
 REM Include the build\classes\main directory so it works in development
 set CASSANDRA_CLASSPATH=%CLASSPATH%;"%CASSANDRA_HOME%\build\classes\main";"%CASSANDRA_HOME%\build\classes\thrift"
 set CASSANDRA_PARAMS=-Dcassandra -Dcassandra-foreground=yes
-set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% "-Dcassandra.logdir=%CASSANDRA_HOME%\logs"
-set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% "-Dcassandra.storagedir=%CASSANDRA_HOME%\data"
+set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% -Dcassandra.logdir="%CASSANDRA_HOME%\logs"
+set CASSANDRA_PARAMS=%CASSANDRA_PARAMS% -Dcassandra.storagedir="%CASSANDRA_HOME%\data"
+
 if /i "%ARG%" == "INSTALL" goto doInstallOperation
 if /i "%ARG%" == "UNINSTALL" goto doInstallOperation
-goto runDaemon
-
 
-:runDaemon
 echo Starting Cassandra Server
 "%JAVA_HOME%\bin\java" %JAVA_OPTS% %CASSANDRA_PARAMS% -cp %CASSANDRA_CLASSPATH% "%CASSANDRA_MAIN%"
 goto finally
 
+REM -----------------------------------------------------------------------------
 :doInstallOperation
 set SERVICE_JVM="cassandra"
 rem location of Prunsrv
 set PATH_PRUNSRV=%CASSANDRA_HOME%\bin\daemon\
 set PR_LOGPATH=%PATH_PRUNSRV%
 
-rem fix up java ops replace ' -' with ' ;-'
-set JAVA_OPTS_DELM=%JAVA_OPTS: -=;-%
-
 rem Allow prunsrv to be overridden
 if "%PRUNSRV%" == "" set PRUNSRV=%PATH_PRUNSRV%prunsrv
 
@@ -115,18 +112,37 @@ echo trying to delete service if it has been created already
 rem quit if we're just going to uninstall
 if /i "%ARG%" == "UNINSTALL" goto finally
 
-echo.
 echo Installing %SERVICE_JVM%. If you get registry warnings, re-run as an Administrator
 "%PRUNSRV%" //IS//%SERVICE_JVM%
-echo Setting the parameters for %SERVICE_JVM%
-rem set PR_CLASSPATH=%CASSANDRA_CLASSPATH%
-"%PRUNSRV%" //US//%SERVICE_JVM% ^
+
+echo Setting startup parameters for %SERVICE_JVM%
+set cmd="%PRUNSRV%" //US//%SERVICE_JVM% ^
  --Jvm=auto --StdOutput auto --StdError auto ^
  --Classpath=%CASSANDRA_CLASSPATH% ^
  --StartMode=jvm --StartClass=%CASSANDRA_MAIN% --StartMethod=main ^
- --StopMode=jvm --StopClass=%CASSANDRA_MAIN%  --StopMethod=stop ^
- ++JvmOptions=%JAVA_OPTS_DELM% ++JvmOptions=-DCassandra ^
- --PidFile pid.txt
+ --StopMode=jvm --StopClass=%CASSANDRA_MAIN%  --StopMethod=stop
+
+REM convert ' -' into ';-' so we can tokenize on semicolon as we may have spaces in folder
names
+set tempOptions=%JAVA_OPTS: -=;-%
+REM Append the JAVA_OPTS, each with independent ++JvmOptions as delimited list fails for
some options
+:optStrip
+for /F "tokens=1* delims=;" %%a in ("%tempOptions%") do (
+    set JVMOPTIONS=%JVMOPTIONS% ++JvmOptions=%%a
+    set tempOptions=%%b
+)
+if defined tempOptions goto :optStrip
+
+REM do the same for CASSANDRA_PARAMS
+set tempOptions=%CASSANDRA_PARAMS: -=;-%
+
+:paramStrip
+for /F "tokens=1* delims=;" %%a in ("%tempOptions%") do (
+    set JVMOPTIONS=%JVMOPTIONS% ++JvmOptions=%%a
+    set tempOptions=%%b
+)
+if defined tempOptions goto :paramStrip
+
+%cmd% %JVMOPTIONS%
 
 echo Installation of %SERVICE_JVM% is complete
 goto finally
@@ -135,6 +151,7 @@ goto finally
 echo JAVA_HOME environment variable must be set!
 pause
 
+REM -----------------------------------------------------------------------------
 :finally
 
 ENDLOCAL

http://git-wip-us.apache.org/repos/asf/cassandra/blob/51b27f20/bin/cassandra.ps1
----------------------------------------------------------------------
diff --git a/bin/cassandra.ps1 b/bin/cassandra.ps1
index 33ff97a..099f019 100644
--- a/bin/cassandra.ps1
+++ b/bin/cassandra.ps1
@@ -13,33 +13,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-param (
-    [switch]$install,
-    [switch]$uninstall,
-    [switch]$help,
-    [switch]$v,
-    [switch]$s,
-    [switch]$f,
-    [string]$p,
-    [string]$H,
-    [string]$E
-)
-
-$pidfile = "pid.txt"
-
-#-----------------------------------------------------------------------------
-Function ValidateArguments
-{
-    if ($install -and $uninstall)
-    {
-        exit
-    }
-    if ($help)
-    {
-        PrintUsage
-    }
-}
-
 #-----------------------------------------------------------------------------
 Function PrintUsage
 {
@@ -92,10 +65,6 @@ Function Main
     }
     $pidfile = "$env:CASSANDRA_HOME\$pidfile"
 
-    $logdir = "$env:CASSANDRA_HOME/logs"
-    $storagedir = "$env:CASSANDRA_HOME/data"
-    $env:CASSANDRA_PARAMS = $env:CASSANDRA_PARAMS + " -Dcassandra.logdir=""$logdir"" -Dcassandra.storagedir=""$storagedir"""
-
     # Other command line params
     if ($H)
     {
@@ -176,23 +145,29 @@ Function HandleInstallation
     echo "Setting launch parameters for [$SERVICE_JVM]"
     Start-Sleep -s 2
 
-    # Change delim from " -" to ";-" in JVM_OPTS for prunsrv
-    $env:JVM_OPTS = $env:JVM_OPTS -replace " -", ";-"
-    $env:JVM_OPTS = $env:JVM_OPTS -replace " -", ";-"
-
-    # Strip off leading ; if it's there
-    $env:JVM_OPTS = $env:JVM_OPTS.TrimStart(";")
-
-    # Broken multi-line for convenience - glued back together in a bit
     $args = @"
 //US//$SERVICE_JVM
  --Jvm=auto --StdOutput auto --StdError auto
  --Classpath=$env:CLASSPATH
  --StartMode=jvm --StartClass=$env:CASSANDRA_MAIN --StartMethod=main
  --StopMode=jvm --StopClass=$env:CASSANDRA_MAIN  --StopMethod=stop
- ++JvmOptions=$env:JVM_OPTS ++JvmOptions=-DCassandra
  --PidFile "$pidfile"
 "@
+
+    # Include cassandra params
+    $prunArgs = "$env:CASSANDRA_PARAMS $env:JVM_OPTS"
+
+    # Change to semicolon delim as we can't split on space due to potential spaces in directory
names
+    $prunArgs = $prunArgs -replace " -", ";-"
+
+    # JvmOptions w/multiple semicolon delimited items isn't working correctly.  storagedir
and logdir were
+    # both being ignored / failing to parse on startup.  See CASSANDRA-8115
+    $split_opts = $prunArgs.Split(";")
+    foreach ($arg in $split_opts)
+    {
+        $args += " ++JvmOptions=$arg"
+    }
+
     $args = $args -replace [Environment]::NewLine, ""
     $proc = Start-Process -FilePath "$env:PRUNSRV" -ArgumentList $args -PassThru -WindowStyle
Hidden
 
@@ -305,4 +280,52 @@ WARNING! Failed to write pidfile to $pidfile.  stop-server.bat and
 }
 
 #-----------------------------------------------------------------------------
+Function ValidateArguments
+{
+    if ($install -and $uninstall)
+    {
+        echo "Cannot install and uninstall"
+        exit
+    }
+    if ($help)
+    {
+        PrintUsage
+    }
+}
+
+Function CheckEmptyParam($param)
+{
+    if ([String]::IsNullOrEmpty($param))
+    {
+        echo "Invalid parameter: empty value"
+        PrintUsage
+    }
+}
+
+for ($i = 0; $i -lt $args.count; $i++)
+{
+    Switch($args[$i])
+    {
+        "-install"          { $install = $True }
+        "-uninstall"        { $uninstall = $True }
+        "-help"             { PrintUsage }
+        "-v"                { $v = $True }
+        "-f"                { $f = $True }
+        "-s"                { $s = $True }
+        "-p"                { $p = $args[++$i]; CheckEmptyParam($p) }
+        "-H"                { $H = $args[++$i]; CheckEmptyParam($H) }
+        "-E"                { $E = $args[++$i]; CheckEmptyParam($E) }
+        default
+        {
+            "Invalid argument: " + $args[$i];
+            if (-Not $args[$i].startsWith("-"))
+            {
+                echo "Note: All options require -"
+            }
+            exit
+        }
+    }
+}
+$pidfile = "pid.txt"
+
 Main

http://git-wip-us.apache.org/repos/asf/cassandra/blob/51b27f20/conf/cassandra-env.ps1
----------------------------------------------------------------------
diff --git a/conf/cassandra-env.ps1 b/conf/cassandra-env.ps1
index 47f4fa3..69bc6d1 100644
--- a/conf/cassandra-env.ps1
+++ b/conf/cassandra-env.ps1
@@ -269,6 +269,11 @@ Function SetCassandraEnvironment
     SetCassandraHome
     $env:CASSANDRA_CONF = "$env:CASSANDRA_HOME\conf"
     $env:CASSANDRA_PARAMS="-Dcassandra -Dlogback.configurationFile=logback.xml"
+
+    $logdir = "$env:CASSANDRA_HOME\logs"
+    $storagedir = "$env:CASSANDRA_HOME\data"
+    $env:CASSANDRA_PARAMS = $env:CASSANDRA_PARAMS + " -Dcassandra.logdir=""$logdir"" -Dcassandra.storagedir=""$storagedir"""
+
     SetCassandraMain
     BuildClassPath
 


Mime
View raw message