]> git.pld-linux.org Git - packages/gitlab-ce.git/blob - gitlab-ctl.sh
setup db backup and db upgrade on package upgrade
[packages/gitlab-ce.git] / gitlab-ctl.sh
1 #!/bin/sh
2 #
3 # gitlab-ctl implementing similar commands as gitlab omnibus package does
4 #
5 set -e
6
7 auto_migrations_skip_file=/etc/gitlab/skip-auto-migrations
8
9 die() {
10         cat >&2
11         exit 1
12 }
13
14 # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
15 upgrade() {
16         gitlab-rake db:migrate "$@"
17 }
18
19 # GitLab | Create a backup of the GitLab system
20 backup() {
21         gitlab-rake gitlab:backup:create "$@"
22 }
23
24 # http://docs.gitlab.com/ce/administration/restart_gitlab.html#installations-from-source
25 restart() {
26         :
27 }
28
29 # Run backup before package upgrade
30 # https://gitlab.com/gitlab-org/omnibus-gitlab/blob/8.8.1+ce.0/config/templates/package-scripts/preinst.erb#L10
31 preinst() {
32         if [ -f $auto_migrations_skip_file ]; then
33                 echo >&2 "Found $auto_migrations_skip_file, skipping auto backup..."
34                 return
35         fi
36
37         if ! backup SKIP=repositories,uploads,builds,artifacts,lfs,registry; then
38                 cat >&2 <<-EOF
39
40                 Backup failed! If you want to skip this backup, run the following command and try again:
41
42                 touch ${auto_migrations_skip_file}
43
44                 EOF
45                 exit 1
46         fi
47 }
48
49 # Run migrations after a package upgrade
50 # https://gitlab.com/gitlab-org/omnibus-gitlab/blob/8.8.1+ce.0/config/templates/package-scripts/posttrans.erb
51 # https://gitlab.com/gitlab-org/omnibus-gitlab/blob/8.8.1+ce.0/files/gitlab-ctl-commands/upgrade.rb
52 posttrans() {
53         upgrade
54
55         cat >&2 <<-EOF
56                 Upgrade complete!
57
58                 If you need to roll back to the previous version you can
59                 use the database backup made during the upgrade (scroll up for the filename).
60         EOF
61 }
62
63 case "$1" in
64 preinst)
65         preinst
66         ;;
67 posttrans)
68         posttrans
69         ;;
70 backup)
71         backup "$@"
72         ;;
73 upgrade)
74         upgrade
75         ;;
76 esac
This page took 0.036904 seconds and 4 git commands to generate.