Project

General

Profile

Download (2.79 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/bin/bash -x
2

    
3
# NOTE: 
4
# This script will only deploy the index for a specific cdmserver instance specified by 
5
# $INSTANCE_NAME. In order to securly install the new index it is recommendet to
6
# stop the instance before the index deployment is done. After this script has been run 
7
# the instance must be of course be started again. The EDIT Jeknins servers proviede 
8
# the sessecary groovy scripts (see jenkins scriptler)
9
#
10
#
11
#
12
# Requirements: 
13
# 1) for the commands executed by this script on the remote server the user jenkins 
14
# (requires to be member of the group 'cdm' ?still true?) and needs the following permissions in 
15
# sudoers:
16
#
17
#  |  # User alias specification
18
#  |  User_Alias      CDMUSERS = jenkins
19
#  |
20
#  |  #Cmnd alias specification
21
#  |  Cmnd_Alias      CDMSERVER = /bin/rm -rf /var/lib/cdmserver/*, /bin/mv /var/lib/cdmserver/*, /bin/chmod -R 775 /var/lib/cdmserver/*, /bin/chown -R * /var/lib/cdmserver/*
22
#  |  # User privilege specification
23
#  |  CDMUSERS        ALL=(ALL)NOPASSWD: CDMSERVER
24
#
25
# 2) the user executing this script (e.g. jenkins) must be allowed to ssh into the $REMOTE_SERVER 
26
#    via public key authentication 
27
#
28
# 3) /opt/cdmserver/.cdmLibrary/remote-webapp/index must be a symlink to the REMOTE_INDEX_CONTAINER
29
#
30
# 4) the REMOTE_INDEX_CONTAINER folder must have the permissions 775 for cdm:cdm
31
#    fix this: 
32
#      sudo chown -R cdm:cdm $REMOTE_INDEX_CONTAINER
33
#      sudo chmod -R 775 $REMOTE_INDEX_CONTAINER
34

    
35
if [ -z "${REMOTE_INDEX_CONTAINER}" ]; then
36
	REMOTE_INDEX_CONTAINER=/var/lib/cdmserver/
37
fi
38

    
39
if [ -z "${LOCAL_INDEX_CONTAINER}" ]; then
40
	LOCAL_INDEX_CONTAINER=/var/lib/cdmserver/
41
fi
42
if [ -z "${REMOTE_SERVER}" ]; then
43
	echo '$REMOTE_SERVER missing'
44
	exit 1
45
fi
46
if [ -z "${INSTANCE_NAME}" ]; then
47
  echo '$INSTANCE_NAME missing'
48
  exit 1
49
fi
50

    
51
echo "cdmserver-delpoy-index:"
52
echo "  REMOTE_SERVER = ${REMOTE_SERVER}"
53
echo "  LOCAL_INDEX_CONTAINER = ${LOCAL_INDEX_CONTAINER}"
54
echo "  REMOTE_INDEX_CONTAINER = ${REMOTE_INDEX_CONTAINER}"
55
echo "  INSTANCE_NAME = ${INSTANCE_NAME}"
56
echo "  "
57

    
58
echo "transferring  index to "${REMOTE_SERVER}
59
ssh ${REMOTE_SERVER} "sudo rm -rf ${REMOTE_INDEX_CONTAINER}tmp; sudo mkdir -p ${REMOTE_INDEX_CONTAINER}tmp; sudo chown -R cdm:cdm ${REMOTE_INDEX_CONTAINER}tmp"
60
cd ${LOCAL_INDEX_CONTAINER}/index
61
tar czf - ${INSTANCE_NAME} | ssh ${REMOTE_SERVER} "cd ${REMOTE_INDEX_CONTAINER}tmp ; tar xzf -"
62
# fixing owner and permissions
63
ssh ${REMOTE_SERVER} chmod -R 775 ${REMOTE_INDEX_CONTAINER}tmp
64
ssh ${REMOTE_SERVER} sudo chown -R cdm:cdm ${REMOTE_INDEX_CONTAINER}tmp
65

    
66
echo "installing new index for ${INSTANCE_NAME}"
67
ssh ${REMOTE_SERVER} sudo rm -rf ${REMOTE_INDEX_CONTAINER}index/${INSTANCE_NAME}
68
ssh ${REMOTE_SERVER} sudo mv ${REMOTE_INDEX_CONTAINER}tmp/${INSTANCE_NAME} ${REMOTE_INDEX_CONTAINER}index/${INSTANCE_NAME}
69
ssh ${REMOTE_SERVER} sudo rm -rf ${REMOTE_INDEX_CONTAINER}tmp
(1-1/3)