atlas_start.py 2.72 KB
Newer Older
Jon Maron committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/env python

#
# 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 language governing permissions and
# limitations under the License.
import os
import sys
20
import traceback
Jon Maron committed
21

22
import atlas_config as mc
Jon Maron committed
23

24
METADATA_LOG_OPTS="-Datlas.log.dir=%s -Datlas.log.file=application.log"
Jon Maron committed
25
METADATA_COMMAND_OPTS="-Dmetadata.home=%s"
26
METADATA_CONFIG_OPTS="-Dmetadata.conf=%s"
Jon Maron committed
27 28 29 30 31 32 33
DEFAULT_JVM_OPTS="-Xmx1024m"

def main():

    metadata_home = mc.metadataDir()
    confdir = mc.dirMustExist(mc.confDir(metadata_home))
    mc.executeEnvSh(confdir)
34
    logdir = mc.dirMustExist(mc.logDir(metadata_home))
Jon Maron committed
35 36 37 38 39 40 41

    #create sys property for conf dirs
    jvm_opts_list = (METADATA_LOG_OPTS % logdir).split()

    cmd_opts = (METADATA_COMMAND_OPTS % metadata_home)
    jvm_opts_list.extend(cmd_opts.split())

42 43 44
    config_opts = (METADATA_CONFIG_OPTS % confdir)
    jvm_opts_list.extend(config_opts.split())

Jon Maron committed
45 46 47 48 49 50 51 52 53 54
    default_jvm_opts = DEFAULT_JVM_OPTS
    metadata_jvm_opts = os.environ.get(mc.METADATA_OPTS, default_jvm_opts)
    jvm_opts_list.extend(metadata_jvm_opts.split())

    #expand web app dir
    web_app_dir = mc.webAppDir(metadata_home)
    mc.expandWebApp(metadata_home)

    p = os.pathsep
    metadata_classpath = confdir + p \
55 56
                       + os.path.join(web_app_dir, "atlas", "WEB-INF", "classes" ) + p \
                       + os.path.join(web_app_dir, "atlas", "WEB-INF", "lib", "*" )  + p \
Jon Maron committed
57 58
                       + os.path.join(metadata_home, "libext", "*")

59
    metadata_pid_file = mc.pidFile(metadata_home)
Jon Maron committed
60 61 62 63 64

    if os.path.isfile(metadata_pid_file):
        print "%s already exists, exiting" % metadata_pid_file
        sys.exit()

65
    args = ["-app", os.path.join(web_app_dir, "atlas")]
Jon Maron committed
66 67
    args.extend(sys.argv[1:])

68
    process = mc.java("org.apache.atlas.Main", args, metadata_classpath, jvm_opts_list, logdir)
Jon Maron committed
69 70
    mc.writePid(metadata_pid_file, process)

71
    print "Apache Atlas Server started!!!\n"
Jon Maron committed
72 73 74 75 76 77

if __name__ == '__main__':
    try:
        returncode = main()
    except Exception as e:
        print "Exception: %s " % str(e)
78
        print traceback.format_exc()
Jon Maron committed
79 80 81
        returncode = -1

    sys.exit(returncode)