2014年4月7日月曜日

号機ごとに違うantターゲットを起動させるときのメモ



環境変数に号機ごとに情報を仕込んでおくやりかた。
.bash_profile等に
export AP=ap1      (1号機)など判別できる情報を号機ごとにいれておく


下記内容のようなシェルスクリプトを作成し、環境変数にあわせ
antの実行対象がかわるようにする。
====================================================================
source /home/xxxxx/.bash_profile

echo "Starting build.install.$AP by ant."

cd $WORK_DIR/blog/WEB-INF/
/usr/local/ant/bin/ant -Dcode=$PRJ_CODE install-ap.clean-libs
if [ $? -ne 0 ]; then
    echo "Failed install-ap.clean-libs by ant."
    exit 1
fi

/usr/local/ant/bin/ant -Dcode=$PRJ_CODE build.install.$AP
if [ $? -ne 0 ]; then
    echo "Failed build.install by ant."
    exit 2
fi

echo "Succeeded at installation of $AP!"

exit 0
====================================================================



ant側は下記のように

====================================================================
<-- 略-->

    <target name="build.install"
      description="Install and setup files for server. "
      depends="">
      <antcall target="install-ww" />
      <antcall target="install-ap1" />
    </target>

    <target name="build.install.ap1"
      description="Install and setup files for server 1. "
      depends="">
      <antcall target="install-ww" />
      <antcall target="install-ap1" />
    </target>

    <target name="build.install.ap2"
      description="Install and setup files for server 2. "
      depends="">
      <antcall target="install-ww" />
      <antcall target="install-ap2" />
    </target>



    <target name="install-ap1"
        description="install AP server files">
        <antcall target="install-ap.copy-files" />
        <antcall target="install-ap1.setup_server" />
    </target>

    <target name="install-ap2"
        description="install AP server files">
        <antcall target="install-ap.copy-files" />
        <antcall target="install-ap2.setup_server" />
    </target>


    <target name="install-ap1.setup_server" description="Setup Tomcat and Apache" depends="build.resources">
        <install-ap serverPort="${tomcat5.server.port.1}"
                      httpPort="${tomcat5.connector.http.port.1}"
              httpRedirectPort="${tomcat5.connector.http.redirectPort.1}"
                       ajpPort="${tomcat5.connector.ajp.port.1}"
               ajpRedirectPort="${tomcat5.connector.ajp.redirectPort.1}"
              ajpMinProcessors="${tomcat5.connector.ajp.minProcessors.1}"
              ajpMaxProcessors="${tomcat5.connector.ajp.maxProcessors.1}"
            cachesize="${tomcat5.connector.cachesize.1}"
            jvmRoute="${tomcat5.engine.jvmRoute.1}"
                    />
    </target>

    <target name="install-ap2.setup_server" description="Setup Tomcat and Apache" depends="build.resources">
        <install-ap serverPort="${tomcat5.server.port.2}"
                      httpPort="${tomcat5.connector.http.port.2}"
              httpRedirectPort="${tomcat5.connector.http.redirectPort.2}"
                       ajpPort="${tomcat5.connector.ajp.port.2}"
               ajpRedirectPort="${tomcat5.connector.ajp.redirectPort.2}"
              ajpMinProcessors="${tomcat5.connector.ajp.minProcessors.2}"
              ajpMaxProcessors="${tomcat5.connector.ajp.maxProcessors.2}"
            cachesize="${tomcat5.connector.cachesize.2}"
            jvmRoute="${tomcat5.engine.jvmRoute.2}"
                    />
    </target>
<-- 略-->


            <!-- Prepare filterset -->
            <filterset id="filter.tomcat">
                <filter token="project.title" value="${project.title}" />
                <filter token="project.distname" value="${project.distname}" />
                <filter token="project.version" value="${project.version}" />
                <filter token="displayName" value="${project.title}" />
                <filter token="app_root" value="${tomcat_app_root}" />
                <filter token="workDir" value="${tomcat_workDir}" />
                <filter token="ap.log.dir" value="${tomcat_ap.log.dir}" />
                <filter token="smtp" value="${smtp}" />
            <filter token="mail_return_path" value="${mail_return_path}" />

                <filter token="db.realm.driver" value="${db.realm.driver}"/>
                <filter token="db.realm.dsn" value="${db.realm.dsn}"/>
                <filter token="db.realm.userid" value="${db.realm.userid}"/>
                <filter token="db.realm.password" value="${db.realm.password}"/>

                <filter token="db.blog.resource" value="${db.blog.resource}"/>
                <filter token="db.blog.driver" value="${db.blog.driver}"/>
                <filter token="db.blog.dsn" value="${db.blog.dsn}"/>
                <filter token="db.blog.userid" value="${db.blog.userid}"/>
                <filter token="db.blog.password" value="${db.blog.password}"/>

                <filter token="db.blog.dbcp.maxActive" value="${db.blog.dbcp.maxActive}"/>
                <filter token="db.blog.dbcp.maxWait" value="${db.blog.dbcp.maxWait}"/>
                <filter token="db.blog.dbcp.maxIdle" value="${db.blog.dbcp.maxIdle}"/>

<!-- Search Database -->
<filter token="db.search.jndi" value="${db.search.jndi}" />
<filter token="db.search.hibernate.dialect" value="${db.search.hibernate.dialect}" />
<filter token="db.search.show_sql" value="${db.search.show_sql}" />
<filter token="db.search.host" value="${db.search.host}" />
<filter token="db.search.name" value="${db.search.name}" />
<filter token="db.search.userid" value="${db.search.userid}" />
<filter token="db.search.password" value="${db.search.password}" />
<filter token="db.search.jndi" value="${db.search.jndi}" />
<filter token="db.search.hibernate.dialect" value="${db.search.hibernate.dialect}" />
<filter token="db.search.show_sql" value="${db.search.show_sql}" />
<filter token="db.search.dbcp.maxActive" value="${db.search.dbcp.maxActive}" />
<filter token="db.search.dbcp.maxWait" value="${db.search.dbcp.maxWait}" />
<filter token="db.search.dbcp.maxIdle" value="${db.search.dbcp.maxIdle}" />
<filter token="db.search.dsn" value="${db.search.dsn}" />
<filter token="db.search.driver" value="${db.search.driver}" />

              <!-- cache database -->
              <filter token="cachedb.enable" value="${cachedb.enable}" />
              <filter token="cache_db.default.host" value="${cache_db.default.host}" />
            <filter token="cache_db.default_name" value="${cache_db.default_name}" />
              <filter token="db.blog_cache.userid" value="${db.blog_cache.userid}" />
              <filter token="db.blog_cache.password" value="${db.blog_cache.password}" />
              <filter token="db.blog_cache.driver" value="${db.blog_cache.driver}" />
            <filter token="db.blog_cache.dbcp.initialSize" value="${db.blog_cache.dbcp.initialSize}" />
            <filter token="db.blog_cache.dbcp.maxActive" value="${db.blog_cache.dbcp.maxActive}" />
            <filter token="db.blog_cache.dbcp.maxIdle" value="${db.blog_cache.dbcp.maxIdle}" />
            <filter token="db.blog_cache.dbcp.minIdle" value="${db.blog_cache.dbcp.minIdle}" />
            <filter token="db.blog_cache.dbcp.maxWait" value="${db.blog_cache.dbcp.maxWait}" />
            <filter token="db.blog_cache.name" value="${db.blog_cache.name}" />
            <filter token="db.blog_cache.resource" value="${db.blog_cache.resource}" />
            <filter token="db.blog_cache.jndi" value="${db.blog_cache.jndi}" />
            <filter token="db.blog_cache.dsn" value="${db.blog_cache.dsn}" />

                <filter token="tomcat5.server.port" value="@{serverPort}"/>
                <filter token="tomcat5.connector.http.port" value="@{httpPort}"/>
                <filter token="tomcat5.connector.http.redirectPort" value="@{httpRedirectPort}"/>
              <filter token="tomcat5.connector.ajp.port" value="@{ajpPort}"/>
                <filter token="tomcat5.connector.ajp.redirectPort" value="@{ajpRedirectPort}"/>
                <filter token="tomcat5.connector.ajp.minProcessors" value="@{ajpMinProcessors}"/>
                <filter token="tomcat5.connector.ajp.maxProcessors" value="@{ajpMaxProcessors}"/>
              <filter token="tomcat5.connector.cachesize" value="@{cachesize}"/>
                <filter token="tomcat5.engine.jvmRoute" value="@{jvmRoute}"/>

                <filter token="tomcat5.cookieDomain" value="${tomcat5.cookieDomain}"/>
                <filter token="project.blog.development" value="${project.blog.development}"/>
                <filter token="blog.servlet.session_timeout" value="${blog.servlet.session_timeout}" />

                <filter token="tomcat5.server.port.1" value="${tomcat5.server.port.1}"/>
                <filter token="tomcat5.connector.http.port.1" value="${tomcat5.connector.http.port.1}"/>
                <filter token="tomcat5.connector.http.redirectPort.1" value="${tomcat5.connector.http.redirectPort.1}"/>
              <filter token="tomcat5.connector.ajp.port.1" value="${tomcat5.connector.ajp.port.1}"/>
                <filter token="tomcat5.connector.ajp.redirectPort.1" value="${tomcat5.connector.ajp.redirectPort.1}"/>
                <filter token="tomcat5.connector.ajp.minProcessors.1" value="@{tomcat5.connector.ajp.minProcessors.1}"/>
                <filter token="tomcat5.connector.ajp.maxProcessors.1" value="@{tomcat5.connector.ajp.maxProcessors.1}"/>
              <filter token="tomcat5.connector.cachesize.1" value="${tomcat5.connector.cachesize.1}"/>
              <filter token="tomcat5.engine.jvmRoute.1" value="${tomcat5.engine.jvmRoute.1}"/>
                <filter token="tomcat5.host.1" value="${tomcat5.host.1}"/>

                <filter token="tomcat5.server.port.2" value="${tomcat5.server.port.2}"/>
                <filter token="tomcat5.connector.http.port.2" value="${tomcat5.connector.http.port.2}"/>
                <filter token="tomcat5.connector.http.redirectPort.2" value="${tomcat5.connector.http.redirectPort.2}"/>
              <filter token="tomcat5.connector.ajp.port.2" value="${tomcat5.connector.ajp.port.2}"/>
                <filter token="tomcat5.connector.ajp.redirectPort.2" value="${tomcat5.connector.ajp.redirectPort.2}"/>
                <filter token="tomcat5.connector.ajp.minProcessors.2" value="@{tomcat5.connector.ajp.minProcessors.2}"/>
                <filter token="tomcat5.connector.ajp.maxProcessors.2" value="@{tomcat5.connector.ajp.maxProcessors.2}"/>
              <filter token="tomcat5.connector.cachesize.2" value="${tomcat5.connector.cachesize.2}"/>
              <filter token="tomcat5.engine.jvmRoute.2" value="${tomcat5.engine.jvmRoute.2}"/>
                <filter token="tomcat5.host.2" value="${tomcat5.host.2}"/>

                <filter token="tomcat5.server.port.3" value="${tomcat5.server.port.3}"/>
                <filter token="tomcat5.connector.http.port.3" value="${tomcat5.connector.http.port.3}"/>
                <filter token="tomcat5.connector.http.redirectPort.3" value="${tomcat5.connector.http.redirectPort.3}"/>
              <filter token="tomcat5.connector.ajp.port.3" value="${tomcat5.connector.ajp.port.3}"/>
                <filter token="tomcat5.connector.ajp.redirectPort.3" value="${tomcat5.connector.ajp.redirectPort.3}"/>
                <filter token="tomcat5.connector.ajp.minProcessors.3" value="@{tomcat5.connector.ajp.minProcessors.3}"/>
                <filter token="tomcat5.connector.ajp.maxProcessors.3" value="@{tomcat5.connector.ajp.maxProcessors.3}"/>
              <filter token="tomcat5.connector.cachesize.3" value="${tomcat5.connector.cachesize.3}"/>
              <filter token="tomcat5.engine.jvmRoute.3" value="${tomcat5.engine.jvmRoute.3}"/>
                <filter token="tomcat5.host.3" value="${tomcat5.host.3}"/>

                <filter token="tomcat5.server.port.4" value="${tomcat5.server.port.4}"/>
                <filter token="tomcat5.connector.http.port.4" value="${tomcat5.connector.http.port.4}"/>
                <filter token="tomcat5.connector.http.redirectPort.4" value="${tomcat5.connector.http.redirectPort.4}"/>
                <filter token="tomcat5.connector.ajp.port.4" value="${tomcat5.connector.ajp.port.4}"/>
                <filter token="tomcat5.connector.ajp.redirectPort.4" value="${tomcat5.connector.ajp.redirectPort.4}"/>
                <filter token="tomcat5.connector.ajp.minProcessors.4" value="@{tomcat5.connector.ajp.minProcessors.4}"/>
                <filter token="tomcat5.connector.ajp.maxProcessors.4" value="@{tomcat5.connector.ajp.maxProcessors.4}"/>
              <filter token="tomcat5.connector.cachesize.4" value="${tomcat5.connector.cachesize.4}"/>
              <filter token="tomcat5.engine.jvmRoute.4" value="${tomcat5.engine.jvmRoute.4}"/>
                <filter token="tomcat5.host.4" value="${tomcat5.host.4}"/>
              
                <filter token="tomcat5.server.port.5" value="${tomcat5.server.port.5}"/>
                <filter token="tomcat5.connector.http.port.5" value="${tomcat5.connector.http.port.5}"/>
                <filter token="tomcat5.connector.http.redirectPort.5" value="${tomcat5.connector.http.redirectPort.5}"/>
                <filter token="tomcat5.connector.ajp.port.5" value="${tomcat5.connector.ajp.port.5}"/>
                <filter token="tomcat5.connector.ajp.redirectPort.5" value="${tomcat5.connector.ajp.redirectPort.5}"/>
                <filter token="tomcat5.connector.ajp.minProcessors.5" value="@{tomcat5.connector.ajp.minProcessors.5}"/>
                <filter token="tomcat5.connector.ajp.maxProcessors.5" value="@{tomcat5.connector.ajp.maxProcessors.5}"/>
              <filter token="tomcat5.connector.cachesize.5" value="${tomcat5.connector.cachesize.5}"/>
              <filter token="tomcat5.engine.jvmRoute.5" value="${tomcat5.engine.jvmRoute.5}"/>
                <filter token="tomcat5.host.5" value="${tomcat5.host.5}"/>
              
            </filterset>
            <presetdef name="tomcat.copy-config">
                <blog:copy-file backupdir="conf/tomcat/backup"><replace>
                    <filterset refid="filter.tomcat" />
                </replace></blog:copy-file>
            </presetdef>

            <tomcat.copy-config file="conf/tomcat/server.xml"
                                tofile="${TOMCAT_HOME}/conf/server.xml"
                                encoding="Windows-31J" />
            <tomcat.copy-config file="conf/tomcat/Catalina/localhost/blog.xml"
                                tofile="${TOMCAT_HOME}/conf/Catalina/localhost/blog.xml"
                                encoding="Windows-31J" />

====================================================================



それぞれの変数値はビルドプロパティファイルなどに記載しておく

====================================================================
tomcat5.server.port.1=8005
tomcat5.connector.http.port.1=8080
tomcat5.connector.http.redirectPort.1=8443
tomcat5.connector.ajp.port.1=8009
tomcat5.connector.ajp.redirectPort.1=8443
tomcat5.connector.ajp.minProcessors.1=50
tomcat5.connector.ajp.maxProcessors.1=400
tomcat5.connector.cachesize.1=1
tomcat5.engine.jvmRoute.1=ap2
tomcat5.host.1=ap1

tomcat5.server.port.2=8005
tomcat5.connector.http.port.2=8080
tomcat5.connector.http.redirectPort.2=8443
tomcat5.connector.ajp.port.2=8009
tomcat5.connector.ajp.redirectPort.2=8443
tomcat5.connector.ajp.minProcessors.2=50
tomcat5.connector.ajp.maxProcessors.2=200
tomcat5.connector.cachesize.2=30
tomcat5.engine.jvmRoute.2=ap2
tomcat5.host.2=ap2
====================================================================

0 件のコメント:

コメントを投稿