18870: Deploy individual nodes
[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 deploynode() {
10             if test $NODE = localhost ; then
11                 sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}
12             else
13                 if ! ssh $NODE test -d arvados-setup ; then
14                     ssh $NODE git init --bare arvados-setup.git
15                     if ! git remote add $NODE $DEPLOY_USER@$NODE:arvados-setup.git ; then
16                         git remote set-url $NODE $DEPLOY_USER@$NODE:arvados-setup.git
17                     fi
18                     git push $NODE $BRANCH
19                     ssh $NODE git clone arvados-setup.git arvados-setup
20                 fi
21
22                 git push $NODE $BRANCH
23                 ssh $NODE git -C arvados-setup checkout $BRANCH
24                 ssh $NODE git -C arvados-setup pull
25
26                 ssh $DEPLOY_USER@$NODE "cd arvados-setup && sudo ./provision.sh --config local.params --roles ${NODES[$NODE]}"
27             fi
28 }
29
30 subcmd="$1"
31 if test -n "$subcmd" ; then
32     shift
33 fi
34 case "$subcmd" in
35     initialize)
36         if ! test -f provision.sh ; then
37             echo "Must be run from arvados/tools/salt-install"
38             exit
39         fi
40
41         SETUPDIR=$1
42         PARAMS=$2
43         SLS=$3
44
45         err=
46         if test -z "$PARAMS" -o ! -f local.params.example.$PARAMS ; then
47             echo "Not found: local.params.example.$PARAMS"
48             echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
49             err=1
50         fi
51
52         if test -z "$SLS" -o ! -d config_examples/$SLS ; then
53             echo "Not found: config_examples/$SLS"
54             echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
55             err=1
56         fi
57
58         if test -z "$SETUPDIR" -o -z "$PARAMS" -o -z "$SLS" ; then
59             echo "installer.sh <setup dir to initialize> <params template> <config template>"
60             err=1
61         fi
62
63         if test -n "$err" ; then
64             exit 1
65         fi
66
67         echo "Initializing $SETUPDIR"
68         git init $SETUPDIR
69         cp -r *.sh tests $SETUPDIR
70
71         cp local.params.example.$PARAMS $SETUPDIR/local.params
72         cp -r config_examples/$SLS $SETUPDIR/local_config_dir
73
74         cd $SETUPDIR
75         git add *.sh local.params local_config_dir tests
76         git commit -m"initial commit"
77
78         echo "setup directory initialized, now go to $SETUPDIR, edit 'local.params' and 'local_config_dir' as needed, then run 'installer.sh deploy'"
79     ;;
80     deploy)
81         NODE=$1
82         CONFIG_FILE=local.params
83         if ! test -s $CONFIG_FILE ; then
84             echo "Must be run from arvados-setup, maybe you need to 'initialize' first?"
85         fi
86
87         source ${CONFIG_FILE}
88
89         set -x
90
91         BRANCH=$(git branch --show-current)
92
93         git add -A
94         if ! git diff --cached --exit-code ; then
95             git commit -m"prepare for deploy"
96         fi
97
98         if test -z "$NODE"; then
99             for NODE in "${!NODES[@]}"
100             do
101                 deploynode
102             done
103         else
104             deploynode
105         fi
106         ;;
107     *)
108         echo "Arvados installer"
109         echo ""
110         echo "initialize   initialize the setup directory for configuration"
111         echo "deploy       deploy the configuration from the setup directory"
112         ;;
113 esac