Browse code

Only modify folders created by devstack

running chown and chmod on files and folders not created by
devstack causes a few issues:

* On nfs mounted directories it can take an extremely
long time to chown -R some of the git repos, especially
if any tox commands have been ran in the host
* chown can cause the host files to get into a weird state
if nfs is set up wrong.

If files and folders are pre-existing we should assume
they are in the correct state, and not modify them.

Fix setup-devstack-log-dir to create the logs directory with
correct permissions in the first place.

Change-Id: I5ebdaded3ffd0a5bc70c5e9ab5b18daefb358f58
Signed-off-by: Graham Hayes <gr@ham.ie>

Graham Hayes authored on 2015/07/21 00:28:52
Showing 3 changed files
... ...
@@ -2,4 +2,7 @@
2 2
   file:
3 3
     path: '{{ devstack_base_dir }}/logs'
4 4
     state: directory
5
+    mode: 0755
6
+    owner: stack
7
+    group: stack
5 8
   become: yes
... ...
@@ -46,3 +46,14 @@
46 46
     dest: "{{ devstack_data_base_dir }}/data/"
47 47
     mode: push
48 48
   when: 'inventory_hostname in groups["subnode"]|default([])'
49
+
50
+- name: Ensure the data folder and subfolders have the correct permissions
51
+  become: true
52
+  file:
53
+    path: "{{ devstack_data_base_dir }}/data"
54
+    state: directory
55
+    owner: stack
56
+    group: stack
57
+    mode: 0755
58
+    recurse: yes
59
+  when: 'inventory_hostname in groups["subnode"]|default([])'
... ...
@@ -365,9 +365,12 @@ DEST=${DEST:-/opt/stack}
365 365
 
366 366
 # Create the destination directory and ensure it is writable by the user
367 367
 # and read/executable by everybody for daemons (e.g. apache run for horizon)
368
-sudo mkdir -p $DEST
369
-safe_chown -R $STACK_USER $DEST
370
-safe_chmod 0755 $DEST
368
+# If directory exists do not modify the permissions.
369
+if [[ ! -d $DEST ]]; then
370
+    sudo mkdir -p $DEST
371
+    safe_chown -R $STACK_USER $DEST
372
+    safe_chmod 0755 $DEST
373
+fi
371 374
 
372 375
 # Destination path for devstack logs
373 376
 if [[ -n ${LOGDIR:-} ]]; then
... ...
@@ -376,9 +379,11 @@ fi
376 376
 
377 377
 # Destination path for service data
378 378
 DATA_DIR=${DATA_DIR:-${DEST}/data}
379
-sudo mkdir -p $DATA_DIR
380
-safe_chown -R $STACK_USER $DATA_DIR
381
-safe_chmod 0755 $DATA_DIR
379
+if [[ ! -d $DATA_DIR ]]; then
380
+    sudo mkdir -p $DATA_DIR
381
+    safe_chown -R $STACK_USER $DATA_DIR
382
+    safe_chmod 0755 $DATA_DIR
383
+fi
382 384
 
383 385
 # Configure proper hostname
384 386
 # Certain services such as rabbitmq require that the local hostname resolves