<commit_before>

###
Mysql Server
------------

###
mecano = require 'mecano'
each = require 'each'
module.exports = []
escape = (text) -> text.replace(/[\\"]/g, "\\$&")

# Install the mysql driver
module.exports.push 'phyla/core/yum'
module.exports.push 'phyla/tools/mysql_client'

###
Configure
---------
###
module.exports.push module.exports.configure = (ctx) ->
  ctx.config.mysql_server ?= {}
  ctx.config.mysql_server.sql_on_install ?= []
  ctx.config.mysql_server.sql_on_install = [ctx.config.mysql_server.sql_on_install] if typeof ctx.config.mysql_server.sql_on_install is 'string'
  ctx.config.mysql_server.current_password ?= ''
  ctx.config.mysql_server.port ?= '3306'
  ctx.config.mysql_server.username ?= 'root'
  ctx.config.mysql_server.password ?= ''
  ctx.config.mysql_server.remove_anonymous ?= true
  ctx.config.mysql_server.disallow_remote_root_login ?= false
  ctx.config.mysql_server.remove_test_db ?= true
  ctx.config.mysql_server.reload_privileges ?= true

###
Package
-------
Install the Mysql database server. Secure the temporary directory.
###
module.exports.push name: 'Mysql Server # Package', timeout: -1, callback: (ctx, next) ->
  modified = false
  do_install = ->
    ctx.service
      name: 'mysql-server'
      chk_name: 'mysqld'
      startup: '235'
      # action: 'start'
    , (err, serviced) ->
      return next err if err
      modified = true if serviced
      do_tmp()
  do_tmp = ->
    ctx.mkdir
      destination: '/tmp/mysql'
      uid: 'mysql'
      gid: 'mysql'
      mode: '0744'
    , (err, created) ->
      return next err if err
      modified = true if created
      ctx.ini
        destination: '/etc/my.cnf'
        content: mysqld: tmpdir: '/tmp/mysql'
        merge: true
        backup: true
      , (err, updated) ->
        return next err if err
        modified = true if updated
        do_end()
  # do_socket = ->
  #   # Create the socket inside "/tmp" instead of default "/var/lib/mysql/mysql.sock". That
  #   # way, on restart, there won't be any existing file preventing the mysql server to start
  #   ctx.ini
  #     destination: '/etc/my.cnf'
  #     content: mysqld: socket: '/tmp/mysql/mysql.sock'
  #     merge: true
  #     backup: true
  #   , (err, updated) ->
  #     return next err if err
  #     modified = true if updated
  #     ctx.link
  #       source: '/tmp/mysql/mysql.sock'
  #       destination: '/var/lib/mysql/mysql.sock'
  #     , (err, linked) ->
  #       modified = true if linked
  #       do_start()
  do_end = ->
    next null, if modified then ctx.OK else ctx.PASS<commit_msg>Add my_cnf support<commit_after>

###
Mysql Server
------------

###
mecano = require 'mecano'
each = require 'each'
module.exports = []
escape = (text) -> text.replace(/[\\"]/g, "\\$&")

# Install the mysql driver
module.exports.push 'phyla/core/yum'
module.exports.push 'phyla/tools/mysql_client'

###
Configure
---------
###
module.exports.push module.exports.configure = (ctx) ->
  ctx.config.mysql_server ?= {}
  ctx.config.mysql_server.sql_on_install ?= []
  ctx.config.mysql_server.sql_on_install = [ctx.config.mysql_server.sql_on_install] if typeof ctx.config.mysql_server.sql_on_install is 'string'
  ctx.config.mysql_server.current_password ?= ''
  ctx.config.mysql_server.port ?= '3306'
  ctx.config.mysql_server.username ?= 'root'
  ctx.config.mysql_server.password ?= ''
  ctx.config.mysql_server.remove_anonymous ?= true
  ctx.config.mysql_server.disallow_remote_root_login ?= false
  ctx.config.mysql_server.remove_test_db ?= true
  ctx.config.mysql_server.reload_privileges ?= true
  # /etc/my.cnf
  ctx.config.mysql_server.my_cnf ?= {}
  ctx.config.mysql_server.my_cnf['mysqld'] ?= {}
  ctx.config.mysql_server.my_cnf['mysqld']['tmpdir'] ?= '/tmp/mysql'

###
Package
-------
Install the Mysql database server. Secure the temporary directory.
###
module.exports.push name: 'Mysql Server # Package', timeout: -1, callback: (ctx, next) ->
  {my_cnf} = ctx.config.mysql_server
  modified = false
  do_install = ->
    ctx.service
      name: 'mysql-server'
      chk_name: 'mysqld'
      startup: '235'
      # action: 'start'
    , (err, serviced) ->
      return next err if err
      modified = true if serviced
      do_tmp()
  do_tmp = ->
    ctx.mkdir
      destination: '/tmp/mysql'
      uid: 'mysql'
      gid: 'mysql'
      mode: '0744'
    , (err, created) ->
      return next err if err
      modified = true if created
      ctx.ini
        destination: '/etc/my.cnf'
        content: my_cnf
        merge: true
        backup: true
      , (err, updated) ->
        return next err if err
        modified = true if updated
        do_end()
  # do_socket = ->
  #   # Create the socket inside "/tmp" instead of default "/var/lib/mysql/mysql.sock". That
  #   # way, on restart, there won't be any existing file preventing the mysql server to start
  #   ctx.ini
  #     destination: '/etc/my.cnf'
  #     content: mysqld: socket: '/tmp/mysql/mysql.sock'
  #     merge: true
  #     backup: true
  #   , (err, updated) ->
  #     return next err if err
  #     modified = true if updated
  #     ctx.link
  #       source: '/tmp/mysql/mysql.sock'
  #       destination: '/var/lib/mysql/mysql.sock'
  #     , (err, linked) ->
  #       modified = true if linked
  #       do_start()
  do_end = ->
    next null, if modified then ctx.OK else ctx.PASS
{'fraction_non_alphanumeric': 0.1437371663244353, 'fraction_numerical': 0.00448011946985253, 'mean_word_length': 2.6032279757901815, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6406420', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1794, 'n_words': 416}