Tuesday, November 26, 2013

Configuring OpenAM Session Failover to run as a Windows Service

In hopes of saving people many hours of frustration I am documenting here what I did in order to get OpenAM session failover to run as a Windows Service rather than as a perl script (amsfo.pl). I did this so if/when the server restarts the session failover service will automatically restart. First, follow the instruction here - https://wikis.forgerock.org/confluence/display/openam/5+Extending+to+a+Dual+Instance+Deployment up to "Activating Session Failover". You will need to download and install Apache Commons Daemon, http://commons.apache.org/proper/commons-daemon/, and install/copy it to a directory where you want to reference it. Now the fun starts:
  1. Rename procrun.exe to the name you want the service to run as, I used OAMSessionFailover.exe. (Note: you may need to copy the correct binary version from the subdirectory for 64 bit exes)
  2. Rename prunsvc.exe to the name you want the service to run as, I used OAMSessionFailoverw.exe Note: no special binary version for 64 bit OSes)
  3. Make sure that JAVA_HOME and JRE_HOME environment variable is set.
  4. I found that using host names rather than virtual DNS entries works better for the cluster list
  5. Configure/Install the Apache Commons Daemon service by doing the following (replace anything in italics with your values):
    1. set SERVICE_NAME="OAMSessionFailover"
    2. set "EXECUTABLE=C:/SessionFailover/bin/OAMSessionFailover.exe"
    3. set "PR_DESCRIPTION=OpenAM Session Failover Services"
    4. set "PR_INSTALL=%EXECUTABLE%"
    5. set "PR_LOGPATH=C:/SessionFailover/logs"
    6. set "JMQ_INSTALL_DIR=C:/OpenAM-10.0.0/tools/ssoSessionTools/jmq/imq"
    7. set "PR_CLASSPATH=%JMQ_INSTALL_DIR%/lib/imq.jar;%JMQ_INSTALL_DIR%/lib/jms.jar C:/OpenAM-10.0.0/tools/ssoSessionTools/ext/je.jar;C:/OpenAM-10.0.0/tools/ssoSessionTools/locale;C:/OpenAM-10.0.0/tools/ssoSessionTools /lib/am_sessiondb.jar;."
    8. set "PR_JVM=%JRE_HOME%\bin\server\jvm.dll"
    9. set JAVA_CMD_OPTIONS=-a;cluster_list;-u;user_name;-f;passwordfile;-b;database_dir; AMSESSIONDB_ARGS;-m; C:/OpenAM-10.0.0/tools/ssoSessionTools/sfoscripts/config/lib/amsfo.conf
    10. "%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass com.sun.identity.ha.jmqdb.client.FAMHaDB --Startup=auto --StartMethod=main --StartParams="%JAVA_CMD_OPTIONS%" --StartMode=jvm
  6. . Configure the Message Broker Service by doing the following (replace anything in italics with your values):
    1. set IMQSVCADMIN_OPTIONS=-name broker_instance_name -port broker_port -cluster cluster_list
    2. %JMQ_INSTALL_DIR%\bin\imqsvcadmin.exe install -vmargs "-Xms256m -Xmx512m" -args "%IMQSVCADMIN_OPTIONS%"
    3. The message queue must start before the session failover service so do the following to tell Windows that the dependency exists:
    1. sc config OAMSessionFailover depend= Tcpip/Afd/MQ4.4_Broker
  7. Start the services
    1. sc start MQ4.4_Broker
    2. sc start OAMSessionFailover
  8. Configure OpenAM to use session failover
    1. set FAILOVER_CONF_FILE="session-failover-subconfig-attributes.txt"
    2. >%FAILOVER_CONF_FILE% (
    3. echo iplanet-am-session-jdbc-url=cluster list(host:7777,host2:7777)
    4. echo iplanet-am-session-sfo-enabled=true
    5. echo iplanet-am-session-store-cpl-max-wait-time=5000
    6. echo iplanet-am-session-store-password=password
    7. echo iplanet-am-session-store-username=user
    8. )
    9. ssoadm create-sub-cfg --servicename iPlanetAMSessionService --subconfigname sitename --subconfigid Site --priority 0 -D "%FAILOVER_CONF_FILE%" –u amadmin –f passwordfile.txt (Make sure subconfigname is you site name – it must match exact!!)
  9. This does not shutdown the process cleanly because there is no way to get to the private method that shuts down the session db (Unless you wite a hack class that makes the method public and call it that is! :)
I hope this helps someone!