3 # Copyright (C) The Arvados Authors. All rights reserved.
5 # SPDX-License-Identifier: CC-BY-SA-3.0
10 # Helps manage the configuration in a git repository, and then deploy
11 # nodes by pushing a copy of the git repository to each node and
12 # running the provision script to do the actual installation and
19 declare CONFIG_FILE=local.params
21 # The salt template directory
22 declare CONFIG_DIR=local_config_dir
24 # The 5-character Arvados cluster id
25 # This will be populated by loadconfig()
28 # The parent domain (not including the cluster id)
29 # This will be populated by loadconfig()
32 # A bash associative array listing each node and mapping to the roles
33 # that should be provisioned on those nodes.
34 # This will be populated by loadconfig()
37 # The ssh user we'll use
38 # This will be populated by loadconfig()
41 # The git repository that we'll push to on all the nodes
42 # This will be populated by loadconfig()
49 # Synchronizes the configuration by creating a git repository on
50 # each node, pushing our branch, and updating the checkout.
52 if [[ "$NODE" != localhost ]] ; then
53 if ! ssh $NODE test -d ${GITTARGET}.git ; then
55 # Initialize the git repository (1st time case). We're
56 # actually going to make two repositories here because git
57 # will complain if you try to push to a repository with a
58 # checkout. So we're going to create a "bare" repository
59 # and then clone a regular repository (with a checkout)
62 ssh $NODE git init --bare ${GITTARGET}.git
63 if ! git remote add $NODE $DEPLOY_USER@$NODE:${GITTARGET}.git ; then
64 git remote set-url $NODE $DEPLOY_USER@$NODE:${GITTARGET}.git
66 git push $NODE $BRANCH
67 ssh $NODE git clone ${GITTARGET}.git ${GITTARGET}
72 # Push to the bare repository on the remote node, then in the
73 # remote node repository with the checkout, pull the branch
74 # from the bare repository.
76 git push $NODE $BRANCH
77 ssh $NODE "git -C ${GITTARGET} checkout ${BRANCH} && git -C ${GITTARGET} pull"
85 # Deploy a node. This runs the provision script on the node, with
86 # the appropriate roles.
88 if [[ -z "$ROLES" ]] ; then
89 echo "No roles declared for '$NODE' in ${CONFIG_FILE}"
93 if [[ "$NODE" = localhost ]] ; then
94 sudo ./provision.sh --config ${CONFIG_FILE} --roles ${ROLES}
96 ssh $DEPLOY_USER@$NODE "cd ${GITTARGET} && sudo ./provision.sh --config ${CONFIG_FILE} --roles ${ROLES}"
101 if [[ ! -s $CONFIG_FILE ]] ; then
102 echo "Must be run from initialized setup dir, maybe you need to 'initialize' first?"
104 source ${CONFIG_FILE}
105 GITTARGET=arvados-deploy-config-${CLUSTER}
109 if [[ -n "$subcmd" ]] ; then
114 if [[ ! -f provision.sh ]] ; then
115 echo "Must be run from arvados/tools/salt-install"
124 if [[ -z "$PARAMS" || ! -f local.params.example.$PARAMS ]] ; then
125 echo "Not found: local.params.example.$PARAMS"
126 echo "Expected one of multiple_hosts, single_host_multiple_hostnames, single_host_single_hostname"
130 if [[ -z "$SLS" || ! -d config_examples/$SLS ]] ; then
131 echo "Not found: config_examples/$SLS"
132 echo "Expected one of multi_host/aws, single_host/multiple_hostnames, single_host/single_hostname"
136 if [[ -z "$SETUPDIR" || -z "$PARAMS" || -z "$SLS" ]]; then
137 echo "installer.sh <setup dir to initialize> <params template> <config template>"
141 if [[ -n "$err" ]] ; then
145 echo "Initializing $SETUPDIR"
147 cp -r *.sh tests $SETUPDIR
149 cp local.params.example.$PARAMS $SETUPDIR/${CONFIG_FILE}
150 cp -r config_examples/$SLS $SETUPDIR/${CONFIG_DIR}
153 git add *.sh ${CONFIG_FILE} ${CONFIG_DIR} tests
154 git commit -m"initial commit"
156 echo "setup directory initialized, now go to $SETUPDIR, edit '${CONFIG_FILE}' and '${CONFIG_DIR}' as needed, then run 'installer.sh deploy'"
163 if grep -rni 'fixme' ${CONFIG_FILE} ${CONFIG_DIR} ; then
165 echo "Some parameters still need to be updated. Please fix them and then re-run deploy."
169 BRANCH=$(git branch --show-current)
174 if ! git diff --cached --exit-code ; then
175 git commit -m"prepare for deploy"
178 if [[ -z "$NODE" ]]; then
179 for NODE in "${!NODES[@]}"
181 # First, push the git repo to each node. This also
182 # confirms that we have git and can log into each
187 for NODE in "${!NODES[@]}"
189 # Do 'database' role first,
190 if [[ "${NODES[$NODE]}" =~ database ]] ; then
191 deploynode $NODE ${NODES[$NODE]}
196 for NODE in "${!NODES[@]}"
198 # then 'api' or 'controller' roles
199 if [[ "${NODES[$NODE]}" =~ (api|controller) ]] ; then
200 deploynode $NODE ${NODES[$NODE]}
205 for NODE in "${!NODES[@]}"
207 # Everything else (we removed the nodes that we
208 # already deployed from the list)
209 deploynode $NODE ${NODES[$NODE]}
212 # Just deploy the node that was supplied on the command line.
223 if ! which arvados-client ; then
224 echo "arvados-client not found, install 'arvados-client' package with 'apt-get' or 'yum'"
228 if [[ -z "$LOCATION" ]] ; then
229 echo "Need to provide '-internal-client' or '-external-client'"
231 echo "-internal-client You are running this on the same private network as the Arvados cluster (e.g. on one of the Arvados nodes)"
232 echo "-external-client You are running this outside the private network of the Arvados cluster (e.g. your workstation)"
236 export ARVADOS_API_HOST="${CLUSTER}.${DOMAIN}"
237 export ARVADOS_API_TOKEN="$SYSTEM_ROOT_TOKEN"
239 arvados-client diagnostics $LOCATION
242 echo "Arvados installer"
244 echo "initialize initialize the setup directory for configuration"
245 echo "deploy deploy the configuration from the setup directory"
246 echo "diagnostics check your install using diagnostics"