Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-server / src / main / jenkins-ci / cdmserver-deploy-index.sh @ b2fb0473

History | View | Annotate | Download (2.9 KB)

1
#!/bin/bash -x
2

    
3
# Requirements: 
4
# 1) for the commands executed by this script on the remote server the user jenkins 
5
# (requires to be member of the group 'cdm' ?still true?) and needs the following permissions in 
6
# sudoers:
7
#
8
#  |  # User alias specification
9
#  |  User_Alias      CDMUSERS = jenkins
10
#  |
11
#  |  #Cmnd alias specification
12
#  |  Cmnd_Alias      CDMSERVER = /bin/cp -f cdm-server*.jar /opt/cdmserver/, /etc/init.d/cdmserver *, /bin/rm -f /opt/cdmserver/cdm-server.jar, /bin/ln -s cdm-server*.jar cdm-server.jar, /bin/rm -rf /var/lib/cdmserver/*, /bin/mv /var/lib/cdmserver/*, /bin/chmod -R 775 /var/lib/cdmserver/*, /bin/chown -R * /var/lib/cdmserver/*
13
#  |  # User privilege specification
14
#  |  CDMUSERS        ALL=(ALL)NOPASSWD: CDMSERVER
15
#
16
# 2) the user executing this script (e.g. jenkins) must be allowed to ssh into the $REMOTE_SERVER 
17
#    via public key authentication 
18
#
19
# 3) /opt/cdmserver/.cdmLibrary/remote-webapp/index must be a symlink to the REMOTE_INDEX_CONTAINER
20
#
21
# 4) the REMOTE_INDEX_CONTAINER folder must have the permissions 775 for cdm:cdm
22
#    fix this: 
23
#      sudo chown -R cdm:cdm $REMOTE_INDEX_CONTAINER
24
#      sudo chmod -R 775 $REMOTE_INDEX_CONTAINER
25

    
26
if [ -z "${REMOTE_INDEX_CONTAINER}" ]; then
27
	REMOTE_INDEX_CONTAINER=/var/lib/cdmserver/
28
fi
29

    
30
if [ -z "${LOCAL_INDEX_CONTAINER}" ]; then
31
	LOCAL_INDEX_CONTAINER=/var/lib/cdmserver/
32
fi
33

    
34
if [ -z "${REMOTE_SERVER_DO_RESTART}" ]; then
35
	REMOTE_SERVER_DO_RESTART="restart"
36
fi
37
if [ -z "${REMOTE_SERVER}" ]; then
38
	echo '$REMOTE_SERVER missing'
39
	exit 1
40
fi
41

    
42
echo "cdmserver-delpoy-index:"
43
echo "  REMOTE_SERVER = ${REMOTE_SERVER}"
44
echo "  LOCAL_INDEX_CONTAINER = ${LOCAL_INDEX_CONTAINER}"
45
echo "  REMOTE_INDEX_CONTAINER = ${REMOTE_INDEX_CONTAINER}"
46
echo "  REMOTE_SERVER_DO_RESTART = ${REMOTE_SERVER_DO_RESTART}"
47
echo "  "
48

    
49
echo "transferring  index to "${REMOTE_SERVER}
50
ssh ${REMOTE_SERVER} "sudo rm -rf ${REMOTE_INDEX_CONTAINER}tmp; mkdir -p ${REMOTE_INDEX_CONTAINER}tmp"
51
cd ${LOCAL_INDEX_CONTAINER}
52
tar czf - index | ssh ${REMOTE_SERVER} "cd ${REMOTE_INDEX_CONTAINER}tmp ; tar xzf -"
53
# fixing owner and permissions
54
ssh ${REMOTE_SERVER} chmod -R 775 ${REMOTE_INDEX_CONTAINER}tmp
55
ssh ${REMOTE_SERVER} sudo chown -R cdm:cdm ${REMOTE_INDEX_CONTAINER}tmp
56

    
57
STATUS=$(ssh ${REMOTE_SERVER} "sudo /etc/init.d/cdmserver status")
58
NOT_RUNNING=$(echo "${STATUS}" | grep "not running")
59
if [ -z "${NOT_RUNNING}" ]; then
60
  echo "stopping $REMOTE_SERVER ..." 
61
  ssh ${REMOTE_SERVER} sudo /etc/init.d/cdmserver stop
62
  echo "waiting 20 seconds for server shutting down ..."
63
  sleep 20 
64
else 
65
  echo "server is not running"
66
fi
67

    
68
echo "switching to new index"
69
ssh ${REMOTE_SERVER} rm -rf ${REMOTE_INDEX_CONTAINER}index
70
ssh ${REMOTE_SERVER} mv ${REMOTE_INDEX_CONTAINER}tmp/index ${REMOTE_INDEX_CONTAINER}index
71
ssh ${REMOTE_SERVER} rm -rf ${REMOTE_INDEX_CONTAINER}tmp
72

    
73
if [ "${REMOTE_SERVER_DO_RESTART}" == "restart" ]; then
74
	echo "restarting server"
75
    ssh ${REMOTE_SERVER} sudo /etc/init.d/cdmserver start
76
fi
Add picture from clipboard (Maximum size: 40 MB)