|
| 1 | +# Move home directory from /home/git to /var/lib/git |
| 2 | + |
| 3 | +### 0. Stop services |
| 4 | + |
| 5 | +```bash |
| 6 | +service gitlab stop |
| 7 | +service nginx stop |
| 8 | +``` |
| 9 | + |
| 10 | +### 1. Update passwd/group file |
| 11 | + |
| 12 | +Update the `/etc/group` file, and change the gid of the group |
| 13 | + |
| 14 | +```bash |
| 15 | +git:x:500: |
| 16 | +``` |
| 17 | +or you can run the following command |
| 18 | + |
| 19 | +```bash |
| 20 | +groupmod -g 500 git |
| 21 | +``` |
| 22 | + |
| 23 | +Amended the `/etc/passwd` file to change the uid, gid and the home directory for git |
| 24 | + |
| 25 | +```bash |
| 26 | +git:x:500:500:GitLab,,,:/var/lib/git:/bin/bash |
| 27 | +``` |
| 28 | +or you can run the following command |
| 29 | + |
| 30 | +```bash |
| 31 | +usermod -d /var/lib/git -g 500 -u 500 git |
| 32 | +``` |
| 33 | + |
| 34 | +### 2. Move the git folder |
| 35 | + |
| 36 | +```bash |
| 37 | +cp -r /home/git /var/lib/ |
| 38 | +``` |
| 39 | + |
| 40 | +### 3. Change permissions to use the new uid/gid |
| 41 | + |
| 42 | +```bash |
| 43 | +chown -R git:git /var/lib/git |
| 44 | +``` |
| 45 | + |
| 46 | +### 4. Update Gitlab config files |
| 47 | +update `~git/gitlab/config/gitlab.yml`, using the following command |
| 48 | + |
| 49 | +```bash |
| 50 | +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab/config/gitlab.yml |
| 51 | +``` |
| 52 | + |
| 53 | +You should see the following difference after running the command |
| 54 | + |
| 55 | +```diff |
| 56 | +--- gitlab.yml.example 2013-12-20 16:27:14.784403409 -0500 |
| 57 | ++++ gitlab.yml 2014-01-05 15:11:17.706013229 -0500 |
| 58 | +@@ -165,7 +166,7 @@ |
| 59 | + # GitLab Satellites |
| 60 | + satellites: |
| 61 | + # Relative paths are relative to Rails.root (default: tmp/repo_satellites/) |
| 62 | +- path: /home/git/gitlab-satellites/ |
| 63 | ++ path: /var/lib/git/gitlab-satellites/ |
| 64 | + |
| 65 | + ## Backup |
| 66 | +@@ -174,11 +175,11 @@ |
| 67 | + |
| 68 | + ## GitLab Shell settings |
| 69 | + gitlab_shell: |
| 70 | +- path: /home/git/gitlab-shell/ |
| 71 | ++ path: /var/lib/git/gitlab-shell/ |
| 72 | + |
| 73 | + # REPOS_PATH MUST NOT BE A SYMLINK!!! |
| 74 | +- repos_path: /home/git/repositories/ |
| 75 | +- hooks_path: /home/git/gitlab-shell/hooks/ |
| 76 | ++ repos_path: /var/lib/git/repositories/ |
| 77 | ++ hooks_path: /var/lib/git/gitlab-shell/hooks/ |
| 78 | + |
| 79 | + # Git over HTTP |
| 80 | + upload_pack: true |
| 81 | +``` |
| 82 | +Update `~git/gitlab/config/unicorb.rb`, using the following command |
| 83 | + |
| 84 | +```bash |
| 85 | +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab/config/unicorn.rb |
| 86 | +``` |
| 87 | + |
| 88 | +You should see the following difference after running the command |
| 89 | + |
| 90 | +```diff |
| 91 | +--- unicorn.rb.example 2013-12-20 16:27:14.795402739 -0500 |
| 92 | ++++ unicorn.rb 2014-01-07 07:47:33.786389865 -0500 |
| 93 | +@@ -32,24 +32,24 @@ |
| 94 | + |
| 95 | + # Help ensure your application will always spawn in the symlinked |
| 96 | + # "current" directory that Capistrano sets up. |
| 97 | +-working_directory "/home/git/gitlab" # available in 0.94.0+ |
| 98 | ++working_directory "/var/lib/git/gitlab" # available in 0.94.0+ |
| 99 | + |
| 100 | + # listen on both a Unix domain socket and a TCP port, |
| 101 | + # we use a shorter backlog for quicker failover when busy |
| 102 | +-listen "/home/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64 |
| 103 | ++listen "/var/lib/git/gitlab/tmp/sockets/gitlab.socket", :backlog => 64 |
| 104 | + listen "127.0.0.1:8080", :tcp_nopush => true |
| 105 | + |
| 106 | + # nuke workers after 30 seconds instead of 60 seconds (the default) |
| 107 | + timeout 30 |
| 108 | + |
| 109 | + # feel free to point this anywhere accessible on the filesystem |
| 110 | +-pid "/home/git/gitlab/tmp/pids/unicorn.pid" |
| 111 | ++pid "/var/lib/git/gitlab/tmp/pids/unicorn.pid" |
| 112 | + |
| 113 | + # By default, the Unicorn logger will write to stderr. |
| 114 | + # Additionally, some applications/frameworks log to stderr or stdout, |
| 115 | + # so prevent them from going to /dev/null when daemonized here: |
| 116 | +-stderr_path "/home/git/gitlab/log/unicorn.stderr.log" |
| 117 | +-stdout_path "/home/git/gitlab/log/unicorn.stdout.log" |
| 118 | ++stderr_path "/var/lib/git/gitlab/log/unicorn.stderr.log" |
| 119 | ++stdout_path "/var/lib/git/gitlab/log/unicorn.stdout.log" |
| 120 | + |
| 121 | + # combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings |
| 122 | + # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow |
| 123 | +``` |
| 124 | + |
| 125 | +### 5. Update Gitlab shell config file |
| 126 | +update `~git/gitlab-shell/config.yml`, using the following command |
| 127 | + |
| 128 | +```bash |
| 129 | +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab-shell/config.yml |
| 130 | +``` |
| 131 | + |
| 132 | +You should see the following difference after running the command |
| 133 | + |
| 134 | +```diff |
| 135 | +--- config.yml.old 2014-01-07 09:00:41.522352570 -0500 |
| 136 | ++++ config.yml 2014-01-05 15:12:59.695840545 -0500 |
| 137 | +@@ -15,10 +15,10 @@ |
| 138 | + # Give the canonicalized absolute pathname, |
| 139 | + # REPOS_PATH MUST NOT CONTAIN ANY SYMLINK!!! |
| 140 | + # Check twice that none of the components is a symlink, including "/home". |
| 141 | +-repos_path: "/home/git/repositories" |
| 142 | ++repos_path: "/var/lib/git/repositories" |
| 143 | + |
| 144 | + # File used as authorized_keys for gitlab user |
| 145 | +-auth_file: "/home/git/.ssh/authorized_keys" |
| 146 | ++auth_file: "/var/lib/git/.ssh/authorized_keys" |
| 147 | + |
| 148 | + # Redis settings used for pushing commit notices to gitlab |
| 149 | + redis: |
| 150 | +``` |
| 151 | + |
| 152 | +### 6. Update authorized_keys |
| 153 | + |
| 154 | +Update the `/var/lib/git/.ssh/authorized_keys`, using the following command |
| 155 | + |
| 156 | +```bash |
| 157 | +sed -i -e 's/\/home/\/var\/lib/g' ~git/.ssh/authorized_keys |
| 158 | +``` |
| 159 | + |
| 160 | +### 7. Update nginx config file |
| 161 | + |
| 162 | +update `/etc/nginx/sites-enabled/gitlab`, using the following command |
| 163 | + |
| 164 | +```bash |
| 165 | +sed -i -e 's/\/home/\/var\/lib/g' /etc/nginx/sites-enabled/gitlab |
| 166 | +``` |
| 167 | + |
| 168 | +### 8. Add/Update gitlab service and default files |
| 169 | + |
| 170 | +We need to apply the following patch to `/etc/init.d/gitlab`, This has been submitted as a |
| 171 | +PR already to gitlabhq. This enables to read the default file, and initialises other variables. |
| 172 | +Without this diff, other variables then also need to be defined in `/etc/default/gitlab` |
| 173 | + |
| 174 | +```diff |
| 175 | +--- gitlab 2013-12-20 16:27:14.919395198 -0500 |
| 176 | ++++ /etc/init.d/gitlab 2014-01-06 08:51:18.253120785 -0500 |
| 177 | +@@ -31,14 +31,15 @@ |
| 178 | + # internal /bin/sh variables such as PATH, EDITOR or SHELL. |
| 179 | + app_user="git" |
| 180 | + app_root="/home/$app_user/gitlab" |
| 181 | ++ |
| 182 | ++# Read configuration variable file if it is present |
| 183 | ++test -f /etc/default/gitlab && . /etc/default/gitlab |
| 184 | ++ |
| 185 | + pid_path="$app_root/tmp/pids" |
| 186 | + socket_path="$app_root/tmp/sockets" |
| 187 | + web_server_pid_path="$pid_path/unicorn.pid" |
| 188 | + sidekiq_pid_path="$pid_path/sidekiq.pid" |
| 189 | + |
| 190 | +-# Read configuration variable file if it is present |
| 191 | +-test -f /etc/default/gitlab && . /etc/default/gitlab |
| 192 | +- |
| 193 | + # Switch to the app_user if it is not he/she who is running the script. |
| 194 | + if [ "$USER" != "$app_user" ]; then |
| 195 | + sudo -u "$app_user" -H -i $0 "$@"; exit; |
| 196 | +``` |
| 197 | + |
| 198 | +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 |
| 199 | + |
| 200 | +```bash |
| 201 | +cp ~git/gitlab/lib/support/init.d/gitlab.default.example /etc/default/gitlab |
| 202 | +sed -i -e 's/\/home/\/var\/lib/g' /etc/default/gitlab |
| 203 | +``` |
| 204 | + |
| 205 | +### 9. Update gitlab-shell hooks |
| 206 | + |
| 207 | +The file `~git/gitlab-shell/support/rewrite-hooks.sh`, has the home directory hardcoded, so we need to update this file as well |
| 208 | + |
| 209 | +```bash |
| 210 | +sed -i -e 's/\/home/\/var\/lib/g' ~git/gitlab-shell/support/rewrite-hooks.sh |
| 211 | +``` |
| 212 | + |
| 213 | +Now we update all the hooks |
| 214 | + |
| 215 | +```bash |
| 216 | +cd ~git |
| 217 | +sudo -u git -H gitlab-shell/support/rewrite-hooks.sh |
| 218 | +``` |
| 219 | + |
| 220 | +### 10. Restart application |
| 221 | + |
| 222 | +```bash |
| 223 | +sudo service gitlab restart |
| 224 | +sudo service nginx restart |
| 225 | +``` |
| 226 | + |
| 227 | +### 11. Check application status |
| 228 | + |
| 229 | +Check if GitLab and its environment are configured correctly: |
| 230 | + |
| 231 | + cd ~git/gitlab |
| 232 | + sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production |
| 233 | + |
| 234 | +To make sure you didn't miss anything run a more thorough check with: |
| 235 | + |
| 236 | + cd ~git/gitlab |
| 237 | + sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production |
| 238 | + |
| 239 | +### 12. Remove old home |
| 240 | + |
| 241 | +Once you are happy that everything is now working in the new directory, you can remove the old `/home/git` |
| 242 | + |
| 243 | + rm -rf /home/git |
0 commit comments