You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2016/02/15 13:18:21 UTC

ambari git commit: AMBARI-15043. ambari server upstart support (aonishuk)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.2 1e0e461fe -> 2c34af6fb


AMBARI-15043. ambari server upstart support (aonishuk)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2c34af6f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2c34af6f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2c34af6f

Branch: refs/heads/branch-2.2
Commit: 2c34af6fb859019e4a9b5f35dcfa1a31ae09fa8a
Parents: 1e0e461
Author: Andrew Onishuk <ao...@hortonworks.com>
Authored: Mon Feb 15 14:17:55 2016 +0200
Committer: Andrew Onishuk <ao...@hortonworks.com>
Committed: Mon Feb 15 14:17:55 2016 +0200

----------------------------------------------------------------------
 ambari-server/etc/init/ambari-server.conf       | 33 ++++++++++++++++++++
 ambari-server/pom.xml                           | 23 ++++++++++++++
 .../src/main/python/ambari_server/utils.py      |  4 +--
 .../src/main/python/ambari_server_main.py       | 19 +++++++++--
 4 files changed, 74 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2c34af6f/ambari-server/etc/init/ambari-server.conf
----------------------------------------------------------------------
diff --git a/ambari-server/etc/init/ambari-server.conf b/ambari-server/etc/init/ambari-server.conf
new file mode 100644
index 0000000..ba92a43
--- /dev/null
+++ b/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
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c34af6f/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 39ca740..fe555bd 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -407,6 +407,18 @@
               </sources>
             </mapping>
             <mapping>
+              <directory>/etc/init</directory>
+              <filemode>755</filemode>
+              <username>root</username>
+              <groupname>root</groupname>
+              <directoryIncluded>false</directoryIncluded>
+              <sources>
+                <source>
+                  <location>etc/init/ambari-server.conf</location>
+                </source>
+              </sources>
+            </mapping>
+            <mapping>
               <directory>/etc/ambari-server/conf</directory>
               <configuration>true</configuration>
               <sources>
@@ -888,6 +900,17 @@
               </mapper>
             </data>
             <data>
+              <src>etc/init/ambari-server.conf</src>
+              <type>file</type>
+              <mapper>
+                <type>perm</type>
+                <prefix>/etc/init</prefix>
+                <user>root</user>
+                <group>root</group>
+                <filemode>755</filemode>
+              </mapper>
+            </data>
+            <data>
               <src>target/classes/Ambari-DDL-Postgres-CREATE.sql</src>
               <type>file</type>
               <mapper>

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c34af6f/ambari-server/src/main/python/ambari_server/utils.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/utils.py b/ambari-server/src/main/python/ambari_server/utils.py
index e7cdb7b..adca486 100644
--- a/ambari-server/src/main/python/ambari_server/utils.py
+++ b/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:

http://git-wip-us.apache.org/repos/asf/ambari/blob/2c34af6f/ambari-server/src/main/python/ambari_server_main.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server_main.py b/ambari-server/src/main/python/ambari_server_main.py
index 89283fb..10bd794 100644
--- a/ambari-server/src/main/python/ambari_server_main.py
+++ b/ambari-server/src/main/python/ambari_server_main.py
@@ -54,6 +54,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 " + \
@@ -62,7 +65,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 " + \
@@ -71,7 +74,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 " \
@@ -198,7 +205,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):
@@ -271,6 +278,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:
@@ -304,5 +314,8 @@ def server_process_main(options, scmStatus=None):
 
   if scmStatus is not None:
     scmStatus.reportStarted()
+    
+  if IS_FOREGROUND:
+    procJava.communicate()
 
   return procJava