|
|
|
|
|
Crtserver
Action : tom.crtserver (Category : tom, Name : crtserver, By : kikonf)
Complete Name : tom.crtserver.by.kikonf Version : 4.0 License : Modified BSD License Purpose of the tom category : Easy to customize. This category use in background the Kikonf Repoz tools to create and configure Apache Tomcat ® root installs and Catalina bases at any level (server.xml, hosts or defaults). You can use it to manage the whole Tomcat ® Architecture. Purpose of this crtserver plugin : Creates a Tomcat Catalina Base Server instance. The following shows the main Source Code File for the Action : tom.crtserver Toggle lines
## Copyright (c) 2008, Patrick Germain Placidoux
## All rights reserved.
##
## This file is part of Kikonf Public Software.
##
## Kikonf Public Software is released under the modified BSD License,
## which should accompany it or any part of it in the file "COPYING".
## If you do not have this file you can access the license
## through the WWW at http://www.kikonf.org/license/bsd/license.txt.
##
## Home: http://www.kikonf.org
## Contact: kikonf@gmx.com
CBASE_DIRS=('bin', 'logs', 'temp', 'webapps', 'work')
#------#
# Main #
#------#
# Stores the Action File's Processor Alias
var source_action_alias=ro['alias']
# Stores the Action File's First Node <=> self_action.getTop()
:ls
source_action_node=ro[0]
try:
from StringIO import StringIO
from os import path
import shutil
import os
## Retreives the Scope
action_node=self_action.getTop()
action_attrs=action_node.getAttrs()
scope_attrs=action_node.getNode('scope')[0].getAttrs()
cbase=path.normpath(path.realpath(scope_attrs.cbase))
chome=self_action.getCAttr('software_tom_catalina_home')
indent=self_action.getIndent() + 3*' '
## Check first
plateform=getOsType()
if plateform=='windows':suffix='bat'
else:suffix='sh'
catalina=path.normpath(path.realpath(chome + '/bin/catalina.' + suffix))
java_home=path.normpath(path.realpath(action_attrs.java_home))
setenv=path.normpath(path.realpath(cbase + '/bin/setenv.' + suffix))
if not path.isfile(catalina):raise xception.kikonfActionSystemException(self_action, 'inject', 'The file: ' + catalina + ', do not exist ! Advice: you may consider to install the Tomcat zip file, instead of the executable version from the Tomcat official site')
if not path.isdir(java_home):raise xception.kikonfActionSystemException(self_action, 'inject', 'The directory for JAVA_HOME: ' + java_home + ', do not exist !')
## Destroys first
print
print '## Destroys first'
verbose('cbase: ' + cbase + ' Removing.', level=self_action.getVerbose(), ifLevel=4, indent=indent, logFile=self_action.getLogFile())
if not self_action.getCAttr('test'):
if path.isdir(cbase):
shutil.rmtree(cbase, ignore_errors=False)
verbose('cbase: ' + cbase + ' Removed.', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile())
else:
message=xception.kikonfActionInformation(self_action, 'inject', 'cbase: ' + cbase + ' Not removed, because Action is running in test mode.').warn(verbose=self_action.getVerbose(), doPrint=False)
verbose(message, level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile())
## Creates the Catalina_base
print
print '## Creates the Catalina_base'
verbose('cbase: ' + cbase + ' Creating.', level=self_action.getVerbose(), ifLevel=4, indent=indent, logFile=self_action.getLogFile())
if not self_action.getCAttr('test'):
#-- Create cbase
if path.isdir(cbase):raise xception.kikonfActionSystemException(self_action, 'inject', 'cbase: ' + cbase + ' should not exist at this step !')
os.makedirs(cbase, action_attrs.mode)
#-- Create sub dirs
for dir in CBASE_DIRS:os.mkdir(path.normpath(cbase + '/' + dir), action_attrs.mode)
#-- Feed inner files
shutil.copy(catalina, path.normpath(cbase + '/bin'))
shutil.copytree(path.normpath(chome + '/conf'), path.normpath(cbase + '/conf'))
verbose('cbase: ' + cbase + ' Created.', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile())
else:
message=xception.kikonfActionInformation(self_action, 'inject', 'cbase: ' + cbase + ' Not created, because Action is running in test mode.').warn(verbose=self_action.getVerbose(), doPrint=False)
verbose(message, level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile())
if self_action.getCAttr('test'):
exit
print 'ooooooooooooo'
fd=open(setenv, 'wb')
sb=StringIO()
sb.write('set CATALINA_HOME = ' + chome + '\n')
sb.write('set CATALINA_BASE = ' + cbase + '\n')
sb.write('set JAVA_HOME = ' + java_home + '\n')
fd.write(sb.getvalue())
fd.close()
verbose('Now you can launch or stop this instance running ' + 'catalina.' + suffix + ' from cbase: ' + cbase + ' !', level=self_action.getVerbose(), ifLevel=3, indent=indent, logFile=self_action.getLogFile())
## Retreives the Scope
print
print '## Retreives the Scope'
scope_name, scope_attrs, scope=self_action.getScope(parent_node=self_action.getTop(), indent=self_action.getIndent())
self_action.verbose(scope_name=scope_name, scope_attrs=scope_attrs)
## Stores the target Scope Processor Alias and mount it
print '## Stores the target Scope Processor Alias and mount it'
var target_scope_alias=scope.pc_ro['alias']
:mount $target_scope_alias
:ls
target_node=ro[0]
print '#-- Set Engine@jvmRoute'
var jvm_route = action_attrs.jvm_route
:set jvmRoute = $jvm_route
print
print '#-- Set Server@port'
:cd /
var server_port = action_attrs.server_port
:set port = $server_port
except Exception, e:
_e=xception.kikonfActionSystemException(self_action, 'inject', 'An exception occures ! SubException is:' + str(e) + ' !')
_e.setSubException(e)
REPOZ.recordSessionException(self_action.getName(), _e)
if self_action.getVerbose()>=10:raise
# Dont forget to skipt a strict empty line at the end to let the Interpretor to interprete the End of the bloc !
Trademarks :
|