This article shows you how to automatically set up DB2 for Linux, UNIX, and Windows (hereafter referred to as DB2) and IBM Content Manager. The automatic installation scripts are written in Python, which enables these two products to be installed without human intervention.
The setup of each product is divided into three main steps:
- Pre-installation steps are performed to check whether the requirements of the product are met.
- Installation starts.
- Post-installation steps are executed after installation is complete to verify a successful installation and to allow for some extra tasks to be done based on project requirements; for example, it might check the installation logs to confirm that no error occurred in the installation or execute some DB2 SQL scripts to set up a DB2 database for development.
To set up a product like DB2 automatically, you need a silent installation. In a silent installation, you use response files to specify the configuration parameters that you'd normally type in the installer's GUI. A response file is a text file with one line for each input field that you'd find in the regular interactive installation.
In general, there are two ways to prepare a response file:
- Saving: When performing manual installation, you can have the installer generate one, recording the options that you've selected during the installation, and then make some small modifications as needed. This is quite useful if you're installing the exact same components on a large number of machines.
- Editing: Modify a response file from a common template. A template response file displays all the possible options that you can specify, but it's more difficult because you must be an expert on the response file template.
In the automatic installation scripts, several response files are already provided. You can use them directly, make some modifications, or users can overwrite the response file. An example of a DB2 response file is shown in Listing 1.
Listing 1. Example of a DB2 response file
PROD=ENTERPRISE_SERVER_EDITION LIC_AGREEMENT=ACCEPT # installation destination dir FILE=C:\IBM\SQLLIB\ INSTALL_TYPE=CUSTOM COMP=SPATIAL_EXTENDER_SAMPLES COMP=INFORMATION_CATALOG_SAMPLES COMP=JDBC_SUPPORT COMP=IBM_JDK COMP=IBM_JRE COMP=LDAP_EXPLOITATION ... ... ... ... COMP=TCPIP_DB2_LISTENER_SUPPORT LANG=EN DAS_CONTACT_LIST=LOCAL INSTANCE=DB2 DB2.NAME=DB2 DEFAULT_INSTANCE=DB2 DB2.AUTOSTART=YES #db2 user name and password DB2.USERNAME=db2admin DB2.PASSWORD=244259359291351148346332 ... ... ... ... DB2_ADMINGROUP_NAME=DB2ADMNS |
As discussed in the Introduction, complete the following three main steps—pre-installation, installation, and post-installation—to finish DB2 setup.
- Check to see whether there's a DB2 product installed in the
destination directory, as shown in Listing 2.
Listing 2. DB2 pre-installation#1. Check to see whether there's a DB2 product installed in the destination dir. def checkDB2Installed(): filename = "db2level_output.txt"; db2level = os.path.join(db2BinDir, "db2level.exe") executeFile = db2level + " > " + filename os.system(executeFile) if(os.path.exists(filename)): f = file(filename) for line in f: if(line.startswith("Product is installed at \"" + db2BinDir + "\".")): return True return False
- Check to see if the DB2 response file is already prepared.
- Execute the DB2 silent installation, as shown in Listing 3.
Listing 3. DB2 installation#execute DB2 installation def executeDB2Installation() : #1. Check to see if the response file is prepared. if os.path.exists(responseFile): executeFile = executeFile + " -f -l " + db2_log + " -u " + responseFile #2. execute silent installation os.system(executeFile) return True else : log(responseFile + " is invalid!") return False
- Make sure the installation is successful. Here you use the operation
checkDB2Installed, shown in Listing 2. - Try to find and catalog existing databases on the local hard disk, as
shown in Listing 4. This task is useful to recover the existing data
in the scenarios that a DB2 server has removed and then reinstalled.
Listing 4. Find and catalog existing databases on the local hard disk#2. Find and catalog already existed databases on the local hard disk def addExistedDatabase(): self.executeDB2Command("list database directory on " + db2InstalledBaseDir) if(os.path.exists(db2_cmd_log)) : f = file(db2_cmd_log) for line in f: #find the database name in the line, denoted by name1 databaseList.append(name) self.executeDB2Command("catalog database " + name1) return True # execute "db2cmd db2 command" def executeDB2Command() : if( os.path.exists(db2cmdFile())) : #run db2cmd db2 -z logcommand cmd = "start /D" + db2BinDir + " /I /WAIT " + db2cmdFile + " /w " + "db2 " + "-z" + db2_cmd_log + " " + command os.system(cmd) return self.checkCommandExeResult(db2_cmd_log) return False # See if the result of "db2cmd db2 command" is successful def checkCommandExeResult(self, logfile = ""): if(os.path.exists(logfile)): f = file(logfile) for line in f: if line.find("DB20000I") != -1 : return True return False return False - There are also some extra tasks based on the project requirements (see
Listing 5), such as creating tables, preparing needed data, or
creating a DB2 instance.
Listing 5. Extra tasks based on the project requirementsdef doMoreTasks(): db2.createDatabase('SampleDB') db2.executeSQLScripts('Sample.sql') #create database databaseName def createDatabase(): command = "create database " + databaseName return self.executeDB2Command(command) #execute sql scripts def executeSQLScripts(self, filename) : #run db2cmd /w db2 -tf filename -z logfile cmd = "start /D" + db2BinDir + " /I /WAIT " + db2cmdFile + " /w " + "db2 -tf " + filename + " -z " + logfile os.system(cmd) if(os.path.exists(logfile)): logfilef = file(logfile) for line in logfilef: #Find an error in the sql execution if( not line.startswith("DB20000I")): return False return True return False
Table 1 shows detailed information about how to use Python and DB2 commands in your DB2 automatic installation scripts.
Table 1. Detailed information about Python and DB2 commands
| Steps | Task | Python functions | DB2 commands |
|---|---|---|---|
| Pre-installation | Check to see if there's a DB2 product installed in the destination directory. | os.system(...) | db2level |
| Installation | Confirm that the response file has already been prepared. | os.path.exists(...) | - |
| Execute the DB2 silent installation. | os.system(...) | db2setup -f -l db2.log âu responseFile.txt | |
| Post-installation | Make sure the installation was successful. | os.system(...) | db2level |
| Find and catalog the existing databases on the local hard disk. | os.system(...) | (1) db2cmd db2(2) LIST DATABASE DIRECTORY [ON drive](3) CATALOG DATABASE database-name [AS alias] [ON drive] | |
| Perform extra tasks based on the project requirements, such as creating tables, preparing needed data, or creating a DB2 instance. | os.system(...) | db2 -tf filename -z logfiledb2 CREATE DATABASE database-name |
WebSphere Application Server V5.1.1 setup
The WebSphere Application Server V5.1.1 setup isn't the focus of this article, but we're introducing it here because IBM Content Manager needs WebSphere Application Server V5.1.1. So the following section covers just enough of the WebSphere Application Server installation and configuration to show you how it supports the IBM Content Manager installation. (For more information about WebSphere Application Server V5.1.1 installation and configuration, visit the WebSphere Application Server information center.)
WebSphere Application Server pre-installation
- Check to see whether there's a WebSphere Application Server V5.1.1 product already installed in the destination
directory, as shown in Listing 6.
Listing 6. Check to see if there's a WebSphere Application Server V5.1.1 product already installed in the destination directory#Check to see whether there's a WebSphere Application Server V5.1.1 product already installed in the destination dir def checkWASInstalled(): versionInfo = WASBinDir + "\\versionInfo.bat" if(not os.path.exists(versionInfo)): return False versionLog = "versionInfo.log" os.system(versionInfo + " > " + versionLog) installed = False; if os.path.exists(versionLog): f = file(versionLog, 'r') #Read all content in versionLog, and try to find version in the versionLog for line in f: if line.find(version) != -1: installed = True f.close() return installed
WebSphere Application Server installation
- Check to see if the WebSphere Application Server response file is prepared.
- Execute the WebSphere Application Server V5.1.0 silent installation.
Listing 7. Execute WebSphere Application Server V5.1.0 silent installationdef installWAS(self, executeFile, responseFile) : #1. Check to see if the WebSphere Application Server response file is prepared. if os.path.exists(responseFile): executeFile = executeFile + " -options " + responseFile #2. Execute WebSphere Application Server 5.1.0 silent installation. os.system(executeFile) return True else : log( responseFile + " is invalid!" ) return False
- Check to see whether WebSphere Application Server V5.1.0 is installed
successfully. Here you use the
operation
checkWASInstalled, shown in Listing 6. - Execute the WebSphere Application Server V5.1.1 fix pack silent update.
Listing 8. Execute WebSphere Application Server V5.1.1 fix pack#4. Install WebSphere Application Server 5.1.1 fix pack silent update. def installWASFixPack() : log( "start to install the fixpack of WAS ...." ) logfile = "fixpack.log"; command = FixpackExecutableFile + " -fixpack -install -installDir " + "\"" + WASInstalledDir + "\""\ + " -fixpackDir " + "\"" + FixpackDir + "\"" + " -fixpackID " + FixpackID + " -ihsInstallDir " + IHSInstalledDir + " -skipMQ " + "> " + logfile os.system(command) log( "The installation is ended!" ) return True
WebSphere Application Server post-installation
- Make sure that WebSphere Application Server
V5.1.1 has been installed successfully. Here you use the operation
checkWASInstalled, shown in Listing 6.
Table 2 shows detailed information about how you use Python and WebSphere Application Server commands in your WebSphere Application Server automatic installation scripts.
Table 2. Detailed information about Python and WebSphere Application Server commands
| Steps | Task | Python functions | WebSphere Application Server commands |
|---|---|---|---|
| Pre-installation | Check to see whether a WebSphere Application Server V5.1.1 product is installed in the destination directory. | os.system(...) | versionInfo.bat |
| Installation | Confirm that the response file has already been prepared. | os.path.exists(...) | - |
| Execute the WebSphere Application Server V5.1.0 silent installation. | os.system(...) | win\Install.exe -options responseFile.txt | |
| Execute the WebSphere Application Server V5.1.1 fix pack silent update. | os.system(...) | fixpackDir\updateSilent.bat
-fixpack -install -installDir WAS511InstalledDir
-fixpackDir fixpackDir\ fixpacks
-fixpackID "was51_fp1_win"
-ihsInstallDir IHSInstalledDir
-skipMQ > logfile | |
| Post installation | Check to see if the installation was successful. | os.system(...) | versionInfo.bat |
This section walks you through the steps involved in IBM Content Manager setup. IBM Content Manager depends on a DB2 server and WebSphere Application Server V5.1.1. So in the pre-installation of DB2 Content Manager, you also complete steps for DB2 setup and WebSphere Application Server setup.
IBM Content Manager pre-installation
- Check to see whether IBM Content Manager is installed in the destination directory.
- Check to see whether DB2 and WebSphere Application Server V5.1.1 have
been installed. If they have not been installed, please go perform the
installation steps discussed in the DB2 setup and
WebSphere
Application Server V5.1.1 setup sections.
Listing 9. IBM Content Manager pre-installation#1. Check to see if IBM Content Manager is installed in the destination dir. def checkDB2CMInstallation(): foundedString = "IBM Content Manager Enterprise Edition" if(code == "IIC"): foundedString = "IBM DB2 Information Integrator for Content" elif(code == "EC"): foundedString = "IBM Content Manager eClient" db2cmlevel = CMBinDir + "\\cmlevel.bat" > filename if(os.path.exists(db2cmlevel)) : os.system(db2cmlevel) if(os.path.exists(filename)): f = file(filename) for line in f: if(line.startswith(foundedString)): log("The " + code + " has been installed") return True log("The " + code + " has not been installed") return False #2. Check to see if DB2 and WebSphere Application Server V5.1.1 are installed def checkPreRequisit(self): if(not checkWASInstalled()): log("WAS 511 has not been installed") return False if(not checkDB2Installed()): log("DB2 has not been installed") return False return True
IBM Content Manager installation
- Start the WebSphere Application Server V5.1.1 server called server1.
Listing 10. Start the WebSphere Application Server V5.1.1 server called serverNamedef startServer(serverName): if(not self.serverStatus(serverName)): log( "try to start " + serverName) logfile = "startServer.log" startfile = WASBinDir + "\\startServer.bat" os.system(startfile) return True
- Check to see if the IBM Content Manager response file is prepared.
- Execute the IBM Content Manager silent installation.
- Make sure that IBM Content Manager is installed successfully.
Listing 11. IBM Content Manager installationdef installCM() : executeDir = CMSrcInstallDir executeFile = CMSrcInstallDir + "\\setup-cm-8.3.00.exe" responseFile = CM_response_file logfile = 'cminstall-rc.txt' successString = "0" self.installDB2CMProduct(executeDir, executeFile, responseFile) # Check that the IBM Content Manager is installed successfully. if(os.path.exists(logfile)) : f = file(logfile) for line in f: if(line.startswith(successString)): return True return False def installDB2CMProduct(executeDir, executeFile, responseFile) : if os.path.exists(responseFile) and os.path.exists(executeFile): executeFile = executeFile + " -is:javahome " + executePath + "java\\jre" + " -options " + responseFile\ + " -silent" #execute db2cm product silent instalation os.system(executeFile) return True else : log( responseFile + " or " + executeFile + " is invalid!" ) return False - Start the WebSphere Application Server V5.1.1 server named icmrm, which is added by the IBM Content Manager installation.
- Check to see if the IBM DB2 Information Integrator for Content response file is prepared.
- Execute the DB2 Information Integrator for Content silent installation.
- Make sure that DB2 Information Integrator for Content is installed
successfully.
Listing 12. DB2 Information Integrator for Content installationdef installIIC() : executeDir = IICSrcInstallDir executeFile = IICSrcInstallDir + "\\setup-ii4c-8.3.00.exe" responseFile = IIC_response_file logfile = 'ii4cinstall-rc.txt' successString = "0" if(not startServer("icmrm")): #5. Start WebSphere Application Server V5.1.1 server named icmrm. log("Fail to start icmrm, please take a look at the WebSphere server") return False self.installDB2CMProduct(executeDir, executeFile, responseFile) # Check that the DB2 Information Integrator for Content is installed successfully. if(os.path.exists(logfile)) : f = file(logfile) for line in f: if(line.startswith(successString)): return True return False - Check to see if the IBM Content Manager eClient response file has been prepared.
- Execute the IBM Content Manager eClient silent installation.
- Make sure that the IBM Content Manager eClient is
installed successfully.
Listing 13. IBM Content Manager eClient installationdef installEC() : executeDir = ECSrcInstallDir executeFile = ECSrcInstallDir + "\\setup-ec-8.3.00.exe" responseFile = EC_response_file logfile = 'ecinstall-rc.txt' successString = "0" if(not startServer("icmrm")): #5. start was 511 server named icmrm. log("Fail to start icmrm, please take a look at the WebSphere server") return False self.installDB2CMProduct(executeDir, executeFile, responseFile) # Make sure the IBM Content Manager eClient is installed successfully. if(os.path.exists(logfile)) : f = file(logfile) for line in f: if(line.startswith(successString)): return True return False
IBM Content Manager post-installation
Because you've already checked the installation result in the IBM Content Manager installation section, there are no more tasks in this step.
Table 3 shows detailed information about how you use Python, WebSphere Application Server, and IBM Content Manager commands in your IBM Content Manager automatic installation scripts.
Table 3. Detailed information about Python, WebSphere Application Server, and IBM Content Manager commands
| Step | Task | Python function | IBM Content Manager command |
|---|---|---|---|
| Pre-installation | Check to see if there's an IBM Content Manager product installed in the destination directory. | os.path.exists(...) | cmlevel.bat |
| Check to see if WebSphere Application Server is started. | os.system(...) | startServer [serverName][serverName] can be server1 or icmrm. This is a WebSphere Application Server command. | |
| Check to see if DB2 is installed. | This depends on other Python modules that were
developed earlier in the article. See the operation
checkDB2Installed in Listing 2. | ||
| Installation | Execute IBM Content Manager silent installation. | os.system(...) | [executeFile] -is:javahome executePath java\\jre -options responseFile.txt âsilent[executeFile] can be setup-cm-8.3.00.exe, setup-ii4c-8.3.00.exe, or setup-ec-8.3.00.exe due to the code (CM, IIC, or EC). |
| Post-installation | Check the installation logs to confirm that the IBM Content Manager installation is finished with no errors. | file(...) | - |
This article introduced how to automatically install DB2 and IBM Content Manager, and how to make use of Python. After finishing your design and implementation, you applied those scripts to prepare development and test environments for other team members. You've seen that it saves time and that it's easy to use. Plus, you were able to do all of this installation using only one command!
Learn
- Get more information about Python.
- Visit the DB2 Information
Center, DB2 Content Management
Information Center, and WebSphere Application Server V5.1.1
Information Center.
- The SOA and Web services zone on IBM developerWorks hosts hundreds of informative articles and introductory, intermediate, and advanced tutorials on how to develop Web services
applications.
- Play in the IBM SOA Sandbox! Increase your SOA skills through practical, hands-on experience with the IBM SOA entry points.
- The IBM SOA Web site offers an overview of SOA and how IBM can help you get there.
- Stay current with developerWorks technical events and webcasts.
- Browse for books on these and other technical topics at the
Safari bookstore.
- Check out a quick Web services on demand demo.
- Get an
RSS feed for this series.
(Find out more about
RSS.)
Get products and technologies
- Download
IBM product evaluation versions
and get your hands on application development tools and middleware
products from DB2®, Lotus®, Rational®, Tivoli®,
and WebSphere®.
Discuss
- Participate in the discussion forum.
- Get involved in the developerWorks community
by participating in developerWorks blogs.

HeQing Guan (Hawking) is a senior software engineer on the IBM Global Business Solution Center team. He has a doctorate from the Chinese Academy of Sciences and has worked in the SOA field for almost 5 years.

Qiang Bai has worked as a software engineer with the Global Business Solution Center in CSDL. In addition to focusing on software configuration management (SCM) products, he is responsible for developing the solution assets built on IBM's Service-Oriented Architecture (SOA) methodology.

YuLin Chen is a software engineer in the IBM Global Business Solution Center. He is responsible for developing the solution assets built on IBM's Service-Oriented Architecture (SOA) methodology.

YaoFei Zhu (Richard) joined the IBM China Development Lab in 2005 and has worked in Linux on POWER and on Global Business Solution Center (GBSC) teams as a system developer, application developer, and infrastructure architect. He has more than 6 years of experience in AIX, Linux, System p, System x, storage, and SOA.
Comments (Undergoing maintenance)





