简体   繁体   中英

Openshift [Errno 13] Permission denied

I met an exact same problem with what this link says: pip install Failed in OpenShift, the error info is Permission Denied . I encountered the error while I was deploying django-oscar to openshift. To simplify the issue I did a test by creating a new cartridge. Then access my openshift server via ssh to execute the next command: pip install django-oscar . It has a good beginning but a bad ending as followed code shows:

mrju@mrju:~/Documents/My_Project/My_Website/Oscar_Test$ rhc app create oscartest python-2.7
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
Application Options
-------------------
Domain:     mrju
Cartridges: python-2.7
Gear Size:  default
Scaling:    no

Creating application 'oscartest' ... done


Waiting for your DNS name to be available ... done

Cloning into 'oscartest'...
The authenticity of host 'oscartest-mrju.rhcloud.com (52.3.216.108)' can't be established.
RSA key fingerprint is cf:ee:77:cb:0e:fc:02:d7:72:7e:ae:80:c0:90:88:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oscartest-mrju.rhcloud.com,52.3.216.108' (RSA) to the list of known hosts.

Your application 'oscartest' is now available.



mrju@mrju:~/Documents/My_Project/My_Website/Oscar_Test$ ssh 5773c52c2d52710e5e00024a@oscartest-mrju.rhcloud.com



*********************************************************************

You are accessing a service that is for use only by authorized users.
If you do not have authorization, discontinue use at once.
Any use of the services is subject to the applicable terms of the
agreement which can be found at:
https://www.openshift.com/legal

*********************************************************************

Welcome to OpenShift shell

This shell will assist you in managing OpenShift applications.

!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Shell access is quite powerful and it is possible for you to
accidentally damage your application.  Proceed with care!
If worse comes to worst, destroy your application with "rhc app delete"
and recreate it
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!

Type "help" for more info.


[oscartest-mrju.rhcloud.com 5773c52c2d52710e5e00024a]\> 

[oscartest-mrju.rhcloud.com 5773c52c2d52710e5e00024a]\> cd /var/lib/openshift/5773c52c2d52710e5e00024a/python//virtenv/
[oscartest-mrju.rhcloud.com virtenv]\> ls
bin  include  lib  lib64  pip-selfcheck.json
[oscartest-mrju.rhcloud.com virtenv]\> source bin/activate
(virtenv)[oscartest-mrju.rhcloud.com virtenv]\> pip install django-oscar
***The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.***
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting django-oscar
  Downloading django_oscar-1.2.1-py2.py3-none-any.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 39kB/s 
Collecting phonenumbers<8.0.0,>=6.3.0 (from django-oscar)
  Downloading phonenumbers-7.4.3.tar.gz (2.3MB)
    100% |████████████████████████████████| 2.3MB 81kB/s 
Collecting factory-boy<2.7,>=2.4.1 (from django-oscar)
  Downloading factory_boy-2.6.1-py2.py3-none-any.whl
Collecting purl>=0.7 (from django-oscar)
  Downloading purl-1.3-py2.py3-none-any.whl
Collecting mock<2.0,>=1.0.1 (from django-oscar)
  Downloading mock-1.3.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 57kB 3.7MB/s 
Collecting django<1.9,>=1.7.8 (from django-oscar)
  Downloading Django-1.8.13-py2.py3-none-any.whl (6.2MB)
    100% |████████████████████████████████| 6.2MB 61kB/s 
Collecting django-haystack<2.5.0,>=2.3.1 (from django-oscar)
  Downloading django_haystack-2.4.1-py2-none-any.whl (95kB)
    100% |████████████████████████████████| 98kB 3.9MB/s 
Collecting django-treebeard>=3.0 (from django-oscar)
  Downloading django-treebeard-4.0.1.tar.gz (93kB)
    100% |████████████████████████████████| 94kB 2.6MB/s 
Collecting django-extra-views<0.6.5,>=0.2 (from django-oscar)
  Downloading django_extra_views-0.6.4-py27-none-any.whl
Collecting pillow>=1.7.8 (from django-oscar)
  Downloading Pillow-3.2.0.zip (10.5MB)
    100% |████████████████████████████████| 10.5MB 22kB/s 
Collecting Unidecode<0.05,>=0.04.12 (from django-oscar)
  Downloading Unidecode-0.04.19.tar.gz (204kB)
    100% |████████████████████████████████| 204kB 1.4MB/s 
Collecting sorl-thumbnail==12.3 (from django-oscar)
  Downloading sorl_thumbnail-12.3-py2.py3-none-any.whl (40kB)
    100% |████████████████████████████████| 40kB 4.2MB/s 
Collecting django-tables2<1.1,>=1.0.4 (from django-oscar)
  Downloading django-tables2-1.0.7.tar.gz (966kB)
    100% |████████████████████████████████| 970kB 343kB/s 
Collecting Babel<3.0,>=1.0 (from django-oscar)
  Downloading Babel-2.3.4-py2.py3-none-any.whl (7.1MB)
    100% |████████████████████████████████| 7.1MB 46kB/s 
Collecting django-widget-tweaks>=1.4.1 (from django-oscar)
  Downloading django_widget_tweaks-1.4.1-py2.py3-none-any.whl
Collecting fake-factory>=0.5.0 (from factory-boy<2.7,>=2.4.1->django-oscar)
  Downloading fake_factory-0.5.8-py2.py3-none-any.whl (505kB)
    100% |████████████████████████████████| 507kB 618kB/s 
Requirement already satisfied (use --upgrade to upgrade): six in /opt/rh/python27/root/usr/lib/python2.7/site-packages (from purl>=0.7->django-oscar)
Collecting funcsigs (from mock<2.0,>=1.0.1->django-oscar)
  Downloading funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock<2.0,>=1.0.1->django-oscar)
  Downloading pbr-1.10.0-py2.py3-none-any.whl (96kB)
    100% |████████████████████████████████| 98kB 3.5MB/s 
Collecting pytz>=0a (from Babel<3.0,>=1.0->django-oscar)
  Downloading pytz-2016.4-py2.py3-none-any.whl (480kB)
    100% |████████████████████████████████| 483kB 404kB/s 
Collecting python-dateutil>=2.4 (from fake-factory>=0.5.0->factory-boy<2.7,>=2.4.1->django-oscar)
  Downloading python_dateutil-2.5.3-py2.py3-none-any.whl (201kB)
    100% |████████████████████████████████| 204kB 1.1MB/s 
Collecting ipaddress (from fake-factory>=0.5.0->factory-boy<2.7,>=2.4.1->django-oscar)
  Downloading ipaddress-1.0.16-py27-none-any.whl
Building wheels for collected packages: phonenumbers, django-treebeard, pillow, Unidecode, django-tables2
Exception:
Traceback (most recent call last):
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/commands/install.py", line 293, in run
    wb.build(autobuilding=True)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/wheel.py", line 756, in build
    ensure_dir(output_dir)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/utils/__init__.py", line 70, in ensure_dir
    os.makedirs(path)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache'

(virtenv)[oscartest-mrju.rhcloud.com virtenv]\> 

The prompt is very useful

The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

However I don't know how to get the sudo's permission or how to use sudo's -H flag.

Don't use sudo if you're using pip from within a virtual environment (which you are, judging by the code you've posted) as this will install the package gloabally and not in the virtual environment.

Instead, you can use pip with the --user flag like this:

pip install --user <package_name>

Failing this, try upgrading pip as the traceback suggested and then attempt a re-install

尝试pip install django-oscar --no-cache-dir

sudo is used to execute commands with the root status. You can simply write your command with sudo before like sudo ls .

For your problem I think that pip haven't the execute permission to .cache (if you have the execute permission for a file, then, you can execute this one and, for a directory, you can cross it. To resolve this, add the permission with sudo chmod and the value that you wish.

The chmod take a number like 777 etc given by values of rights. chmod rwx rwx rwx

chmod user group other with each : read write execute with boolean value (0 or 1) so for example : chmod 750 means that user has all permission (111), group has read and execute permissions only (101) and other any permission.

You can also add permission x with sudo chmod +x name

If you don't know a flag, try the man command at first.

man sudo :

The -H (HOME) option option sets the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. The default handling of the HOME environment variable depends on sudoers(5) settings. By default, sudo will set HOME if env_reset or always_set_home are set, or if set_home is set and the -s option is specified on the command line.

So, try a simple sudo pip install django-oscar or a su command to become root during the current session.

In case someone faces this problem in future this helped me - enter link description here

Here is the details from the link -
Here is a fix I managed to find using OpenShift actions hooks. The key web links that helped are listed in the code listing below.

Detailed instructions:

  • In your local repo, change to the folder .openshift\\action_hooks
  • Add a file named build to your local repo folder called .openshift\\action_hooks
  • In the file build add these lines:
# !/bin/bash
# Written by Priyend Somaroo, 06 Jun 2016, Vardaan Enterpises, www.vardaan.com
#
# This will execute pip install but using no caching in order to fix broken 
# cache problems with python-2.7 cartridge as at 06 Jun 2016
#
#   Ref: http://stackoverflow.com/questions/29913677/openshift-app-with-flask-sqlalchemy-and-sqlite-problems-with-database-reverti
#   Ref: http://stackoverflow.com/questions/21691202/how-to-create-file-execute-mode-permissions-in-git-on-windows
#
# 
# *** Very important *** : this file must be marked executable using 'chmod +x'.
# In Windows this is a problem so we simply mark it in the git repo as executable as follows.
# - In Windows open command prompt and change to the folder with this build file
# - Then run 'git update-index --chmod=+x build'
# - Ten check the permissions aer 0755 using 'git ls-files --stage' .
#
# Normal commits and push's occur after that.

# This build hook gets executed at the end of the build cycle before delpoy

# Change to repo directory and run pip install with no caching
cd ${OPENSHIFT_REPO_DIR}
pip install -r requirements.txt --no-cache-dir
  • Mark the build file executable for it to run correctly:
  • In Linux run: chmod +x build
  • For Windows you will need to run this instead: git update-index --chmod=+x build
  • Finally complete your git commit and git push

You can confirm the correct packages got installed by ssh'ing into your app folder and running: pip list

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM