apache2 fails to start if installed via cloud config (on Xenial)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
init-system-helpers (Debian) |
Fix Released
|
Unknown
|
|||
init-system-helpers (Ubuntu) |
Fix Released
|
High
|
Martin Pitt | ||
Xenial |
Fix Released
|
High
|
Martin Pitt | ||
systemd (Debian) |
Fix Released
|
Unknown
|
Bug Description
SRU TEST CASE:
Using the following cloud config, apache2 will fail to start on installation on Xenial:
#cloud-config
packages:
- apache2
See for example:
$ gcloud compute instances create xenial-$(date +%y%m%d-%H%M) --image ubuntu-
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
xenial-160427-1050 europe-west1-d n1-standard-1 10.240.0.7 104.155.86.94 RUNNING
$ ssh ubuntu@
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.
Drop-In: /lib/systemd/
Active: inactive (dead)
Docs: man:systemd-
With the fixed init-system-
Related Bugs:
* bug 1576692: [cloud-init] fully support package installation in systemd
Changed in init-system-helpers (Ubuntu Xenial): | |
status: | New → Triaged |
assignee: | nobody → Martin Pitt (pitti) |
importance: | Undecided → High |
Changed in systemd (Ubuntu Xenial): | |
status: | New → Won't Fix |
description: | updated |
description: | updated |
no longer affects: | cloud-init (Ubuntu Xenial) |
no longer affects: | cloud-init (Ubuntu) |
Changed in systemd (Debian): | |
status: | Unknown → Confirmed |
Changed in systemd (Ubuntu): | |
status: | Won't Fix → Triaged |
importance: | High → Low |
Changed in systemd (Ubuntu): | |
assignee: | nobody → Martin Pitt (pitti) |
Changed in init-system-helpers (Ubuntu Xenial): | |
status: | Triaged → In Progress |
description: | updated |
Changed in init-system-helpers (Debian): | |
status: | Unknown → Fix Released |
no longer affects: | systemd (Ubuntu) |
no longer affects: | systemd (Ubuntu Xenial) |
Changed in systemd (Debian): | |
status: | Confirmed → Fix Released |
This issue was originally reported by a customer, who investigated it as follows:
#####
"If you run up a 16.04 cloud image using EC2 compatible user-data containing a simple shell script.
#!/bin/sh
sudo DEBIAN_ FRONTEND= noninteractive apt-get -q -y update FRONTEND= noninteractive apt-get install -q -y apache2
sudo DEBIAN_
sudo nc -k -l -d 443&
then the apache2 daemon will rarely start - if ever.
(You get the same problem running the equivalent 'cloud-config' script).
This is because 'cloud-init' runs the script when the run level is 'unknown', and the 'invoke-rc.d' script has no case for handling 'unknown' run levels - so it defaults to not starting anything.
I've seen this a few times with packages that have old style SysV init scripts and that start a daemon automatically in the 'postinst' script.
cloud-init should defer running scripts and cloud-config installs until systemd has achieved a defined run level - or the SysV backward compatibility needs improving so that it can deal with systemd being between run levels."
###
I could consistently reproduce across 20+ tests using the user data supplied by the customer; either:
#cloud-config
packages:
- apache2
runcmd:
- "nc -k -l -d 443&"
or:
#!/bin/sh
output_runlevel() { FRONTEND= noninteractive apt-get -q -y update invoke- rc.d FRONTEND= noninteractive apt-get install -q -y apache2
echo -n "Current runlevel is "
sudo /sbin/runlevel
}
output_runlevel
sudo DEBIAN_
#sudo sed -ie 's/set +e$/& -x/' /usr/sbin/
output_runlevel
sudo DEBIAN_
output_runlevel
sudo nc -k -l -d 443&
Apache 2 is correctly installed, but never started (nc is started as expected):
$ sudo systemctl status apache2; sudo netstat -A inet -lnp | grep 443 d/apache2; bad; vendor preset: enabled) system/ apache2. service. d systemd. conf sysv-generator( 8)
● apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.
Drop-In: /lib/systemd/
└─apache2-
Active: inactive (dead)
Docs: man:systemd-
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 2657/nc
Runlevel output is as per the customer's description (unknown). Edited excerpt from cloud-init- output. log on a VM that ran the script:
[snip]
Reading package lists...
Current runlevel is unknown # <-- output of output_runlevel(), as per above
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1
[snip]