简体   繁体   English

wsadmin-Jython脚本未指定时拾取PWD

[英]wsadmin - Jython script picking up PWD when its not specified

TL;DR, Some how the Present Working Directory is being prepended to the EAR location. TL; DR,有关如何将当前工作目录添加到EAR位置的一些信息。

I am trying to run a Jython script for IBM WebSphere ND to do a batch install of some applications in a directory. 我试图为IBM WebSphere ND运行Jython脚本,以在目录中批量安装某些应用程序。 The script takes two arguments, the path to the EARs, and then the Module Mappings. 该脚本采用两个参数,即EAR的路径,然后是模块映射。 Going through this script, it does the discovery of the Apps correctly, and prints the correct AdminApp.install() command, but when I run the actual command, it somehow is putting the PWD in the EAR directory. 通过此脚本,它将正确发现应用程序,并打印正确的AdminApp.install()命令,但是当我运行实际命令时,它将以某种方式将PWD放在EAR目录中。

# This script takes a batch list of EAR names with the extension .ear
# example:
#   script.py "/path/to/ear/files" "WebSphere:cell=CELL,stuff=..."
#

import os
import sys 

# Gets the Cell Name for the environment
cell_name = AdminControl.getCell()

# Get DMGR Name
dmgr_name = "DMGRDEV" # Needs to not be hardcoded

# The location where the EARs will be stored to be installed. 
#ear_location = "/home/wasadmin/ears"
ear_location = sys.argv[0]

# Gets list of files in a directory
dirs = os.listdir( ear_location )

# JVMs and clusters to map the application to. 
map_to_modules = sys.argv[1]

for app_name in dirs :
  install_app = "'%s/%s', '[ -MapModulesToServers [[ %s ]]]'" % ( ear_location, app_name, map_to_modules )
  print("Installing " + app_name + ".")
  print("AdminApp.install( %s )" % ( install_app ) )
  AdminApp.install( install_app )
  print("Saving Changes.")
  AdminConfig.save()
  print("Synching Changes.")
  AdminControl.invoke('' + AdminControl.completeObjectName(""+ dmgr_name +",type=DeploymentManager,*") + '', 'multiSync', '[false]', '[java.lang.Boolean]')
# End of for app_name in applicaiton_array

Then I run that script using these commands. 然后,我使用这些命令运行该脚本。 I made a Run_wsadmin.sh wrapper to mask the username and passwords among other options to launch the wsadmin console and run scripts. 我做了一个Run_wsadmin.sh包装程序,以掩盖用户名和密码以及启动wsadmin控制台和运行脚本的其他选项。

Run_wsadmin.sh -f installEAR.py "/opt/IBM/WebSphere/AppExports3" "WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00"
WASX7209I: Connected to process "dmgr" on node DMGRDEV using SOAP connector;  The type of process is: DeploymentManager
WASX7303I: The following options are passed to the scripting environment and are available as arguments that are stored in the argv variable: "[/opt/IBM/WebSphere/AppExports3, WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00]"
Installing Solution_ChangeApp.ear.
AdminApp.install( '/opt/IBM/WebSphere/AppExports3/Solution_ChangeApp.ear', '[ -MapModulesToServers [[ WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00 ]]]' )
WASX7017E: Exception received while running file "installEAR.py"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7115E: Cannot read input file "/home/wasadmin/ContinuousIntegrationScripts/'/opt/IBM/WebSphere/AppExports3/Solution_ChangeApp.ear', '[ -MapModulesToServers [[ WebSphere:cell=wsibpmpsdev00Cell01,cluster=DEV00_DE_1.AppCluster+WebSphere:cell=wsibpmpsdev00Cell01,node=WPS00,server=DEV00IHS00 ]]]'" 

So, I'm not sure where the PWD is coming from, but in the EAR Location, it keeps prepending the present working directory. 因此,我不确定PWD来自何处,但是在EAR位置,它始终位于当前工作目录的前面。 Where is that coming from? 那是哪里来的 This has been driving me insane all day, and I'm out of options. 这整天让我发疯,而我没有选择。

The signature is: 签名是:

AdminApp.install(earFile,options)

So it's probably easier to try breaking it apart into two separate args like: 因此,尝试将其拆分为两个单独的args可能更容易:

for app_name in dirs :
    install_app_loc = "%s/%s" % ( ear_location, app_name)
    install_app_opts = "'[ -MapModulesToServers [[ %s ]]]'" % ( map_to_modules )
    # ...
    AdminApp.install( install_app_loc, install_app_opts)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM