6842655e3e4eaaeb0c6c41b1159855cc61b6d651
[releng/builder.git] / vagrant / lf-networking / configure_lf_infra.sh
1 #!/bin/bash
2
3 # for some reason not all systems have @base installed
4 yum install -y -q @base
5
6 # also make sure that a few other utilities are definitely installed
7 yum install -y -q unzip xz
8
9 # install some needed internal networking configurations
10 yum install -y dnsmasq puppet
11
12 # install specific versions of puppet modules
13 puppet module install puppetlabs-stdlib -v 4.5.1
14 puppet module install puppetlabs-concat -v 1.2.0
15 puppet module install lex-dnsmasq -v 2.6.1
16
17 # script requires information about subdomain
18 if [ -z "$1" ]; then
19     >&2 echo "Please provide the subdomain to Vagrant"
20     exit 1
21 fi
22
23 # write the subdomain information into a custom facter fact
24 mkdir -p /etc/facter/facts.d/
25 echo "subdomain=${1}" > /etc/facter/facts.d/subdomain.txt
26
27 # remove current networking configurations
28 rm -f /etc/sysconfig/network-scripts/{ifcfg,route}-{eth,docker}*
29
30 # final bits
31 puppet apply /vagrant/confignetwork.pp
32
33 # so that cloud-init doesn't futz with our resolv config after we've
34 # configured it
35 chattr +i /etc/resolv.conf
36
37 # don't let cloud-init do funny things to our routing
38 chattr +i /etc/sysconfig/network-scripts/route-eth0
39
40 # setup the needed routing
41 cat <<EOL >> /etc/rc.d/post-cloud-init
42 #!/bin/bash
43
44 # always force puppet to rerun
45 /usr/bin/puppet apply /vagrant/confignetwork.pp
46 EOL
47
48 chmod +x /etc/rc.d/post-cloud-init
49
50 systemd_init() {
51     # create a post-cloud-init.service and enable it
52     cat <<EOL > /etc/systemd/system/post-cloud-init.service
53 [Unit]
54 Description=Post cloud-init script (overwrites some cloud-init config)
55 After=cloud-init-local.service
56 Requires=cloud-init-local.service
57
58 [Service]
59 Type=oneshot
60 ExecStart=/etc/rc.d/post-cloud-init
61 TimeoutSec=0
62 #RemainAfterExit=yes
63 #SysVStartPriority=99
64
65 # Output needs to appear in instance console output
66 StandardOutput=journal+console
67
68 [Install]
69 WantedBy=multi-user.target
70 EOL
71
72     /usr/bin/systemctl enable post-cloud-init.service
73     chattr +i /etc/systemd/system/post-cloud-init.service
74 }
75
76 sysv_init() {
77     # create the SysV init and enable it
78     cat <<EOL > /etc/init.d/post-cloud-init
79 #!/bin/bash
80
81 ### BEGIN INIT INFO
82 # Provides:         post-cloud-init
83 # Required-Start:   $local_fs $network $named $remote_fs cloud-init-local
84 # Should-Start:     $time
85 # Required-Stop:
86 # Should-Stop:
87 # Default-Start:    2 3 4 5
88 # Default-Stop:     0 1 6
89 # Short-Description:    Setup dnsmasq for LF Rackspace environment
90 # Description:      Setup dnsmasq for LF Rackspace environment after
91 #   cloud-init-local
92
93 # Return values acc. to LSB for all commands but status:
94 # 0       - success
95 # 1       - generic or unspecified error
96 # 2       - invalid or excess argument(s)
97 # 3       - unimplemented feature (e.g. "reload")
98 # 4       - user had insufficient privileges
99 # 5       - program is not installed
100 # 6       - program is not configured
101 # 7       - program is not running
102 # 8--199  - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
103 #
104 # Note that starting an already running service, stopping
105 # or restarting a not-running service as well as the restart
106 # with force-reload (in case signaling is not supported) are
107 # considered a success.
108
109 RETVAL=0
110
111 prog="post-cloud-init"
112
113 start() {
114     echo -n $"Starting $prog: "
115     /etc/rc.d/post-cloud-init
116     RETVAL=$?
117     return $RETVAL
118 }
119
120 stop() {
121     echo -n $"Shutting down $prog:"
122     # No-op
123     RETVAL=7
124     return $RETVAL
125 }
126
127 case "$1" in
128     start)
129         start
130         RETVAL=$?
131         ;;
132     stop)
133         stop
134         RETVAL=$?
135         ;;
136     restart|try-restart|condrestart)
137         start
138         RETVAL=$?
139         ;;
140     status)
141         echo -n $"Checking for service $prog: "
142         # Return value is slightly different for the status command:
143         # 0 - service up and running
144         # 1 - service dead, but /var/run pid file exists
145         # 2 - service dead, but /var/lock file exists
146         # 3 - service not running (unused)
147         # 4 - service status unknown :-(
148         # 5--199 reserved (5-99 LSB, 100-149 distro, 150-199 appl.)
149         RETVAL=4
150         ;;
151     *)
152         echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}"
153         RETVAL=3
154         ;;
155 esac
156
157 exit $RETVAL
158 EOL
159     chmod +x /etc/init.d/post-cloud-init
160
161     /sbin/chkconfig --add post-cloud-init
162     /sbin/chkconfig post-cloud-init on
163 }
164
165 echo "Checking distribution"
166 if [ `/usr/bin/facter operatingsystem` = "Fedora" ]; then
167     echo "---> Fedora found"
168     systemd_init
169 else
170     if [ `/usr/bin/facter operatingsystemrelease | /bin/cut -d '.' -f1` = "7" ]; then
171         echo "---> CentOS 7"
172         systemd_init
173     else
174         echo "---> CentOS 6"
175         sysv_init
176     fi
177 fi
178
179 # vim: sw=4 ts=4 sts=4 et :