Procházet zdrojové kódy

AMBARI-15043. ambari server upstart support (aonishuk)

Andrew Onishuk před 9 roky
rodič
revize
0ff86b1c86

+ 33 - 0
ambari-server/etc/init/ambari-server.conf

@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific
+
+#ambari-server
+description     "ambari server"
+
+stop on runlevel [06]
+
+env PIDFILE=/var/run/ambari-server/ambari-server.pid
+
+respawn
+
+script
+  . /etc/environment
+
+  export AMBARI_SERVER_RUN_IN_FOREGROUND=true
+  exec /etc/init.d/ambari-server start
+end script
+
+post-stop script
+  rm -f $PIDFILE
+end script

+ 4 - 0
ambari-server/src/main/assemblies/server.xml

@@ -170,6 +170,10 @@
       <directory>src/main/resources/host_scripts</directory>
       <outputDirectory>/var/lib/ambari-server/resources/host_scripts</outputDirectory>
     </fileSet>
+    <fileSet>
+      <directory>etc/init</directory>
+      <outputDirectory>/etc/init</outputDirectory>
+    </fileSet>
   </fileSets>
   <!-- Single files. Syntax:
 	  <files>

+ 2 - 2
ambari-server/src/main/python/ambari_server/utils.py

@@ -96,7 +96,7 @@ def save_pid(pid, pidfile):
       pass
 
 
-def save_main_pid_ex(pids, pidfile, exclude_list=[], kill_exclude_list=False):
+def save_main_pid_ex(pids, pidfile, exclude_list=[], kill_exclude_list=False, skip_daemonize=False):
   """
     Save pid which is not included to exclude_list to pidfile.
     If kill_exclude_list is set to true,  all processes in that
@@ -109,7 +109,7 @@ def save_main_pid_ex(pids, pidfile, exclude_list=[], kill_exclude_list=False):
     for item in pids:
       if pid_exists(item["pid"]) and (item["exe"] not in exclude_list):
         pfile.write("%s\n" % item["pid"])
-      if pid_exists(item["pid"]) and (item["exe"] in exclude_list):
+      if pid_exists(item["pid"]) and (item["exe"] in exclude_list) and not skip_daemonize:
         try:
           os.kill(int(item["pid"]), signal.SIGKILL)
         except:

+ 16 - 3
ambari-server/src/main/python/ambari_server_main.py

@@ -55,6 +55,9 @@ if ambari_provider_module is not None:
 
 jvm_args = os.getenv('AMBARI_JVM_ARGS', '-Xms512m -Xmx2048m')
 
+ENV_FOREGROUND_KEY = "AMBARI_SERVER_RUN_IN_FOREGROUND"
+IS_FOREGROUND = ENV_FOREGROUND_KEY in os.environ and os.environ[ENV_FOREGROUND_KEY].lower() == "true"
+
 SERVER_START_CMD = "{0} " \
     "-server -XX:NewRatio=3 " \
     "-XX:+UseConcMarkSweepGC " + \
@@ -63,7 +66,7 @@ SERVER_START_CMD = "{0} " \
     "{1} {2} " \
     "-cp {3} "\
     "org.apache.ambari.server.controller.AmbariServer " \
-    "> {4} 2>&1 || echo $? > {5} &"
+    "> {4} 2>&1 || echo $? > {5}"
 SERVER_START_CMD_DEBUG = "{0} " \
     "-server -XX:NewRatio=2 " \
     "-XX:+UseConcMarkSweepGC " + \
@@ -72,7 +75,11 @@ SERVER_START_CMD_DEBUG = "{0} " \
     "server=y,suspend={6} " \
     "-cp {3} " + \
     "org.apache.ambari.server.controller.AmbariServer " \
-    "> {4} 2>&1 || echo $? > {5} &"
+    "> {4} 2>&1 || echo $? > {5}"
+    
+if not IS_FOREGROUND:
+  SERVER_START_CMD += " &"
+  SERVER_START_CMD_DEBUG += " &"
 
 SERVER_START_CMD_WINDOWS = "{0} " \
     "-server -XX:NewRatio=3 " \
@@ -199,7 +206,7 @@ def wait_for_server_start(pidFile, scmStatus):
   else:
     save_main_pid_ex(pids, pidFile, [locate_file('sh', '/bin'),
                                      locate_file('bash', '/bin'),
-                                     locate_file('dash', '/bin')], True)
+                                     locate_file('dash', '/bin')], True, IS_FOREGROUND)
 
 
 def server_process_main(options, scmStatus=None):
@@ -289,6 +296,9 @@ def server_process_main(options, scmStatus=None):
   # The launched shell process and sub-processes should have a group id that
   # is different from the parent.
   def make_process_independent():
+    if IS_FOREGROUND: # upstart script is not able to track process from different pgid.
+      return
+    
     processId = os.getpid()
     if processId > 0:
       try:
@@ -322,5 +332,8 @@ def server_process_main(options, scmStatus=None):
 
   if scmStatus is not None:
     scmStatus.reportStarted()
+    
+  if IS_FOREGROUND:
+    procJava.communicate()
 
   return procJava