Move Cloudify's password update and plugins upload to
[dcaegen2/deployments.git] / cm-container / scripts / start-persistent.sh
1 #!/bin/bash
2 # ================================================================================
3 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ============LICENSE_END=========================================================
17 # Set up persistent storage for Cloudify Manager's state data
18
19 PDIRS="/var/lib/pgsql/9.5/data /opt/manager/resources /opt/mgmtworker/env/plugins /opt/mgmtworker/work/deployments"
20 PSTORE="/cfy-persist"
21
22 set -ex
23
24 if [ -d "$PSTORE" ] 
25 then
26   # the persistent mount point exists
27   if [ -z "$(ls -A $PSTORE)" ]
28   then
29     # there's nothing in the persistent store yet
30     # copy in the data from the container file system
31     for d in $PDIRS
32     do
33       p="$(dirname $d)"
34       mkdir -p "${PSTORE}$p"
35       cp -rp "$d" "${PSTORE}$p"
36     done
37   fi
38   # at this point, there is persistent storage possibly from a previous startup
39   # set up links from internal file system to persistent storage
40   for d in $PDIRS
41   do
42     if [ -d "$d" ]
43     then
44         mv $d $d-initial        # move directory so we can create symlink
45     fi
46     ln -sf "$PSTORE/$d" "$(dirname $d)"
47   done
48 else
49   echo "No persistent storage available"
50 fi
51
52 # start background script that updates CM password and uploads plugins
53 /scripts/init-cloudify.sh &
54 # start up init, which brings up CM and supporting software
55 exec /sbin/init --log-target=journal 3>&1
56