dev/provisioning/modules/sysconfig/manifests/handle.pp
changeset 150 cb4c47eda2db
parent 146 dc4d1cdc47e0
child 153 338bcc78d431
--- a/dev/provisioning/modules/sysconfig/manifests/handle.pp	Fri Apr 08 19:30:17 2016 +0200
+++ b/dev/provisioning/modules/sysconfig/manifests/handle.pp	Tue Apr 12 13:05:43 2016 +0200
@@ -1,14 +1,15 @@
 class sysconfig::handle (
-    $hdl_host     = hiera('sysconfig::params::hdl_host', $sysconfig::params::hdl_host),
-    $hdl_user     = hiera('sysconfig::params::hdl_user', $sysconfig::params::hdl_user),
-    $hdl_srv_port = hiera('sysconfig::params::hdl_srv_port', $sysconfig::params::hdl_srv_port),
-    $hdl_web_port = hiera('sysconfig::params::hdl_web_port', $sysconfig::params::hdl_web_port),
-    $hdl_key_pswd = hiera('sysconfig::params::hdl_key_pswd', $sysconfig::params::hdl_key_pswd),
-    $hdl_prefix   = hiera('sysconfig::params::hdl_prefix', $sysconfig::params::hdl_prefix),
-    $hdl_db_name  = hiera('sysconfig::params::hdl_db_name', $sysconfig::params::hdl_db_name),
-    $db_user      = hiera('sysconfig::params::db_user',      $sysconfig::params::db_user),
-    $db_pw        = hiera('sysconfig::params::db_pw',        $sysconfig::params::db_pw),
-    $db_host      = hiera('sysconfig::params::db_host',      $sysconfig::params::db_host)
+    $hdl_host           = hiera('sysconfig::params::hdl_host', $sysconfig::params::hdl_host),
+    $hdl_user           = hiera('sysconfig::params::hdl_user', $sysconfig::params::hdl_user),
+    $hdl_srv_port       = hiera('sysconfig::params::hdl_srv_port', $sysconfig::params::hdl_srv_port),
+    $hdl_web_port       = hiera('sysconfig::params::hdl_web_port', $sysconfig::params::hdl_web_port),
+    $hdl_key_pswd       = hiera('sysconfig::params::hdl_key_pswd', $sysconfig::params::hdl_key_pswd),
+    $hdl_prefix         = hiera('sysconfig::params::hdl_prefix', $sysconfig::params::hdl_prefix),
+    $hdl_prefix_admin   = hiera('sysconfig::params::hdl_prefix_admin', $sysconfig::params::hdl_prefix_admin),
+    $hdl_db_name        = hiera('sysconfig::params::hdl_db_name', $sysconfig::params::hdl_db_name),
+    $db_user            = hiera('sysconfig::params::db_user', $sysconfig::params::db_user),
+    $db_pw              = hiera('sysconfig::params::db_pw', $sysconfig::params::db_pw),
+    $db_host            = hiera('sysconfig::params::db_host', $sysconfig::params::db_host)
 ) inherits sysconfig::params {
 
     # iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 1080
@@ -17,8 +18,7 @@
 
     $handle_dirs = [
         "/opt/handle",
-        "/opt/handle/sbin",
-        "/tmp/handle"
+        "/opt/handle/sbin"
     ]
 
     group { "$hdl_user":
@@ -41,6 +41,11 @@
     file { $handle_dirs:
         ensure => directory,
     }->
+    file { "/tmp/handle":
+        ensure => directory,
+        owner => "$hdl_user",
+        group => "$hdl_user"
+    }->
     archive { 'handle-8.1':
         ensure => present,
         url => "http://www.handle.net/hnr-source/hsj-8.1.0.tar.gz",
@@ -62,24 +67,6 @@
         source => "puppet:///modules/sysconfig/handle/mysql-connector-java-5.1.38-bin.jar",
         mode => "0644"
     }->
-    file { '/tmp/handle/handle_db.sql':
-        ensure => file,
-        source => "puppet:///modules/sysconfig/handle/handle_db.sql",
-        owner => "$hdl_user",
-        group => "$hdl_user",
-        mode => "0750"
-    }->
-    mysql::db { "handle_db":
-        dbname => $hdl_db_name,
-        user => $db_user,
-        password => $db_pw,
-        host => $db_host,
-        sql => '/tmp/handle/handle_db.sql',
-        charset => 'utf8',
-        collate => 'utf8_general_ci',
-        notify => Exec['rm-tmp-handle-db'],
-        require => Service["mariadb"],
-    }->
     file { "/tmp/handle/handle_init_script.exp":
         ensure => file,
         content => template("sysconfig/handle/handle_script.exp.erb"),
@@ -102,81 +89,81 @@
         group => "$hdl_user",
         content => template("sysconfig/handle/handle_config.dct.erb"),
         replace => true
+    }
+
+    # create handle admin handle keys
+    file { "/tmp/handle/handle_script_corpus_admin_keys.exp":
+        ensure => file,
+        source => "puppet:///modules/sysconfig/handle/handle_script_corpus_admin_keys.exp",
+        owner => "$hdl_user",
+        group => "$hdl_user",
+        mode => "0750"
     }->
+    exec { "init-handle-corpus-admin-keys":
+        command => "/tmp/handle/handle_script_corpus_admin_keys.exp",
+        cwd => "/opt/handle/bin",
+        provider => 'shell',
+        creates => "/var/lib/handle/corpusadmpriv.bin",
+        user => $hdl_user,
+        notify => Exec['rm-tmp-handle-corpus-admin-key'],
+        require => [Archive["handle-8.1"], Package['java-install'], Package['expect']]
+    }
+
+    file { '/tmp/handle/handle_data.sql.sh':
+        ensure => file,
+        content => template("sysconfig/handle/handle_data.sql.sh.erb"),
+        owner => "$hdl_user",
+        group => "$hdl_user",
+        mode => "0750"
+    }
+
+    exec { "init_handle_db_data":
+        command => "/tmp/handle/handle_data.sql.sh",
+        creates => "/tmp/handle/handle_data.sql",
+        user => $hdl_user,
+        require => [File['/tmp/handle/handle_data.sql.sh'], Exec['init-handle-corpus-admin-keys']]
+    }
+
+    file { '/tmp/handle/handle_db.sql':
+        ensure => file,
+        source => "puppet:///modules/sysconfig/handle/handle_db.sql",
+        owner => "$hdl_user",
+        group => "$hdl_user",
+        mode => "0750"
+    }
+
+    mysql::db { "handle_db":
+        dbname => $hdl_db_name,
+        user => $db_user,
+        password => $db_pw,
+        host => $db_host,
+        sql => ['/tmp/handle/handle_db.sql', '/tmp/handle/handle_data.sql'],
+        charset => 'utf8',
+        collate => 'utf8_general_ci',
+        notify => [Exec['rm-tmp-handle-db'], Exec['rm-tmp-handle-data']],
+        require => [Service["mariadb"], File['/tmp/handle/handle_db.sql'], Exec['init_handle_db_data']],
+    }
+
     exec { "handle-first-start":
         command => "/usr/bin/echo \"${HANDLE_KEY_PSWD}\" | /opt/handle/bin/hdl-server /var/lib/handle &",
         provider => 'shell',
         creates => "/var/lib/handle/.handle_initialized",
         user => $hdl_user,
-        require => File['/etc/sysconfig/handle']
+        require => [File['/etc/sysconfig/handle'], File['/var/lib/handle/config.dct'], Mysql::Db['handle_db']]
     }->
     exec { "handle-first-stop":
         command => "/usr/bin/sleep 10 && rm -f /var/lib/handle/delete_this_to_stop_server && touch /var/lib/handle/.handle_initialized",
         provider => 'shell',
         creates => "/var/lib/handle/.handle_initialized",
-        user => $hdl_user,
-        require => File['/etc/sysconfig/handle']
+        user => $hdl_user
     }->
     file_line { "handle-detached-prefix":
         path => "/var/lib/handle/config.dct",
         match => "\s*\"300:0.NA/$hdl_prefix\"",
-        line => "      \"300:$hdl_prefix/ADMIN\"",
+        line => "      \"300:$hdl_prefix/$hdl_prefix_admin\"",
         multiple => true,
     }
 
-    # file { "/tmp/handle/handle_answers.txt":
-    #     ensure => file,
-    #     content => template("sysconfig/handle/handle_answers.tmp.erb"),
-    # }#->
-    # exec { "init-handle":
-    #     command => "/opt/handle/bin/hdl-setup-server /var/lib/handle < /tmp/handle/handle_answers.txt",
-    #     cwd => "/opt/handle/bin",
-    #     provider => 'shell',
-    #     creates => "/var/lib/handle/sitebndl.zip",
-    #     user => $hdl_user,
-    #     notify => Exec['rm-tmp-handle'],
-    #     require => Package['java-install']
-    # }->
-    # file { "/var/lib/handle/config.dct":
-    #     ensure => file,
-    #     owner => "$hdl_user",
-    #     group => "$hdl_user",
-    #     content => template("sysconfig/handle/handle_config.dct.erb"),
-    #     replace => true
-    # }->
-    # exec { "open-handle-web-port":
-    #     command => "firewall-cmd --permanent --add-port=8000/tcp",
-    #     path => [ '/bin', '/usr/bin', '/usr/local/bin' ]
-    # }->
-    # exec { "open-handle-srv-port":
-    #     command => "firewall-cmd --permanent --add-port=2641/tcp",
-    #     path => [ '/bin', '/usr/bin', '/usr/local/bin' ]
-    # }->
-    # exec { "open-handle-port-reload":
-    #     command => "firewall-cmd --reload",
-    #     path => [ '/bin', '/usr/bin', '/usr/local/bin' ]
-    # }->
-    # exec { "handle-first-start":
-    #     command => "/usr/bin/echo \"${HANDLE_KEY_PSWD}\" | /opt/handle/bin/hdl-server /var/lib/handle &",
-    #     provider => 'shell',
-    #     creates => "/var/lib/handle/.handle_initialized",
-    #     user => $hdl_user,
-    #     require => File['/etc/sysconfig/handle']
-    # }->
-    # exec { "handle-first-stop":
-    #     command => "/usr/bin/sleep 10 && rm -f /var/lib/handle/delete_this_to_stop_server && touch /var/lib/handle/.handle_initialized",
-    #     provider => 'shell',
-    #     creates => "/var/lib/handle/.handle_initialized",
-    #     user => $hdl_user,
-    #     require => File['/etc/sysconfig/handle']
-    # }#->
-    # file_line { "handle-detached-prefix":
-    #     path => "/var/lib/handle/config.dct",
-    #     match => "\s*\"300:0.NA/$hdl_prefix\"",
-    #     line => "      \"300:$hdl_prefix/ADMIN\"",
-    #     multiple => true,
-    # }
-
 
     file { "/etc/sysconfig/handle":
         ensure => file,
@@ -201,18 +188,23 @@
         unless => "/usr/bin/systemctl is-enabled handle.service"
     }
 
-    # exec { "rm-tmp-handle":
-    #     command => "/usr/bin/rm /tmp/handle/handle_answers.txt",
-    #     refreshonly => true
-    # }
-
     exec { "rm-tmp-handle":
-        command => "/usr/bin/rm /tmp/handle/handle_init_script.exp",
+        command => "/usr/bin/rm -f /tmp/handle/handle_init_script.exp",
         refreshonly => true
     }
 
     exec { "rm-tmp-handle-db":
-        command => "/usr/bin/rm /tmp/handle/handle_db.sql",
+        command => "/usr/bin/rm -f /tmp/handle/handle_db.sql",
+        refreshonly => true
+    }
+
+    exec { "rm-tmp-handle-data":
+        command => "/usr/bin/rm -f /tmp/handle/handle_data.sql.sh /tmp/handle/handle_data.sql",
+        refreshonly => true
+    }
+
+    exec { "rm-tmp-handle-corpus-admin-key":
+        command => "/usr/bin/rm -f /tmp/handle/handle_script_corpus_admin_keys.exp",
         refreshonly => true
     }