Arthur Clune avatar Arthur Clune committed a77475e

refactor code and add init script

Comments (0)

Files changed (4)

vagrant/puppet/modules/backend/files/etc/init.d/glassfish

+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          glassfish
+# Required-Start:    networking
+# Required-Stop:     
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: glassfish
+# Description:       Start/stop Glassfish
+### END INIT INFO
+
+PATH="/opt/glassfish/bin:$PATH"
+export PATH
+
+case "$1" in
+    start) 
+        asadmin --port 9948 start-domain hbbackend
+    ;;
+    stop)
+        asadmin --port 9948 stop-domain hbbackend
+    ;;
+    restart)
+        asadmin --port 9948 restart-domain hbbackend
+    ;;
+esac
+    
+
+

vagrant/puppet/modules/backend/files/opt/honeynet/bin/run-it.sh

-#!/bin/sh
-
-PATH="/opt/glassfish/bin:$PATH"
-export PATH
-
-asadmin --port 9948 << EOL
-deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.virustotal.jar
-deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.cymruwhois.jar
-deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.shadowserverdns.jar
-deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.ipfilter.jar
-deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.maxmindgeoip.jar
-deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.submithttp.war
-EOL
-
-

vagrant/puppet/modules/backend/files/opt/honeynet/bin/setup-glassfish.sh

 
 if [ ! -f "/etc/glassfish_configured" ]
 then
-    PATH="/opt/glassfish/bin:$PATH"
-    export PATH
-    asadmin create-domain --nopassword=true --portbase 9900 hbbackend
-    cp /repo/hbbackend/lib/* /opt/glassfish/glassfish/domains/hbbackend/lib/
-
-    # start
-    asadmin --port 9948 start-domain hbbackend
-
-    ## postgres
-    # connection pool
-    asadmin --port 9948 create-jdbc-connection-pool --datasourceclassname org.postgresql.xa.PGXADataSource --restype javax.sql.XADataSource --property user=hbbackend:password=hbbackend:databaseName=hbbackend:serverName=localhost:port=5432 PgPool
-    asadmin --port 9948 ping-connection-pool PgPool
-    # jdbc resource
-    asadmin --port 9948 create-jdbc-resource --connectionpoolid PgPool jdbc/hbbackend
-
-    ## xadisk
-    asadmin --port 9948 create-threadpool --minthreadpoolsize=5 --maxthreadpoolsize=50 hbbackend-xadisk-thread-pool
-    # must restart domain for the thread pool to become available
-    asadmin --port 9948 restart-domain hbbackend 
-    asadmin --port 9948 create-resource-adapter-config --threadpoolid hbbackend-xadisk-thread-pool --property xaDiskHome=/opt/hbbackend/xadisk:instanceId=hbbackend xadisk
-    asadmin --port 9948 deploy --name xadisk /opt/glassfish/glassfish/domains/hbbackend/lib/xadisk-1.1.rar
-    asadmin --port 9948 create-connector-connection-pool --raname xadisk --connectiondefinition org.xadisk.connector.outbound.XADiskConnectionFactory --property instanceId=hbbackend --transactionsupport XATransaction xadisk/ConnectionFactory
-    asadmin --port 9948 ping-connection-pool xadisk/ConnectionFactory
-    asadmin --port 9948 create-connector-resource --poolname xadisk/ConnectionFactory xadisk/ConnectionFactory
-
-    ## jms
-    # stomp bridge
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.enabled=true
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.activelist=stomp
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.admin\\.user=admin
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.admin\\.password=admin
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.stomp\\.tcp\\.port=9972
-    # disable autocreate
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.autocreate\\.queue=false
-    asadmin --port 9948 set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.autocreate\\.topic=false
-    # destinations
-    asadmin --port 9948 create-jmsdest --desttype topic new_attack
-    asadmin --port 9948 create-jmsdest --desttype topic new_attack_geoip
-    asadmin --port 9948 create-jmsdest --desttype topic new_binary
-    asadmin --port 9948 create-jmsdest --desttype topic new_ip
-    asadmin --port 9948 create-jms-resource --restype javax.jms.Topic --property Name=new_attack jms/new_attack
-    asadmin --port 9948 create-jms-resource --restype javax.jms.Topic --property Name=new_attack_geoip jms/new_attack_geoip
-    asadmin --port 9948 create-jms-resource --restype javax.jms.Topic --property Name=new_binary jms/new_binary
-    asadmin --port 9948 create-jms-resource --restype javax.jms.Topic --property Name=new_ip jms/new_ip
-    # connection factories
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory jms/ConnectionFactory
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=testdurable jms/TestDurableConnectionFactory
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=ipfilter jms/DurableConsumer/ipfilter
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=cymruwhois jms/DurableConsumer/cymruwhois
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=shadowserverdns jms/DurableConsumer/shadowserverdns
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=maxmindgeoip jms/DurableConsumer/maxmindgeoip
-    asadmin --port 9948 create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=virustotal jms/DurableConsumer/virustotal
-    asadmin --port 9948 ping-connection-pool jms/ConnectionFactory
-
-    # logback config location
-    asadmin --port 9948 create-jvm-options -Dlogback.configurationFile=/opt/hbbackend/conf/logback.xml
-
-    # monitoring
-    asadmin --port 9948 enable-monitoring --modules connector-connection-pool=HIGH:connector-service=HIGH:deployment=HIGH:ejb-container=HIGH:http-service=HIGH:jdbc-connection-pool=HIGH:jms-service=HIGH:jvm=HIGH:thread-pool=HIGH:transaction-service=HIGH:jms-service=HIGH:web-container=HIGH
-
-    # finally, restart once again for a clean start
-    asadmin --port 9948 restart-domain hbbackend
-
-    touch /etc/glassfish_configured
+
+PATH="/opt/glassfish/bin:$PATH"
+export PATH
+asadmin create-domain --nopassword=true --portbase 9900 hbbackend
+cp /repo/hbbackend/lib/* /opt/glassfish/glassfish/domains/hbbackend/lib/
+
+# start
+asadmin --port 9948 start-domain hbbackend
+
+## postgres connection pool and jdbc
+asadmin --port 9948 <<EOL
+create-jdbc-connection-pool --datasourceclassname org.postgresql.xa.PGXADataSource --restype javax.sql.XADataSource --property user=hbbackend:password=hbbackend:databaseName=hbbackend:serverName=localhost:port=5432 PgPool
+ping-connection-pool PgPool
+create-jdbc-resource --connectionpoolid PgPool jdbc/hbbackend
+EOL
+
+## xadisk then restart domain for the thread pool to become available
+asadmin --port 9948 <<EOL
+create-threadpool --minthreadpoolsize=5 --maxthreadpoolsize=50 hbbackend-xadisk-thread-pool
+restart-domain hbbackend 
+create-resource-adapter-config --threadpoolid hbbackend-xadisk-thread-pool --property xaDiskHome=/opt/hbbackend/xadisk:instanceId=hbbackend xadisk
+deploy --name xadisk /opt/glassfish/glassfish/domains/hbbackend/lib/xadisk-1.1.rar
+create-connector-connection-pool --raname xadisk --connectiondefinition org.xadisk.connector.outbound.XADiskConnectionFactory --property instanceId=hbbackend --transactionsupport XATransaction xadisk/ConnectionFactory
+ping-connection-pool xadisk/ConnectionFactory
+create-connector-resource --poolname xadisk/ConnectionFactory xadisk/ConnectionFactory
+EOL
+
+## jms stomp bridge and disable autocreate
+asadmin --port 9948 <<EOL
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.enabled=true
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.activelist=stomp
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.admin\\.user=admin
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.admin\\.password=admin
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.bridge\\.stomp\\.tcp\\.port=9972
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.autocreate\\.queue=false
+set configs.config.server-config.jms-service.jms-host.default_JMS_host.property.imq\\.autocreate\\.topic=false
+EOL
+
+# destinations
+asadmin --port 9948 <<EOL
+create-jmsdest --desttype topic new_attack
+create-jmsdest --desttype topic new_attack_geoip
+create-jmsdest --desttype topic new_binary
+create-jmsdest --desttype topic new_ip
+create-jms-resource --restype javax.jms.Topic --property Name=new_attack jms/new_attack
+create-jms-resource --restype javax.jms.Topic --property Name=new_attack_geoip jms/new_attack_geoip
+create-jms-resource --restype javax.jms.Topic --property Name=new_binary jms/new_binary
+create-jms-resource --restype javax.jms.Topic --property Name=new_ip jms/new_ip
+EOL
+
+# connection factories
+asadmin --port 9948 <<EOL
+create-jms-resource --restype javax.jms.ConnectionFactory jms/ConnectionFactory
+create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=testdurable jms/TestDurableConnectionFactory
+create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=ipfilter jms/DurableConsumer/ipfilter
+create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=cymruwhois jms/DurableConsumer/cymruwhois
+create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=shadowserverdns jms/DurableConsumer/shadowserverdns
+create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=maxmindgeoip jms/DurableConsumer/maxmindgeoip
+create-jms-resource --restype javax.jms.ConnectionFactory --property ClientId=virustotal jms/DurableConsumer/virustotal
+ping-connection-pool jms/ConnectionFactory
+EOL
+
+# logback config location and monitoring
+asadmin --port 9948 <<EOL
+create-jvm-options -Dlogback.configurationFile=/opt/hbbackend/conf/logback.xml
+enable-monitoring --modules connector-connection-pool=HIGH:connector-service=HIGH:deployment=HIGH:ejb-container=HIGH:http-service=HIGH:jdbc-connection-pool=HIGH:jms-service=HIGH:jvm=HIGH:thread-pool=HIGH:transaction-service=HIGH:jms-service=HIGH:web-container=HIGH
+EOL
+
+# finally, restart once again for a clean start
+asadmin --port 9948 restart-domain hbbackend
+
+# and deploy the code
+asadmin --port 9948 <<EOL
+deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.virustotal.jar
+deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.cymruwhois.jar
+deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.shadowserverdns.jar
+deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.ipfilter.jar
+deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.maxmindgeoip.jar
+deploy /repo/hbbackend/target/modules/org.honeynet.hbbackend.submithttp.war
+EOL
+
+touch /etc/glassfish_configured
+
+
 fi
 

vagrant/puppet/modules/backend/manifests/init.pp

         recurse => "true",
         source  => "puppet:///modules/backend/opt/hbbackend"
     }
+
+    file { "/etc/init.d/glassfish":
+        ensure => "present",
+        owner  => "root", 
+        group  => "root",
+        mode   => "0755",
+        source => "puppet:///modules/backend/etc/init.d/glassfish"
+    }
+
+    file { "/etc/rc0.d/S20glassfish":
+        ensure  => link,
+        target  => "/etc/init.d/glassfish",
+        require => File["/etc/init.d/glassfish"]
+    }
+
 }
 
 # Class: postgres
 #
 #
 class backend::packages {
-
     package { ["ant", "ivy"] : ensure => present }
     package { "openjdk-7-jdk": ensure => present }
     package { "unzip": ensure => present }
 # infinite (0)
 
 class backend {
-    include backend::files, backend::packages, backend::postgres
     require backend::files
     require backend::packages
     require backend::postgres
         require => Package["postgresql"]
     }
 
+    exec { "/opt/honeynet/bin/build-backend.sh":
+        creates => "/repo/hbbackend/lib"
+    }
+    
     exec { "/opt/honeynet/bin/setup-glassfish.sh":
         require => [Exec["/opt/honeynet/bin/setup-db.sh"], Exec["/opt/honeynet/bin/install-geoip.sh"], 
                     Exec["/opt/honeynet/bin/build-backend.sh"], Exec["/opt/honeynet/bin/install-glassfish.sh"]]
     }
 
-    exec { "/opt/honeynet/bin/build-backend.sh":
-        creates => "/repo/hbbackend/lib"
+    service { "glassfish":
+        ensure => running,
+        hasrestart => true,
+        enable => true,
+        require => Exec["/opt/honeynet/bin/setup-glassfish.sh"],
     }
+
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.