This repository has been archived by the owner on Jan 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
setup_chef_server.sh
executable file
·77 lines (64 loc) · 2.35 KB
/
setup_chef_server.sh
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
#!/bin/bash
#
# This script expects to be run in the chef-bcpc directory
#
set -e
set -x
# Default to Test-Laptop if environment not passed in
ENVIRONMENT="${1-Test-Laptop}"
# We may need the proxy for apt-get later
if [[ -f ./proxy_setup.sh ]]; then
. ./proxy_setup.sh
fi
if [[ -z "$CURL" ]]; then
echo "CURL is not defined"
exit
fi
# Make the bootstrap a client of its own BCPC local repo
echo "deb [trusted=yes arch=amd64] file://$(pwd)/bins/ 0.5.0 main" > \
/etc/apt/sources.list.d/bcpc.list
# Update only the BCPC local repo
apt-get -o Dir::Etc::SourceList=/etc/apt/sources.list.d/bcpc.list \
-o Dir::Etc::SourceParts="-" \
-o APT::Get::List-Cleanup="0" \
update
# Faraday will be required in libs, so we will not have a chance to recipe this away
/opt/chefdk/embedded/bin/gem install faraday
pushd /home/vagrant/chef-bcpc/lib/cluster-def-gem > /dev/null
sudo /opt/chefdk/embedded/bin/gem install cluster_def
popd > /dev/null
if dpkg -s chef-server 2>/dev/null | grep -q ^Status.*installed; then
# Faraday will be required in libs, so we will not have a chance to recipe this away
chef-server-ctl restart
echo 'chef-server is installed and the server has been restarted'
else
apt-get -y install chef-server
mkdir -p /etc/chef-server
cat > /etc/chef-server/chef-server.rb <<EOF
chef_server_webui['enable'] = false
# So that we have a proper CN with the bootstrap IP
# node['ipaddress'] is enough for a physical bootstrap.
# Needed for Vagrant + Virtualbox because the default route is to the NAT
# device.
eth1 = node['network']['interfaces']['eth1']['addresses']
nginx['server_name'] = eth1.detect { |_, v| v['family'] == 'inet' }.first
nginx['enable_non_ssl'] = false
nginx['non_ssl_port'] = 4000
# Configure Solr to index right away when we a new node.
# Reference: https://docs.chef.io/config_rb_server.html#opscode-solr4
# Called opscode_solr4 in chef-server 12+
chef_solr['max_commit_docs'] = 1
# we can take about 45 minutes to Chef the first machine when running on VMs
# so follow tuning from CHEF-4253
erchef['s3_url_ttl'] = 3600
EOF
export NO_PROXY=${NO_PROXY-127.0.0.1}
chef-server-ctl reconfigure
fi
# copy our ssh-key to be authorized for root
if [[ -f $HOME/.ssh/authorized_keys && ! -f /root/.ssh/authorized_keys ]]; then
if [[ ! -d /root/.ssh ]]; then
mkdir /root/.ssh
fi
cp $HOME/.ssh/authorized_keys /root/.ssh/authorized_keys
fi