From a2472663576271bf1699c4e6081dd3932ea4bbc0 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Thu, 9 Jan 2014 10:06:42 +0000 Subject: [PATCH 1/2] create a document, on moving the git home directory for gitlab --- misc/homedir-move/README.md | 237 ++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 misc/homedir-move/README.md diff --git a/misc/homedir-move/README.md b/misc/homedir-move/README.md new file mode 100644 index 0000000..7a47e1a --- /dev/null +++ b/misc/homedir-move/README.md @@ -0,0 +1,237 @@ +# Move home directory from /home/git to /var/lib/git + +### 0. Stop services + +```bash +service gitlab stop +service nginx stop +``` + +### 1. Update passwd/group file + +Update the `/etc/group` file, and change the gid of the group + +```bash +git:x:500: +``` +or you can run the following command + +```bash +groupmod -g 500 git +``` + +Amended the `/etc/passwd` file to change the uid, gid and the home directory for git + +```bash +git:x:500:500:GitLab,,,:/var/lib/git:/bin/bash +``` +or you can run the following command + +```bash +usermod -d /var/lib/git -g 500 -u 500 git +``` + +### 2. Move the git folder + +```bash +mv /home/git /var/lib/ +``` + +### 3. Change permissions to use the new uid/gid + +```bash +chown -R git:git /var/lib/git +``` + +### 4. Update Gitlab config files +update `~git/gitlab/config/gitlab.yml`, using the following command + +```bash +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab/config/gitlab.yml +``` + +You should see the following difference after running the command + +```diff +--- gitlab.yml.example 2013-12-20 16:27:14.784403409 -0500 ++++ gitlab.yml 2014-01-05 15:11:17.706013229 -0500 +@@ -165,7 +166,7 @@ + # GitLab Satellites + satellites: + # Relative paths are relative to Rails.root (default: tmp/repo_satellites/) +- path: /home/git/gitlab-satellites/ ++ path: /var/lib/git/gitlab-satellites/ + + ## Backup +@@ -174,11 +175,11 @@ + + ## GitLab Shell settings + gitlab_shell: +- path: /home/git/gitlab-shell/ ++ path: /var/lib/git/gitlab-shell/ + + # REPOS_PATH MUST NOT BE A SYMLINK!!! +- repos_path: /home/git/repositories/ +- hooks_path: /home/git/gitlab-shell/hooks/ ++ repos_path: /var/lib/git/repositories/ ++ hooks_path: /var/lib/git/gitlab-shell/hooks/ + + # Git over HTTP + upload_pack: true +``` +Update `~git/gitlab/config/unicorb.rb`, using the following command + +```bash +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab/config/unicorn.rb +``` + +You should see the following difference after running the command + +```diff +--- unicorn.rb.example 2013-12-20 16:27:14.795402739 -0500 ++++ unicorn.rb 2014-01-07 07:47:33.786389865 -0500 +@@ -32,24 +32,24 @@ + + # Help ensure your application will always spawn in the symlinked + # "current" directory that Capistrano sets up. +-working_directory "/home/git/gitlab" # available in 0.94.0+ ++working_directory "/var/lib/git/gitlab" # available in 0.94.0+ + + # listen on both a Unix domain socket and a TCP port, + # we use a shorter backlog for quicker failover when busy +-listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64 ++listen "/var/lib/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64 + listen "127.0.0.1:8080", :tcp_nopush => true + + # nuke workers after 30 seconds instead of 60 seconds (the default) + timeout 30 + + # feel free to point this anywhere accessible on the filesystem +-pid "/home/git/gitlab/tmp/pids/unicorn.pid" ++pid "/var/lib/git/gitlab/tmp/pids/unicorn.pid" + + # By default, the Unicorn logger will write to stderr. + # Additionally, some applications/frameworks log to stderr or stdout, + # so prevent them from going to /dev/null when daemonized here: +-stderr_path "/home/git/gitlab/log/unicorn.stderr.log" +-stdout_path "/home/git/gitlab/log/unicorn.stdout.log" ++stderr_path "/var/lib/git/gitlab/log/unicorn.stderr.log" ++stdout_path "/var/lib/git/gitlab/log/unicorn.stdout.log" + + # combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings + # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow +``` + +### 5. Update Gitlab shell config file +update `~git/gitlab-shell/config.yml`, using the following command + +```bash +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab-shell/config.yml +``` + +You should see the following difference after running the command + +```diff +--- config.yml.old 2014-01-07 09:00:41.522352570 -0500 ++++ config.yml 2014-01-05 15:12:59.695840545 -0500 +@@ -15,10 +15,10 @@ + # Give the canonicalized absolute pathname, + # REPOS_PATH MUST NOT CONTAIN ANY SYMLINK!!! + # Check twice that none of the components is a symlink, including "/home". +-repos_path: "/home/git/repositories" ++repos_path: "/var/lib/git/repositories" + + # File used as authorized_keys for gitlab user +-auth_file: "/home/git/.ssh/authorized_keys" ++auth_file: "/var/lib/git/.ssh/authorized_keys" + + # Redis settings used for pushing commit notices to gitlab + redis: +``` + +### 6. Update authorized_keys + +Update the `/var/lib/git/.ssh/authorized_keys`, using the following command + +```bash +sed -i -e 's/\/home/\/var\/lib/g' ~git/.ssh/authorized_keys +``` + +### 7. Update nginx config file + +update `/etc/nginx/sites-enabled/gitlab`, using the following command + +```bash +sed -i -e 's/\/home/\/var\/lib/g' /etc/nginx/sites-enabled/gitlab +``` + +### 8. Add/Update gitlab service and default files + +We need to apply the following patch to `/etc/init.d/gitlab`, This has been submitted as a +PR already to gitlabhq. This enables to read the default file, and initialises other variables. +Without this diff, other variables then also need to be defined in `/etc/default/gitlab` + +```diff +--- gitlab 2013-12-20 16:27:14.919395198 -0500 ++++ /etc/init.d/gitlab 2014-01-06 08:51:18.253120785 -0500 +@@ -31,14 +31,15 @@ + # internal /bin/sh variables such as PATH, EDITOR or SHELL. + app_user="git" + app_root="/home/$app_user/gitlab" ++ ++# Read configuration variable file if it is present ++test -f /etc/default/gitlab && . /etc/default/gitlab ++ + pid_path="$app_root/tmp/pids" + socket_path="$app_root/tmp/sockets" + web_server_pid_path="$pid_path/unicorn.pid" + sidekiq_pid_path="$pid_path/sidekiq.pid" + +-# Read configuration variable file if it is present +-test -f /etc/default/gitlab && . /etc/default/gitlab +- + # Switch to the app_user if it is not he/she who is running the script. + if [ "$USER" != "$app_user" ]; then + sudo -u "$app_user" -H -i $0 "$@"; exit; +``` + +If you haven't already, copy the service default file, then do so, and then update the file to point to the new home directory + +```bash +cp ~git/gitlab/lib/support/init.d/gitlab.default.example /etc/default/gitlab +sed -i -e 's/\/home/\/var\/lib/g' /etc/default/gitlab +``` + +### 9. Update gitlab-shell hooks + +The file `~git/gitlab-shell/support/rewrite-hooks.sh`, has the home directory hardcoded, so we need to update this file as well + +```bash +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab-shell/support/rewrite-hooks.sh +``` + +Now we update all the hooks + +```bash +cd ~git +sudo -u git -H gitlab-shell/support/rewrite-hooks.sh +``` + +### 10. Restart application + +```bash +sudo service gitlab restart +sudo service nginx restart +``` + +### 11. Check application status + +Check if GitLab and its environment are configured correctly: + + cd ~git/gitlab + sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production + +To make sure you didn't miss anything run a more thorough check with: + + cd ~git/gitlab + sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production From 37a318c3290bfb581beb7d673b3ca09e5205f7dc Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Fri, 10 Jan 2014 10:16:30 +0000 Subject: [PATCH 2/2] add backup, and removal of backup is successful --- misc/{homedir-move/README.md => homedir/movedir.md} | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) rename misc/{homedir-move/README.md => homedir/movedir.md} (97%) diff --git a/misc/homedir-move/README.md b/misc/homedir/movedir.md similarity index 97% rename from misc/homedir-move/README.md rename to misc/homedir/movedir.md index 7a47e1a..ed3be3d 100644 --- a/misc/homedir-move/README.md +++ b/misc/homedir/movedir.md @@ -34,7 +34,7 @@ usermod -d /var/lib/git -g 500 -u 500 git ### 2. Move the git folder ```bash -mv /home/git /var/lib/ +cp -r /home/git /var/lib/ ``` ### 3. Change permissions to use the new uid/gid @@ -235,3 +235,9 @@ To make sure you didn't miss anything run a more thorough check with: cd ~git/gitlab sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production + +### 12. Remove old home + +Once you are happy that everything is now working in the new directory, you can remove the old `/home/git` + + rm -rf /home/git