<commit_before>#
# Cookbook Name:: glassfish
# Recipe:: default
#
# Copyright 2011, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

action :create do
  requires_authbind = new_resource.port < 1024

  instance_dir = "#{new_resource.var_home}/instances/#{new_resource.instance}"

  directory new_resource.var_home do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  directory "#{new_resource.var_home}/instances" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  directory instance_dir do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  directory "#{instance_dir}/etc" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  directory "#{instance_dir}/log" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  # Not sure why this is required... but something runs service as root which created this file as root owned
  file "#{instance_dir}/log/log.txt" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
    action :touch
  end

  directory "#{instance_dir}/props" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  vm_args = []
  vm_args << "-Xmx#{new_resource.max_memory}m"
  vm_args << "-Xss#{new_resource.max_stack_size}k"
  vm_args << "-Djava.util.logging.config.file=#{instance_dir}/etc/logging.properties"
  if new_resource.jmx_port
    vm_args << "-Dcom.sun.management.jmxremote"
    vm_args << "-Dcom.sun.management.jmxremote.port=#{new_resource.jmx_port}"
    vm_args << "-Dcom.sun.management.jmxremote.access.file=#{instance_dir}/etc/jmxremote.access"
    vm_args << "-Dcom.sun.management.jmxremote.password.file=#{instance_dir}/etc/jmxremote.password"
    vm_args << "-Dcom.sun.management.jmxremote.ssl=false"
  end

  template "/etc/init/omq-#{new_resource.instance}.conf" do
    source "omq-upstart.conf.erb"
    mode "0644"
    cookbook 'glassfish'

    variables(:resource => new_resource,
              :authbind => requires_authbind,
              :vmargs => vm_args.join(" "))
  end
<commit_msg>Specify modes as strings for consistencies sake<commit_after>#
# Cookbook Name:: glassfish
# Recipe:: default
#
# Copyright 2011, <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

action :create do
  requires_authbind = new_resource.port < 1024

  instance_dir = "#{new_resource.var_home}/instances/#{new_resource.instance}"

  directory new_resource.var_home do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode 0700
  end

  directory "#{new_resource.var_home}/instances" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode "0700"
  end

  directory instance_dir do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode "0700"
  end

  directory "#{instance_dir}/etc" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode "0700"
  end

  directory "#{instance_dir}/log" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode "0700"
  end

  # Not sure why this is required... but something runs service as root which created this file as root owned
  file "#{instance_dir}/log/log.txt" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode "0700"
    action :touch
  end

  directory "#{instance_dir}/props" do
    owner node[:glassfish][:user]
    group node[:glassfish][:group]
    mode "0700"
  end

  vm_args = []
  vm_args << "-Xmx#{new_resource.max_memory}m"
  vm_args << "-Xss#{new_resource.max_stack_size}k"
  vm_args << "-Djava.util.logging.config.file=#{instance_dir}/etc/logging.properties"
  if new_resource.jmx_port
    vm_args << "-Dcom.sun.management.jmxremote"
    vm_args << "-Dcom.sun.management.jmxremote.port=#{new_resource.jmx_port}"
    vm_args << "-Dcom.sun.management.jmxremote.access.file=#{instance_dir}/etc/jmxremote.access"
    vm_args << "-Dcom.sun.management.jmxremote.password.file=#{instance_dir}/etc/jmxremote.password"
    vm_args << "-Dcom.sun.management.jmxremote.ssl=false"
  end

  template "/etc/init/omq-#{new_resource.instance}.conf" do
    source "omq-upstart.conf.erb"
    mode "0644"
    cookbook 'glassfish'

    variables(:resource => new_resource,
              :authbind => requires_authbind,
              :vmargs => vm_args.join(" "))
  end

{'fraction_non_alphanumeric': 0.12422360248447205, 'fraction_numerical': 0.01607599561563756, 'mean_word_length': 3.858030168589175, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1405242', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1744, 'n_words': 450}