18870: Run diagnostics
[arvados.git] / tools / salt-install / installer.sh
1 #!/bin/bash
2
3 # Copyright (C) The Arvados Authors. All rights reserved.
4 #
5 # SPDX-License-Identifier: CC-BY-SA-3.0
6
7 set -e
8
9 sync() {
10     if test "$NODE" != localhost ; then
11         if ! ssh $NODE test -d arvados-setup ; then
12             ssh $NODE git init --bare arvados-setup.git
13             if ! git remote add $NODE $DEPLOY_USER@$NODE:arvados-setup.git ; then
14                 git remote set-url $NODE $DEPLOY_USER@$NODE:arvados-setup.git
15             fi
16             git push $NODE $BRANCH
17             ssh $NODE git clone arvados-setup.git arvados-setup
18         fi
19
20         git push $NODE $BRANCH
21         ssh $NODE git -C arvados-setup checkout $BRANCH
22         ssh $NODE git -C arvados-setup pull
23     fi
24 }
25
26 deploynode() {
27     if test -z "${NODES[$NODE]}" ; then
28         echo "No roles declared for '$NODE' in local.params"
29         exit 1
30     fi
31
32     if test $NODE = localhost ; then
33         sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}
34     else
35         ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
36     fi
37 }
38
39 loadconfig() {
40     CONFIG_FILE=local.params
41     if ! test -s $CONFIG_FILE ; then
42         echo "Must be run from arvados-setup, maybe you need to 'initialize' first?"
43     fi
44     source ${CONFIG_FILE}
45 }
46
47 subcmd="$1"
48 if test -n "$subcmd" ; then
49     shift
50 fi
51 case "$subcmd" in
52     initialize)
53         if ! test -f provision.sh ; then
54             echo "Must be run from arvados/tools/salt-install"
55             exit
56         fi
57
58         SETUPDIR=$1
59         PARAMS=$2
60         SLS=$3
61
62         err=
63         if test -z "$PARAMS" -o ! -f local.params.example.$PARAMS ; then
64             echo "Not found: local.params.example.$PARAMS"
65             echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
66             err=1
67         fi
68
69         if test -z "$SLS" -o ! -d config_examples/$SLS ; then
70             echo "Not found: config_examples/$SLS"
71             echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
72             err=1
73         fi
74
75         if test -z "$SETUPDIR" -o -z "$PARAMS" -o -z "$SLS" ; then
76             echo "installer.sh <setup dir to initialize> <params template> <config template>"
77             err=1
78         fi
79
80         if test -n "$err" ; then
81             exit 1
82         fi
83
84         echo "Initializing $SETUPDIR"
85         git init $SETUPDIR
86         cp -r *.sh tests $SETUPDIR
87
88         cp local.params.example.$PARAMS $SETUPDIR/local.params
89         cp -r config_examples/$SLS $SETUPDIR/local_config_dir
90
91         cd $SETUPDIR
92         git add *.sh local.params local_config_dir tests
93         git commit -m"initial commit"
94
95         echo "setup directory initialized, now go to $SETUPDIR, edit 'local.params' and 'local_config_dir' as needed, then run 'installer.sh deploy'"
96         ;;
97     deploy)
98         NODE=$1
99
100         loadconfig
101
102         set -x
103
104         BRANCH=$(git branch --show-current)
105
106         git add -A
107         if ! git diff --cached --exit-code ; then
108             git commit -m"prepare for deploy"
109         fi
110
111         if test -z "$NODE"; then
112             for NODE in "${!NODES[@]}"
113             do
114                 sync
115                 deploynode
116             done
117         else
118             sync
119             deploynode
120         fi
121
122         ;;
123     diagnostics)
124         loadconfig
125
126         if ! which arvados-client ; then
127             apt-get install arvados-client
128         fi
129
130         export ARVADOS_API_HOST="${CONTROLLER_INT_IP}"
131         export ARVADOS_API_TOKEN="$SYSTEM_ROOT_TOKEN"
132
133         arvados-client diagnostics -internal-client
134     *)
135         echo "Arvados installer"
136         echo ""
137         echo "initialize   initialize the setup directory for configuration"
138         echo "deploy       deploy the configuration from the setup directory"
139         ;;
140 esac