This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
/
cloud_controller_ctl.erb
152 lines (118 loc) · 4.6 KB
/
cloud_controller_ctl.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
export CC_JOB_DIR=/var/vcap/jobs/cloud_controller
export RAILS_ENV=production
export PATH=/var/vcap/packages/ruby/bin:$PATH
CC_PACKAGE_DIR=/var/vcap/packages/cloud_controller
NFS_SHARE=/var/vcap/shared
RUN_DIR=/var/vcap/sys/run/cloud_controller
LOG_DIR=/var/vcap/sys/log/cloud_controller
PIDFILE=$RUN_DIR/cloud_controller.pid
export CLOUD_CONTROLLER_CONFIG=$CC_JOB_DIR/config/cloud_controller.yml
export BUNDLE_GEMFILE=$CC_PACKAGE_DIR/cloud_controller/Gemfile
export HOME=/home/vcap # rake needs it to be set to run tasks
export TMPDIR=/var/vcap/data/cloud_controller/tmp
<% if properties.env %>
<% if properties.env.http_proxy %>
export HTTP_PROXY='<%= properties.env.http_proxy %>'
export http_proxy='<%= properties.env.http_proxy %>'
<% end %>
<% if properties.env.https_proxy %>
export HTTPS_PROXY='<%= properties.env.https_proxy %>'
export https_proxy='<%= properties.env.https_proxy %>'
<% end %>
<% if properties.env.no_proxy %>
export NO_PROXY='<%= properties.env.no_proxy %>'
export no_proxy='<%= properties.env.no_proxy %>'
<% end %>
<% end %>
export STAGING_CONFIG_DIR=$CC_JOB_DIR/config/staging
export STAGING_CACHE_DIR=/var/vcap/data/cloud_controller/staging
export CONFIG_DIR=$CC_JOB_DIR/config
export C_INCLUDE_PATH=/var/vcap/packages/mysqlclient/include/mysql:/var/vcap/packages/sqlite/include:/var/vcap/packages/libpq/include:$C_INCLUDE_PATH
export LIBRARY_PATH=/var/vcap/packages/mysqlclient/lib/mysql:/var/vcap/packages/sqlite/lib:/var/vcap/packages/libpq/lib:$LIBRARY_PATH
export LANG=en_US.UTF-8
source /var/vcap/packages/common/utils.sh
case $1 in
start)
pid_guard $PIDFILE "Cloud controller"
mkdir -p $RUN_DIR
mkdir -p $LOG_DIR
mkdir -p $STAGING_CACHE_DIR
mkdir -p $TMPDIR
chown vcap:vcap $RUN_DIR
chown vcap:vcap $LOG_DIR
chown vcap:vcap $TMPDIR
echo $$ > $PIDFILE
chown vcap:vcap $PIDFILE
<% if properties.nfs_server %>
modprobe nfs
mkdir -p $NFS_SHARE
cp -f /etc/default/nfs-common /etc/default/nfs-common.orig
cp -f $CC_JOB_DIR/config/nfs-common /etc/default/nfs-common
cp -f $CC_JOB_DIR/config/idmapd.conf /etc/idmapd.conf
/etc/init.d/idmapd restart
if grep -qs $NFS_SHARE /proc/mounts; then
echo "Found NFS mount, unmounting..."
umount $NFS_SHARE
if [ $? -ne 0 ]; then
echo "Failed to unmount NFS, exiting..."
exit 1
fi
fi
echo "Mounting NFS..."
<% if properties.nfs_server.nfsv4 %>
mount -o timeo=10,intr,lookupcache=positive -t nfs4 <%= properties.nfs_server.address %>:<%= properties.nfs_server.share || "/" %> $NFS_SHARE
<% else %>
mount -o timeo=10,intr,lookupcache=positive -t nfs <%= properties.nfs_server.address %>:<%= properties.nfs_server.share || "/var/vcap/store/shared" %> $NFS_SHARE
<% end %>
if [ $? != 0 ]; then
echo "Cannot mount NFS, exiting..."
exit 1
fi
chpst -u vcap:vcap touch $NFS_SHARE/.nfs_test
if [ $? != 0 ]; then
echo "Failed to start: cannot write to NFS"
exit 1
fi
<% end %>
# Create the secure users and setup sudo privs for vcap
# NB: This needs to happen _before_ executing `rake db:migrate' as that requires
# the existence of secure users (staging initializer).
$CC_PACKAGE_DIR/cloud_controller/script/create_secure_users.rb
chown root:root $CC_JOB_DIR/config/sudoers
chmod 440 $CC_JOB_DIR/config/sudoers
cp $CC_JOB_DIR/config/sudoers /etc/sudoers
# Only done on the first CC launch
<% if spec.index.to_i == 0 %>
cd $CC_PACKAGE_DIR/cloud_controller
export CC_NOSTART=1
chpst -u vcap:vcap bundle exec rake db:migrate >>$LOG_DIR/db_migrate.stdout.log 2>>$LOG_DIR/db_migrate.stderr.log
if [ $? != 0 ]; then
echo "Migrations failed"
# TODO: what to do with other CCs if this failed?
exit 1
fi
unset CC_NOSTART
<% end %>
# Seed the staging cache
cp -an /var/vcap/packages/dea_seed/gem_cache/* $STAGING_CACHE_DIR
chown -R vcap:vcap $STAGING_CACHE_DIR
# Configure the core file location
mkdir -p /var/vcap/sys/cores
chown vcap:vcap /var/vcap/sys/cores
echo /var/vcap/sys/cores/core-%e-%s-%p-%t > /proc/sys/kernel/core_pattern
ulimit -c unlimited
<% if properties.syslog_aggregator %>
/var/vcap/packages/syslog_aggregator/setup_syslog_forwarder.sh $CONFIG_DIR
<% end %>
exec chpst -u vcap:vcap $CC_PACKAGE_DIR/cloud_controller/bin/cloud_controller \
>>$LOG_DIR/cloud_controller.stdout.log \
2>>$LOG_DIR/cloud_controller.stderr.log
;;
stop)
kill_and_wait $PIDFILE
;;
*)
echo "Usage: cloud_controller_ctl {start|stop}"
;;
esac