atlas_start.py 4.94 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
ATLAS_LOG_OPTS="-Datlas.log.dir=%s -Datlas.log.file=%s.log"
25 26
ATLAS_COMMAND_OPTS="-Datlas.home=%s"
ATLAS_CONFIG_OPTS="-Datlas.conf=%s"
27
DEFAULT_JVM_OPTS="-Xmx1024m -XX:MaxPermSize=512m -Dlog4j.configuration=atlas-log4j.xml -Djava.net.preferIPv4Stack=true"
Jon Maron committed
28 29 30

def main():

31 32
    is_setup = (len(sys.argv)>1) and sys.argv[1] is not None and sys.argv[1] == '-setup'

33 34
    atlas_home = mc.atlasDir()
    confdir = mc.dirMustExist(mc.confDir(atlas_home))
Jon Maron committed
35
    mc.executeEnvSh(confdir)
36
    logdir = mc.dirMustExist(mc.logDir(atlas_home))
37 38 39 40 41 42 43 44 45
    if mc.isCygwin():
        # Pathnames that are passed to JVM must be converted to Windows format.
        jvm_atlas_home = mc.convertCygwinPath(atlas_home)
        jvm_confdir = mc.convertCygwinPath(confdir)
        jvm_logdir = mc.convertCygwinPath(logdir)
    else:
        jvm_atlas_home = atlas_home
        jvm_confdir = confdir
        jvm_logdir = logdir
Jon Maron committed
46 47

    #create sys property for conf dirs
48 49 50 51
    if not is_setup:
        jvm_opts_list = (ATLAS_LOG_OPTS % (jvm_logdir, "application")).split()
    else:
        jvm_opts_list = (ATLAS_LOG_OPTS % (jvm_logdir, "atlas_setup")).split()
Jon Maron committed
52

53
    cmd_opts = (ATLAS_COMMAND_OPTS % jvm_atlas_home)
Jon Maron committed
54 55
    jvm_opts_list.extend(cmd_opts.split())

56
    config_opts = (ATLAS_CONFIG_OPTS % jvm_confdir)
57 58
    jvm_opts_list.extend(config_opts.split())

Jon Maron committed
59
    default_jvm_opts = DEFAULT_JVM_OPTS
60 61
    atlas_jvm_opts = os.environ.get(mc.ATLAS_OPTS, default_jvm_opts)
    jvm_opts_list.extend(atlas_jvm_opts.split())
Jon Maron committed
62 63

    #expand web app dir
64 65
    web_app_dir = mc.webAppDir(atlas_home)
    mc.expandWebApp(atlas_home)
Jon Maron committed
66

67
    #add hbase-site.xml to classpath
68 69 70 71 72 73 74
    hbase_conf_dir = mc.hbaseConfDir(atlas_home)

    if mc.is_hbase_local(confdir):
        print "configured for local hbase."
        mc.configure_hbase(atlas_home)
        mc.run_hbase(mc.hbaseBinDir(atlas_home), "start", hbase_conf_dir, logdir)
        print "hbase started."
75

Jon Maron committed
76
    p = os.pathsep
77
    atlas_classpath = confdir + p \
78
                       + os.path.join(web_app_dir, "atlas", "WEB-INF", "classes" ) + p \
79
                       + os.path.join(web_app_dir, "atlas", "WEB-INF", "lib", "atlas-titan-${project.version}.jar" ) + p \
80
                       + os.path.join(web_app_dir, "atlas", "WEB-INF", "lib", "*" )  + p \
81
                       + os.path.join(atlas_home, "libext", "*")
82
    if os.path.exists(hbase_conf_dir):
83
        atlas_classpath = atlas_classpath + p \
84 85
                            + hbase_conf_dir
    else: 
86 87
       if mc.is_hbase(confdir):
           raise Exception("Could not find hbase-site.xml in %s. Please set env var HBASE_CONF_DIR to the hbase client conf dir", hbase_conf_dir)
88
    
89 90 91
    if mc.isCygwin():
        atlas_classpath = mc.convertCygwinPath(atlas_classpath, True)

92
    atlas_pid_file = mc.pidFile(atlas_home)
93
            
94
    if os.path.isfile(atlas_pid_file):
95
       #Check if process listed in atlas.pid file is still running
96
       pf = file(atlas_pid_file, 'r')
97 98 99
       pid = pf.read().strip()
       pf.close() 

100
       if mc.exist_pid((int)(pid)):
101 102
           if is_setup:
               print "Cannot run setup when server is running."
103
           mc.server_already_running(pid)
104
       else:
105
           mc.server_pid_not_running(pid)
106

107 108 109
    web_app_path = os.path.join(web_app_dir, "atlas")
    if (mc.isCygwin()):
        web_app_path = mc.convertCygwinPath(web_app_path)
110 111 112 113 114 115 116 117
    if not is_setup:
        start_atlas_server(atlas_classpath, atlas_pid_file, jvm_logdir, jvm_opts_list, web_app_path)
    else:
        process = mc.java("org.apache.atlas.web.setup.AtlasSetup", [], atlas_classpath, jvm_opts_list, jvm_logdir)
        return process.wait()


def start_atlas_server(atlas_classpath, atlas_pid_file, jvm_logdir, jvm_opts_list, web_app_path):
118
    args = ["-app", web_app_path]
Jon Maron committed
119
    args.extend(sys.argv[1:])
120
    process = mc.java("org.apache.atlas.Atlas", args, atlas_classpath, jvm_opts_list, jvm_logdir)
121
    mc.writePid(atlas_pid_file, process)
122
    print "Apache Atlas Server started!!!\n"
Jon Maron committed
123

124

Jon Maron committed
125 126 127 128 129
if __name__ == '__main__':
    try:
        returncode = main()
    except Exception as e:
        print "Exception: %s " % str(e)
130
        print traceback.format_exc()
Jon Maron committed
131 132 133
        returncode = -1

    sys.exit(returncode)