summarylogtreecommitdiffstats
path: root/gitlab-ci.install
blob: cc873e27d6ae5f9baf46d6cac49e77cda40f9a52 (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
_datadir=/usr/share/webapps/gitlab-ci
_etcdir=/etc/webapps/gitlab-ci

fix_perms() {
	chown -R gitlab_ci "${_datadir}/tmp"
	chown -R gitlab_ci:gitlab /run/gitlab-ci
	chmod -R u+rwX "${_datadir}/tmp"
	chmod 755 /run/gitlab-ci
	# Rails needs to create a token file called .secret into datadir
	chown -R gitlab_ci:gitlab "${_datadir}"
}

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

post_install() {
	groupadd gitlab &>/dev/null
	useradd -m -g gitlab -G users -s /bin/false gitlab_ci
	pids_dir
	fix_perms
	echo "You have to configure the database."
	echo "Configure the application database in ${_etcdir}/database.yml and run:"
	echo "# su - gitlab_ci -s /bin/sh -c \"cd ${_datadir}; bundle-2.1 exec rake setup RAILS_ENV=production\""
	echo "# su - gitlab_ci -s /bin/sh -c \"cd ${_datadir}; bundle-2.1 exec whenever -w RAILS_ENV=production\""
	echo "Configure the application in ${_etcdir}/application.yml"
}

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

	fix_perms
}

post_upgrade() {
	getent group gitlab >/dev/null 2>&1 || groupadd gitlab &>/dev/null
	getent passwd gitlab_ci >/dev/null 2>&1 || useradd -m -g gitlab -G users -s /bin/false gitlab_ci &>/dev/null
	pids_dir
	fix_perms

	su - gitlab_ci -s /bin/sh -c "cd '${_datadir}'; bundle-2.1 exec rake db:migrate RAILS_ENV=production"

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

post_remove() {
	if getent passwd gitlab_ci > /dev/null 2>&1; then
		userdel gitlab_ci
	fi
}