/files/gitlab-cookbooks/gitlab/recipes/gitlab-shell.rb

https://gitlab.com/ruvasik/omnibus-gitlab · Ruby · 121 lines · 86 code · 10 blank · 25 comment · 2 complexity · b64efb1f5eb84207521f8dd0bfec0756 MD5 · raw file

  1. #
  2. ## Copyright:: Copyright (c) 2014 GitLab.com
  3. ## License:: Apache License, Version 2.0
  4. ##
  5. ## Licensed under the Apache License, Version 2.0 (the "License");
  6. ## you may not use this file except in compliance with the License.
  7. ## You may obtain a copy of the License at
  8. ##
  9. ## http://www.apache.org/licenses/LICENSE-2.0
  10. ##
  11. ## Unless required by applicable law or agreed to in writing, software
  12. ## distributed under the License is distributed on an "AS IS" BASIS,
  13. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ## See the License for the specific language governing permissions and
  15. ## limitations under the License.
  16. ##
  17. #
  18. account_helper = AccountHelper.new(node)
  19. git_user = account_helper.gitlab_user
  20. git_group = account_helper.gitlab_group
  21. gitlab_shell_dir = "/opt/gitlab/embedded/service/gitlab-shell"
  22. gitlab_shell_var_dir = "/var/opt/gitlab/gitlab-shell"
  23. git_data_directories = node['gitlab']['gitlab-shell']['git_data_directories']
  24. repositories_storages = node['gitlab']['gitlab-rails']['repositories_storages']
  25. ssh_dir = File.join(node['gitlab']['user']['home'], ".ssh")
  26. authorized_keys = File.join(ssh_dir, "authorized_keys")
  27. log_directory = node['gitlab']['gitlab-shell']['log_directory']
  28. hooks_directory = node['gitlab']['gitlab-rails']['gitlab_shell_hooks_path']
  29. if node['gitlab']['manage-storage-directories']['enable']
  30. git_data_directories.each do |_name, git_data_directory|
  31. directory git_data_directory do
  32. owner git_user
  33. mode "0700"
  34. recursive true
  35. end
  36. end
  37. repositories_storages.each do |_name, repositories_storage|
  38. directory repositories_storage do
  39. owner git_user
  40. mode "2770"
  41. recursive true
  42. end
  43. end
  44. end
  45. directory ssh_dir do
  46. owner git_user
  47. group git_group
  48. mode "0700"
  49. recursive true
  50. end
  51. # All repositories under GitLab share one hooks directory under
  52. # /opt/gitlab. Git-Annex wants write access to this hook directory, but
  53. # this directory is owned by root in the package.
  54. directory hooks_directory do
  55. owner git_user
  56. group git_group
  57. mode "0755"
  58. end
  59. # If SELinux is enabled, make sure that OpenSSH thinks the .ssh directory of the
  60. # git_user is valid.
  61. execute "chcon --recursive --type ssh_home_t #{ssh_dir}" do
  62. only_if "id -Z"
  63. end
  64. [
  65. log_directory,
  66. gitlab_shell_var_dir
  67. ].each do |dir|
  68. directory dir do
  69. owner git_user
  70. mode "0700"
  71. recursive true
  72. end
  73. end
  74. # If no internal_api_url is specified, default to the IP/port Unicorn listens on
  75. api_url = node['gitlab']['gitlab-rails']['internal_api_url']
  76. api_url ||= "http://#{node['gitlab']['unicorn']['listen']}:#{node['gitlab']['unicorn']['port']}#{node['gitlab']['unicorn']['relative_url']}"
  77. redis_port = node['gitlab']['gitlab-rails']['redis_port']
  78. if redis_port
  79. # Leave out redis socket setting because in gitlab-shell, setting a Redis socket
  80. # overrides TCP connection settings.
  81. redis_socket = nil
  82. else
  83. redis_socket = node['gitlab']['gitlab-rails']['redis_socket']
  84. end
  85. template_symlink File.join(gitlab_shell_var_dir, "config.yml") do
  86. link_from File.join(gitlab_shell_dir, "config.yml")
  87. source "gitlab-shell-config.yml.erb"
  88. variables(
  89. :user => git_user,
  90. :api_url => api_url,
  91. :authorized_keys => authorized_keys,
  92. :redis_host => node['gitlab']['gitlab-rails']['redis_host'],
  93. :redis_port => redis_port,
  94. :redis_socket => redis_socket,
  95. :redis_password => node['gitlab']['gitlab-rails']['redis_password'],
  96. :redis_database => node['gitlab']['gitlab-rails']['redis_database'],
  97. :log_file => File.join(log_directory, "gitlab-shell.log"),
  98. :log_level => node['gitlab']['gitlab-shell']['log_level'],
  99. :audit_usernames => node['gitlab']['gitlab-shell']['audit_usernames'],
  100. :http_settings => node['gitlab']['gitlab-shell']['http_settings'],
  101. :git_annex_enabled => node['gitlab']['gitlab-shell']['git_annex_enabled']
  102. )
  103. end
  104. template_symlink File.join(gitlab_shell_var_dir, "gitlab_shell_secret") do
  105. link_from File.join(gitlab_shell_dir, ".gitlab_shell_secret")
  106. source "secret_token.erb"
  107. owner "root"
  108. group "root"
  109. mode "0644"
  110. variables(node['gitlab']['gitlab-shell'].to_hash)
  111. end