dev/provisioning/modules/sysconfig/manifests/handle.pp
changeset 150 cb4c47eda2db
parent 146 dc4d1cdc47e0
child 153 338bcc78d431
equal deleted inserted replaced
149:3ace15523e6b 150:cb4c47eda2db
     1 class sysconfig::handle (
     1 class sysconfig::handle (
     2     $hdl_host     = hiera('sysconfig::params::hdl_host', $sysconfig::params::hdl_host),
     2     $hdl_host           = hiera('sysconfig::params::hdl_host', $sysconfig::params::hdl_host),
     3     $hdl_user     = hiera('sysconfig::params::hdl_user', $sysconfig::params::hdl_user),
     3     $hdl_user           = hiera('sysconfig::params::hdl_user', $sysconfig::params::hdl_user),
     4     $hdl_srv_port = hiera('sysconfig::params::hdl_srv_port', $sysconfig::params::hdl_srv_port),
     4     $hdl_srv_port       = hiera('sysconfig::params::hdl_srv_port', $sysconfig::params::hdl_srv_port),
     5     $hdl_web_port = hiera('sysconfig::params::hdl_web_port', $sysconfig::params::hdl_web_port),
     5     $hdl_web_port       = hiera('sysconfig::params::hdl_web_port', $sysconfig::params::hdl_web_port),
     6     $hdl_key_pswd = hiera('sysconfig::params::hdl_key_pswd', $sysconfig::params::hdl_key_pswd),
     6     $hdl_key_pswd       = hiera('sysconfig::params::hdl_key_pswd', $sysconfig::params::hdl_key_pswd),
     7     $hdl_prefix   = hiera('sysconfig::params::hdl_prefix', $sysconfig::params::hdl_prefix),
     7     $hdl_prefix         = hiera('sysconfig::params::hdl_prefix', $sysconfig::params::hdl_prefix),
     8     $hdl_db_name  = hiera('sysconfig::params::hdl_db_name', $sysconfig::params::hdl_db_name),
     8     $hdl_prefix_admin   = hiera('sysconfig::params::hdl_prefix_admin', $sysconfig::params::hdl_prefix_admin),
     9     $db_user      = hiera('sysconfig::params::db_user',      $sysconfig::params::db_user),
     9     $hdl_db_name        = hiera('sysconfig::params::hdl_db_name', $sysconfig::params::hdl_db_name),
    10     $db_pw        = hiera('sysconfig::params::db_pw',        $sysconfig::params::db_pw),
    10     $db_user            = hiera('sysconfig::params::db_user', $sysconfig::params::db_user),
    11     $db_host      = hiera('sysconfig::params::db_host',      $sysconfig::params::db_host)
    11     $db_pw              = hiera('sysconfig::params::db_pw', $sysconfig::params::db_pw),
       
    12     $db_host            = hiera('sysconfig::params::db_host', $sysconfig::params::db_host)
    12 ) inherits sysconfig::params {
    13 ) inherits sysconfig::params {
    13 
    14 
    14     # iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 1080
    15     # iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 1080
    15 
    16 
    16     notify {'handle': name => "\$hdl_host : ${hdl_host}, \$hdl_srv_port : ${hdl_srv_port}, \$hdl_web_port : ${hdl_web_port}", withpath => true }
    17     notify {'handle': name => "\$hdl_host : ${hdl_host}, \$hdl_srv_port : ${hdl_srv_port}, \$hdl_web_port : ${hdl_web_port}", withpath => true }
    17 
    18 
    18     $handle_dirs = [
    19     $handle_dirs = [
    19         "/opt/handle",
    20         "/opt/handle",
    20         "/opt/handle/sbin",
    21         "/opt/handle/sbin"
    21         "/tmp/handle"
       
    22     ]
    22     ]
    23 
    23 
    24     group { "$hdl_user":
    24     group { "$hdl_user":
    25         ensure => present,
    25         ensure => present,
    26     }->
    26     }->
    38         owner => "$hdl_user",
    38         owner => "$hdl_user",
    39         group => "$hdl_user"
    39         group => "$hdl_user"
    40     }->
    40     }->
    41     file { $handle_dirs:
    41     file { $handle_dirs:
    42         ensure => directory,
    42         ensure => directory,
       
    43     }->
       
    44     file { "/tmp/handle":
       
    45         ensure => directory,
       
    46         owner => "$hdl_user",
       
    47         group => "$hdl_user"
    43     }->
    48     }->
    44     archive { 'handle-8.1':
    49     archive { 'handle-8.1':
    45         ensure => present,
    50         ensure => present,
    46         url => "http://www.handle.net/hnr-source/hsj-8.1.0.tar.gz",
    51         url => "http://www.handle.net/hnr-source/hsj-8.1.0.tar.gz",
    47         checksum => false,
    52         checksum => false,
    60     file { '/opt/handle/lib/mysql-connector-java-5.1.38-bin.jar':
    65     file { '/opt/handle/lib/mysql-connector-java-5.1.38-bin.jar':
    61         ensure => file,
    66         ensure => file,
    62         source => "puppet:///modules/sysconfig/handle/mysql-connector-java-5.1.38-bin.jar",
    67         source => "puppet:///modules/sysconfig/handle/mysql-connector-java-5.1.38-bin.jar",
    63         mode => "0644"
    68         mode => "0644"
    64     }->
    69     }->
       
    70     file { "/tmp/handle/handle_init_script.exp":
       
    71         ensure => file,
       
    72         content => template("sysconfig/handle/handle_script.exp.erb"),
       
    73         owner => "$hdl_user",
       
    74         group => "$hdl_user",
       
    75         mode => "0750"
       
    76     }->
       
    77     exec { "init-handle":
       
    78         command => "/tmp/handle/handle_init_script.exp",
       
    79         cwd => "/opt/handle/bin",
       
    80         provider => 'shell',
       
    81         creates => "/var/lib/handle/sitebndl.zip",
       
    82         user => $hdl_user,
       
    83         notify => Exec['rm-tmp-handle'],
       
    84         require => [Package['java-install'], Package['expect']]
       
    85     }->
       
    86     file { "/var/lib/handle/config.dct":
       
    87         ensure => file,
       
    88         owner => "$hdl_user",
       
    89         group => "$hdl_user",
       
    90         content => template("sysconfig/handle/handle_config.dct.erb"),
       
    91         replace => true
       
    92     }
       
    93 
       
    94     # create handle admin handle keys
       
    95     file { "/tmp/handle/handle_script_corpus_admin_keys.exp":
       
    96         ensure => file,
       
    97         source => "puppet:///modules/sysconfig/handle/handle_script_corpus_admin_keys.exp",
       
    98         owner => "$hdl_user",
       
    99         group => "$hdl_user",
       
   100         mode => "0750"
       
   101     }->
       
   102     exec { "init-handle-corpus-admin-keys":
       
   103         command => "/tmp/handle/handle_script_corpus_admin_keys.exp",
       
   104         cwd => "/opt/handle/bin",
       
   105         provider => 'shell',
       
   106         creates => "/var/lib/handle/corpusadmpriv.bin",
       
   107         user => $hdl_user,
       
   108         notify => Exec['rm-tmp-handle-corpus-admin-key'],
       
   109         require => [Archive["handle-8.1"], Package['java-install'], Package['expect']]
       
   110     }
       
   111 
       
   112     file { '/tmp/handle/handle_data.sql.sh':
       
   113         ensure => file,
       
   114         content => template("sysconfig/handle/handle_data.sql.sh.erb"),
       
   115         owner => "$hdl_user",
       
   116         group => "$hdl_user",
       
   117         mode => "0750"
       
   118     }
       
   119 
       
   120     exec { "init_handle_db_data":
       
   121         command => "/tmp/handle/handle_data.sql.sh",
       
   122         creates => "/tmp/handle/handle_data.sql",
       
   123         user => $hdl_user,
       
   124         require => [File['/tmp/handle/handle_data.sql.sh'], Exec['init-handle-corpus-admin-keys']]
       
   125     }
       
   126 
    65     file { '/tmp/handle/handle_db.sql':
   127     file { '/tmp/handle/handle_db.sql':
    66         ensure => file,
   128         ensure => file,
    67         source => "puppet:///modules/sysconfig/handle/handle_db.sql",
   129         source => "puppet:///modules/sysconfig/handle/handle_db.sql",
    68         owner => "$hdl_user",
   130         owner => "$hdl_user",
    69         group => "$hdl_user",
   131         group => "$hdl_user",
    70         mode => "0750"
   132         mode => "0750"
    71     }->
   133     }
       
   134 
    72     mysql::db { "handle_db":
   135     mysql::db { "handle_db":
    73         dbname => $hdl_db_name,
   136         dbname => $hdl_db_name,
    74         user => $db_user,
   137         user => $db_user,
    75         password => $db_pw,
   138         password => $db_pw,
    76         host => $db_host,
   139         host => $db_host,
    77         sql => '/tmp/handle/handle_db.sql',
   140         sql => ['/tmp/handle/handle_db.sql', '/tmp/handle/handle_data.sql'],
    78         charset => 'utf8',
   141         charset => 'utf8',
    79         collate => 'utf8_general_ci',
   142         collate => 'utf8_general_ci',
    80         notify => Exec['rm-tmp-handle-db'],
   143         notify => [Exec['rm-tmp-handle-db'], Exec['rm-tmp-handle-data']],
    81         require => Service["mariadb"],
   144         require => [Service["mariadb"], File['/tmp/handle/handle_db.sql'], Exec['init_handle_db_data']],
    82     }->
   145     }
    83     file { "/tmp/handle/handle_init_script.exp":
   146 
    84         ensure => file,
       
    85         content => template("sysconfig/handle/handle_script.exp.erb"),
       
    86         owner => "$hdl_user",
       
    87         group => "$hdl_user",
       
    88         mode => "0750"
       
    89     }->
       
    90     exec { "init-handle":
       
    91         command => "/tmp/handle/handle_init_script.exp",
       
    92         cwd => "/opt/handle/bin",
       
    93         provider => 'shell',
       
    94         creates => "/var/lib/handle/sitebndl.zip",
       
    95         user => $hdl_user,
       
    96         notify => Exec['rm-tmp-handle'],
       
    97         require => [Package['java-install'], Package['expect']]
       
    98     }->
       
    99     file { "/var/lib/handle/config.dct":
       
   100         ensure => file,
       
   101         owner => "$hdl_user",
       
   102         group => "$hdl_user",
       
   103         content => template("sysconfig/handle/handle_config.dct.erb"),
       
   104         replace => true
       
   105     }->
       
   106     exec { "handle-first-start":
   147     exec { "handle-first-start":
   107         command => "/usr/bin/echo \"${HANDLE_KEY_PSWD}\" | /opt/handle/bin/hdl-server /var/lib/handle &",
   148         command => "/usr/bin/echo \"${HANDLE_KEY_PSWD}\" | /opt/handle/bin/hdl-server /var/lib/handle &",
   108         provider => 'shell',
   149         provider => 'shell',
   109         creates => "/var/lib/handle/.handle_initialized",
   150         creates => "/var/lib/handle/.handle_initialized",
   110         user => $hdl_user,
   151         user => $hdl_user,
   111         require => File['/etc/sysconfig/handle']
   152         require => [File['/etc/sysconfig/handle'], File['/var/lib/handle/config.dct'], Mysql::Db['handle_db']]
   112     }->
   153     }->
   113     exec { "handle-first-stop":
   154     exec { "handle-first-stop":
   114         command => "/usr/bin/sleep 10 && rm -f /var/lib/handle/delete_this_to_stop_server && touch /var/lib/handle/.handle_initialized",
   155         command => "/usr/bin/sleep 10 && rm -f /var/lib/handle/delete_this_to_stop_server && touch /var/lib/handle/.handle_initialized",
   115         provider => 'shell',
   156         provider => 'shell',
   116         creates => "/var/lib/handle/.handle_initialized",
   157         creates => "/var/lib/handle/.handle_initialized",
   117         user => $hdl_user,
   158         user => $hdl_user
   118         require => File['/etc/sysconfig/handle']
       
   119     }->
   159     }->
   120     file_line { "handle-detached-prefix":
   160     file_line { "handle-detached-prefix":
   121         path => "/var/lib/handle/config.dct",
   161         path => "/var/lib/handle/config.dct",
   122         match => "\s*\"300:0.NA/$hdl_prefix\"",
   162         match => "\s*\"300:0.NA/$hdl_prefix\"",
   123         line => "      \"300:$hdl_prefix/ADMIN\"",
   163         line => "      \"300:$hdl_prefix/$hdl_prefix_admin\"",
   124         multiple => true,
   164         multiple => true,
   125     }
   165     }
   126 
       
   127     # file { "/tmp/handle/handle_answers.txt":
       
   128     #     ensure => file,
       
   129     #     content => template("sysconfig/handle/handle_answers.tmp.erb"),
       
   130     # }#->
       
   131     # exec { "init-handle":
       
   132     #     command => "/opt/handle/bin/hdl-setup-server /var/lib/handle < /tmp/handle/handle_answers.txt",
       
   133     #     cwd => "/opt/handle/bin",
       
   134     #     provider => 'shell',
       
   135     #     creates => "/var/lib/handle/sitebndl.zip",
       
   136     #     user => $hdl_user,
       
   137     #     notify => Exec['rm-tmp-handle'],
       
   138     #     require => Package['java-install']
       
   139     # }->
       
   140     # file { "/var/lib/handle/config.dct":
       
   141     #     ensure => file,
       
   142     #     owner => "$hdl_user",
       
   143     #     group => "$hdl_user",
       
   144     #     content => template("sysconfig/handle/handle_config.dct.erb"),
       
   145     #     replace => true
       
   146     # }->
       
   147     # exec { "open-handle-web-port":
       
   148     #     command => "firewall-cmd --permanent --add-port=8000/tcp",
       
   149     #     path => [ '/bin', '/usr/bin', '/usr/local/bin' ]
       
   150     # }->
       
   151     # exec { "open-handle-srv-port":
       
   152     #     command => "firewall-cmd --permanent --add-port=2641/tcp",
       
   153     #     path => [ '/bin', '/usr/bin', '/usr/local/bin' ]
       
   154     # }->
       
   155     # exec { "open-handle-port-reload":
       
   156     #     command => "firewall-cmd --reload",
       
   157     #     path => [ '/bin', '/usr/bin', '/usr/local/bin' ]
       
   158     # }->
       
   159     # exec { "handle-first-start":
       
   160     #     command => "/usr/bin/echo \"${HANDLE_KEY_PSWD}\" | /opt/handle/bin/hdl-server /var/lib/handle &",
       
   161     #     provider => 'shell',
       
   162     #     creates => "/var/lib/handle/.handle_initialized",
       
   163     #     user => $hdl_user,
       
   164     #     require => File['/etc/sysconfig/handle']
       
   165     # }->
       
   166     # exec { "handle-first-stop":
       
   167     #     command => "/usr/bin/sleep 10 && rm -f /var/lib/handle/delete_this_to_stop_server && touch /var/lib/handle/.handle_initialized",
       
   168     #     provider => 'shell',
       
   169     #     creates => "/var/lib/handle/.handle_initialized",
       
   170     #     user => $hdl_user,
       
   171     #     require => File['/etc/sysconfig/handle']
       
   172     # }#->
       
   173     # file_line { "handle-detached-prefix":
       
   174     #     path => "/var/lib/handle/config.dct",
       
   175     #     match => "\s*\"300:0.NA/$hdl_prefix\"",
       
   176     #     line => "      \"300:$hdl_prefix/ADMIN\"",
       
   177     #     multiple => true,
       
   178     # }
       
   179 
   166 
   180 
   167 
   181     file { "/etc/sysconfig/handle":
   168     file { "/etc/sysconfig/handle":
   182         ensure => file,
   169         ensure => file,
   183         owner => "root",
   170         owner => "root",
   199         command => "/usr/bin/systemctl enable handle",
   186         command => "/usr/bin/systemctl enable handle",
   200         subscribe => [ Exec['systemctl-daemon-reload'], File['/etc/systemd/system/handle.service'] ],
   187         subscribe => [ Exec['systemctl-daemon-reload'], File['/etc/systemd/system/handle.service'] ],
   201         unless => "/usr/bin/systemctl is-enabled handle.service"
   188         unless => "/usr/bin/systemctl is-enabled handle.service"
   202     }
   189     }
   203 
   190 
   204     # exec { "rm-tmp-handle":
       
   205     #     command => "/usr/bin/rm /tmp/handle/handle_answers.txt",
       
   206     #     refreshonly => true
       
   207     # }
       
   208 
       
   209     exec { "rm-tmp-handle":
   191     exec { "rm-tmp-handle":
   210         command => "/usr/bin/rm /tmp/handle/handle_init_script.exp",
   192         command => "/usr/bin/rm -f /tmp/handle/handle_init_script.exp",
   211         refreshonly => true
   193         refreshonly => true
   212     }
   194     }
   213 
   195 
   214     exec { "rm-tmp-handle-db":
   196     exec { "rm-tmp-handle-db":
   215         command => "/usr/bin/rm /tmp/handle/handle_db.sql",
   197         command => "/usr/bin/rm -f /tmp/handle/handle_db.sql",
       
   198         refreshonly => true
       
   199     }
       
   200 
       
   201     exec { "rm-tmp-handle-data":
       
   202         command => "/usr/bin/rm -f /tmp/handle/handle_data.sql.sh /tmp/handle/handle_data.sql",
       
   203         refreshonly => true
       
   204     }
       
   205 
       
   206     exec { "rm-tmp-handle-corpus-admin-key":
       
   207         command => "/usr/bin/rm -f /tmp/handle/handle_script_corpus_admin_keys.exp",
   216         refreshonly => true
   208         refreshonly => true
   217     }
   209     }
   218 
   210 
   219     exec { "open-handle-web-port":
   211     exec { "open-handle-web-port":
   220         command => "firewall-cmd --permanent --add-port=8000/tcp",
   212         command => "firewall-cmd --permanent --add-port=8000/tcp",