Configure database session persistence using scripting
Use scripting and the wsadmin tool to configure database persistence.
Start the wsadmin scripting client.
Perform the following steps to configure database persistence. Within these steps, the following variables apply to the Jython and Jacl commands:
- node is the affected node within the configuration.
- server is the affected server within the configuration.
- cell is the affected cell within the configuration.
- db2_administrator is the ID for the database administrator.
- db2_password is the password for the ID associated with the database administrator.
Tasks
- Retrieve the configuration ID of the server to enable database persistence and store its values in the server variable.
- Jacl:
set server [$AdminConfig getid /Node:node/Server:server/]Example output:
server(cells/cell/nodes/node/servers/server |server.xml#Server_1265038035855)- Jython:
server = AdminConfig.getid('/Node:node/Server:server/')Example output: None
- Retrieve the name of the session manager, which is associated with the server values in the previous step, and assign the session manager to the sm variable.
- Jacl:
set sm [$AdminConfig list SessionManager $server]Example output:
(cells/cell/nodes/node/servers/server |server.xml#SessionManager_1256932276179)- Jython:
sm = AdminConfig.list('SessionManager', server)Example output: None
- Add the database session persistence mode value to the sm variable, which already contains the session manager value from the previous steps.
- Jacl:
$AdminConfig modify $sm {{sessionPersistenceMode "DATABASE"}}Example output: None
- Jython:
AdminConfig.modify(sm,'[[sessionPersistenceMode "DATABASE"]]')Example output: None
- Retrieve the database session persistence value for the session manager and the database session persistence mode that are set to the sm variable. Set this value to the sesdb variable.
- Jacl:
set sesdb [$AdminConfig list SessionDatabasePersistence $sm]Example output:
(cells/cell/nodes/node/servers/server |server.xml#SessionDatabasePersistence_1256932276179)- Jython:
sesdb = AdminConfig.list('SessionDatabasePersistence',sm)Example output: None
- Modify the sesdb variable to include the user ID and password to access the database and the table space name; and the Java naming and directory interface (JNDI) name.
- Jacl:
$AdminConfig modify $sesdb { {userId "db2_administrator"} {password "db2_password"} {tableSpaceName ""} {datasourceJNDIName "jdbc/SessionDataSource"} }Example output: None
- Jython:
AdminConfig.modify(sesdb,'[[userId "db2_administrator"] [password "db2_password"] [tableSpaceName ""] [datasourceJNDIName "jdbc/SessionDataSource"]]')Example output: None
- Save the configuration changes. See documentation on saving configuration changes with the wsadmin tool.
Save wsadmin configuration changes wsadmin AdminConfig Commands for the AdminConfig object Configure for database session persistence