summarylogtreecommitdiffstats
path: root/gitlab.install
blob: b941f4394c207791d690f88bdb02acca212c3315 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
_datadir=/usr/share/webapps/gitlab
_homedir=/var/lib/gitlab
_etcdir=/etc/webapps/gitlab


fix_perms() {
	chown -R gitlab:gitlab "${_datadir}" "${_homedir}"
	chmod 770 "${_homedir}/satellites"
	chown root:gitlab "${_etcdir}/secret"
	chmod 640 "${_etcdir}/secret"
}

pids_dir() {
	systemd-tmpfiles --create gitlab.conf
}

generate_secret() {
	if [ ! -s "${_etcdir}/secret" ]; then
		hexdump -v -n 64 -e '1/1 "%02x"' /dev/urandom > "${_etcdir}/secret"
	fi
}

post_install() {
	pids_dir
	generate_secret
	fix_perms
	echo "You have to configure few things."
	echo "Configure gitlab-shell in /etc/webapps/gitlab-shell/config.yml"
	echo "Configure the application database in ${_etcdir}/database.yml and run:"
	echo "# su - gitlab -s /bin/sh -c \"cd '${_datadir}'; bundle-2.1 exec rake gitlab:setup RAILS_ENV=production\""
	echo "Compile Assets:"
	echo "# su - gitlab -s /bin/sh -c \"cd '${_datadir}'; bundle-2.1 exec rake assets:precompile RAILS_ENV=production\""
	echo "Check that ${_etcdir}/secret contains a random hex string."
}

pre_upgrade() {
	echo "Stopping gitlab-unicorn & gitlab-sidekiq services, check them after update !"
	if [[ `systemctl is-active gitlab-unicorn` == 'active' ]]; then
		touch /tmp/gitlab-upgrade-unicorn
		systemctl stop gitlab-unicorn
	fi
	if [[ `systemctl is-active gitlab-sidekiq` == 'active' ]]; then
		touch /tmp/gitlab-upgrade-sidekiq
		systemctl stop gitlab-sidekiq
	fi

	fix_perms
	cd "${_datadir}"
	sudo -u gitlab -H bundle-2.1 exec rake gitlab:backup:create RAILS_ENV=production
	if [ \( -e "${_datadir}/log" \) -a \( ! -L "${_datadir}/log" \) ]; then
		mv "${_datadir}/log" "${_datadir}/log.bck"
	fi
	if [ \( -e "${_datadir}/tmp" \) -a \( ! -L "${_datadir}/tmp" \) ]; then
		mv "${_datadir}/tmp" "${_datadir}/tmp.bck"
	fi

	if [ ! -s "${_etcdir}/secret" ]; then
		if [ \( -s ${_datadir}/.secret \) -a \( ! -L ${_datadir}/.secret \) ]; then
			mv "${_datadir}/.secret" "${_etcdir}/secret"
		else
			rm -f "${_datadir}/.secret"
		fi
	fi
	if [ \( ! -L "${_datadir}/.gitlab_shell_secret" \) -a \( -s "${_datadir}/.gitlab_shell_secret" \) ]; then
		mv "${_datadir}/.gitlab_shell_secret" "${_datadir}/.gitlab_shell_secret.pacsave"
	else
		rm -f "${_datadir}/.gitlab_shell_secret"
	fi

	if [ \( -e "${_datadir}/builds" \) -a \( ! -L "${_datadir}/builds" \) -a \( ! -e "${_homedir}/builds" \) ]; then
		mv "${_datadir}/builds" "${_homedir}/builds"
	fi
}

post_upgrade() {
	pids_dir
	generate_secret
	fix_perms

	su - gitlab -s /bin/sh -c "cd '${_datadir}'; bundle-2.1 exec rake db:migrate RAILS_ENV=production"
	su - gitlab -s /bin/sh -c "cd '${_datadir}'; bundle-2.1 exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production"

	systemctl daemon-reload
	if [ -e /tmp/gitlab-upgrade-unicorn ]; then
		systemctl start gitlab-unicorn
		rm /tmp/gitlab-upgrade-unicorn
	fi
	if [ -e /tmp/gitlab-upgrade-sidekiq ]; then
		systemctl start gitlab-sidekiq
		rm /tmp/gitlab-upgrade-sidekiq
	fi
}