Error deploying website with apache-php

Bug #1815107 reported by Andre Ruiz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Charm Helpers
New
Undecided
Unassigned

Bug Description

I got an error when deploying a website using apache-php.

Context: You can pass it a URL for a compressed file which it will automatically download and unpack into /var/www/<sitename> during the setup process. Also, sometimes this packages have all meaningful files inside a subdirectory, for easying the unpacking. The apache-php layer tries to dectect that and moves that subdir out of the path bringing it's contents to the parent dir.

Problem: when the subdir have the same name of the website dir it will try to move a dir to the parent subdirectory which already have a one with the same name, and it fails.

It needs to detect this case and move the subdir to a temporary name before moving to the parent dir.

Evidence:

unit-nextcloud-17: 16:31:12 INFO unit.nextcloud/17.juju-log Making dir /var/www/nextcloud root:root 555
unit-nextcloud-17: 16:31:26 ERROR unit.nextcloud/17.juju-log Hook error:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/charms/reactive/__init__.py", line 73, in main
    bus.dispatch(restricted=restricted_mode)
  File "/usr/local/lib/python3.6/dist-packages/charms/reactive/bus.py", line 379, in dispatch
    _invoke(hook_handlers)
  File "/usr/local/lib/python3.6/dist-packages/charms/reactive/bus.py", line 359, in _invoke
    handler.invoke()
  File "/usr/local/lib/python3.6/dist-packages/charms/reactive/bus.py", line 181, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-nextcloud-17/charm/reactive/apache.py", line 25, in install
    install_site(name, site)
  File "/var/lib/juju/agents/unit-nextcloud-17/charm/reactive/apache.py", line 64, in install_site
    strip_archive_dir(dest)
  File "/var/lib/juju/agents/unit-nextcloud-17/charm/reactive/apache.py", line 98, in strip_archive_dir
    os.rename(subdir, tmp_dest)
OSError: [Errno 39] Directory not empty: '/var/www/nextcloud/nextcloud' -> '/var/www/nextcloud'

unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install Traceback (most recent call last):
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/var/lib/juju/agents/unit-nextcloud-17/charm/hooks/install", line 22, in <module>
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install main()
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/usr/local/lib/python3.6/dist-packages/charms/reactive/__init__.py", line 73, in main
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install bus.dispatch(restricted=restricted_mode)
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/usr/local/lib/python3.6/dist-packages/charms/reactive/bus.py", line 379, in dispatch
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install _invoke(hook_handlers)
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/usr/local/lib/python3.6/dist-packages/charms/reactive/bus.py", line 359, in _invoke
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install handler.invoke()
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/usr/local/lib/python3.6/dist-packages/charms/reactive/bus.py", line 181, in invoke
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install self._action(*args)
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/var/lib/juju/agents/unit-nextcloud-17/charm/reactive/apache.py", line 25, in install
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install install_site(name, site)
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/var/lib/juju/agents/unit-nextcloud-17/charm/reactive/apache.py", line 64, in install_site
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install strip_archive_dir(dest)
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install File "/var/lib/juju/agents/unit-nextcloud-17/charm/reactive/apache.py", line 98, in strip_archive_dir
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install os.rename(subdir, tmp_dest)
unit-nextcloud-17: 16:31:26 DEBUG unit.nextcloud/17.install OSError: [Errno 39] Directory not empty: '/var/www/nextcloud/nextcloud' -> '/var/www/nextcloud'
unit-nextcloud-17: 16:31:26 ERROR juju.worker.uniter.operation hook "install" failed: exit status 1
unit-nextcloud-17: 16:31:26 INFO juju.worker.uniter awaiting error resolution for "install" hook

The following patch fixes it:

diff -uNr nextcloud_orig/reactive/apache.py nextcloud/reactive/apache.py
--- nextcloud_orig/reactive/apache.py 2019-02-07 15:29:02.112829947 -0200
+++ nextcloud/reactive/apache.py 2019-02-07 15:33:13.615706901 -0200
@@ -94,6 +94,11 @@
     subdir = os.path.join(site_dir, contents[0])
     if not os.path.isdir(subdir):
         return
+ # check for the case where subdir have the same name of the parent
+ if os.path.basename(site_dir) == contents[0]:
+ os.rename(subdir, subdir+"_tmp")
+ contents = os.listdir(site_dir)
+ subdir = os.path.join(site_dir, contents[0])
     tmp_dest = os.path.join(os.path.dirname(site_dir), contents[0])
     os.rename(subdir, tmp_dest)
     os.rmdir(site_dir)

Revision history for this message
Andre Ruiz (andre-ruiz) wrote :

Sorry I guess this is the wrong place for this bug. Uppon more investigation it seems that layers get downloaded from github in realtime and are not present on any package.

I will submit a pull request to the project on github.

This can be closed. Thank you.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.