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/0ff86b1c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0ff86b1c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0ff86b1c Branch: refs/heads/branch-dev-patch-upgrade Commit: 0ff86b1c869ea1a3e13087e37225dd99a8e37926 Parents: 230c1d6 Author: Andrew Onishuk <[email protected]> Authored: Mon Feb 15 14:18:45 2016 +0200 Committer: Andrew Onishuk <[email protected]> Committed: Mon Feb 15 14:18:45 2016 +0200 ---------------------------------------------------------------------- ambari-server/etc/init/ambari-server.conf | 33 ++++++++++++++++++++ ambari-server/src/main/assemblies/server.xml | 4 +++ .../src/main/python/ambari_server/utils.py | 4 +-- .../src/main/python/ambari_server_main.py | 19 +++++++++-- 4 files changed, 55 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/0ff86b1c/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/0ff86b1c/ambari-server/src/main/assemblies/server.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/assemblies/server.xml b/ambari-server/src/main/assemblies/server.xml index ca74185..e1a4919 100644 --- a/ambari-server/src/main/assemblies/server.xml +++ b/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> http://git-wip-us.apache.org/repos/asf/ambari/blob/0ff86b1c/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 49af869..c4990f5 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/0ff86b1c/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 5c98bf4..8be3239 100644 --- a/ambari-server/src/main/python/ambari_server_main.py +++ b/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
