Microsoft MVP성태의 닷넷 이야기
오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty [링크 복사], [링크+제목 복사],
조회: 5346
글쓴 사람
정성태 (seongtaejeong at gmail.com)
홈페이지
첨부 파일
 

Azure - rm: cannot remove '...': Directory not empty

Azure Web App 환경의 경우, 예를 들어 Python 앱이라면,

파이썬 웹 앱을 Azure App Service에 배포하기
; https://www.sysnet.pe.kr/2/0/13830

리눅스 환경에서 호스팅하게 되는데요, 여기서 임의의 데이터를 지속하고 싶다면 반드시 /home 디렉터리 하위에 위치시켜야 합니다.

예를 들어, 파이썬 앱에서 사용하는 패키지를 다음과 같이 설치하면,

$ pip install test-app

Scale-out이 된 경우, 저 SSH로 들어간 환경에서만 test-app 패키지를 사용할 수 있는 데다, 만약 해당 Web App 인스턴스가 재시작하면 저 test-app을 설치한 디렉터리는 다시 초기화되므로 사라지게 됩니다.

따라서, 이런 경우 반드시 /home 디렉터리 하위에 설치해야 합니다.

$ pip install test-app -t /home/test_pacakge

/home 디렉터리 외에도, Azure는 이를 우회할 수 있는 자동화 스크립트 방법을 제공하는데요,

Customize build automation
; https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#customize-build-automation

정리하면 SCM_DO_BUILD_DURING_DEPLOYMENT 환경변수를 1로 설정하고, 원하는 스크립트를 PRE_BUILD_COMMAND / POST_BUILD_COMMAND 환경변수에 설정하거나, 보유하고 있는 requirements.txt에 해당 패키지를 추가하는 식으로 처리할 수 있습니다.




여기서는 /home 디렉터리 하위에 직접 사용자가 설치한 경우를 예로 들어 보겠습니다.

$ pip install test-app -t /home/test_pacakge

이런 상태에서 Python Web App이 실행 중일 때, /home/test_pacakge 디렉터리 하위에 있는 "실행 파일"을 함께 구동했다고 가정하면, 그 실행 파일은 Web App이 Scale-out하면 그 인스턴스 수만큼 실행이 될 것입니다.

재미있는 건, 그 상태에서 해당 패키지가 업그레이드돼 다시 설치하게 되면,

# pip install test-app -U -t /home/test_pacakge
Collecting test-app
...[생략]...

ERROR: Exception:
Traceback (most recent call last):
  File "/tmp/8dd0d13008cfbf9/antenv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 105, in _run_wrapper
    status = _inner_run()
             ^^^^^^^^^^^^
  File "/tmp/8dd0d13008cfbf9/antenv/lib/python3.12/site-packages/pip/_internal/cli/base_command.py", line 96, in _inner_run
    return self.run(options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/8dd0d13008cfbf9/antenv/lib/python3.12/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    return func(self, options, args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/8dd0d13008cfbf9/antenv/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 519, in run
    self._handle_target_dir(
  File "/tmp/8dd0d13008cfbf9/antenv/lib/python3.12/site-packages/pip/_internal/commands/install.py", line 574, in _handle_target_dir
    shutil.rmtree(target_item_dir)
  File "/opt/python/3.12.2/lib/python3.12/shutil.py", line 785, in rmtree
    _rmtree_safe_fd(fd, path, onexc)
  File "/opt/python/3.12.2/lib/python3.12/shutil.py", line 686, in _rmtree_safe_fd
    _rmtree_safe_fd(dirfd, fullname, onexc)
  File "/opt/python/3.12.2/lib/python3.12/shutil.py", line 686, in _rmtree_safe_fd
    _rmtree_safe_fd(dirfd, fullname, onexc)
  File "/opt/python/3.12.2/lib/python3.12/shutil.py", line 697, in _rmtree_safe_fd
    onexc(os.rmdir, fullname, err)
  File "/opt/python/3.12.2/lib/python3.12/shutil.py", line 695, in _rmtree_safe_fd
    os.rmdir(entry.name, dir_fd=topfd)
OSError: [Errno 39] Directory not empty: 'amd64'

이런 식의 오류가 발생합니다. 실제로 해당 경로를 직접 삭제하려고 하면 문제가 되는 디렉터리가 밝혀지는데요,

# rm -rf /home/test_pacakge
rm: cannot remove '/home/test_pacakge/bin/linux/amd64': Directory not empty

저 amd64에는 실행 파일이 있고, 그 실행 파일이 사용 중이라 삭제가 안 되는 것입니다. 따라서, 저 디렉터리가 삭제될 수 있어야 하는데요, 만약 Web App 재시작으로 가능하다면 그렇게 하면 됩니다.

혹은, SSH 환경에서 직접 저 실행 파일을 kill 하면 되는데요,

# ps aux | grep test-app
root          65  0.1  0.2 714036  4920 ?        SNl  01:34   0:13 /home/test_package/bin/linux/amd64/test-app
root         139  0.0  0.0   6240   620 pts/1    SN+  04:31   0:00 grep test-app

# kill 65

# ps aux | grep test-app
root         141  0.0  0.0   6240   652 pts/1    SN+  04:31   0:00 grep test-app

Scale-out 환경이라면 저렇게 했어도 여전히 디렉터리 삭제가 안 될 것입니다. 왜냐하면, 저렇게 실행 중인 프로세스를 모든 인스턴스에서 종료해야 하기 때문입니다.




한 가지 재미있는 점이 있는데요, Azure Web App 환경의 SSH 접속으로 설치한 파일들의 소유자를 보면,

# pip install test-app -t /home/test_pacakge

# ls /home/test_pacakge/ -l
total 0
drwxrwxrwx 2 nobody nogroup 0 Dec  2 01:19 bin
drwxrwxrwx 2 nobody nogroup 0 Dec  2 01:19 test_app
drwxrwxrwx 2 nobody nogroup 0 Dec  2 01:19 test_app-1.0.0.0.dist-info

저렇게 nobody, nogroup이 있습니다. 검색해 보면,

Debian change owner of nobody:nogroup
; https://unix.stackexchange.com/questions/563942/debian-change-owner-of-nobodynogroup

이게 컨테이너 내에서 볼 수 없는 상위 네임스페이스에서 설정된 파일 권한이어서 그렇다고 합니다.

# ls -n 
total 3064
-rwxrwxrwx 1 65534 65534 3137536 Nov 29 01:46 test-app

이런 경우 저렇게 uid/gid도 65534로 나온다고. ^^




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 12/3/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
10999정성태7/16/201622013오류 유형: 341. .NET Framework 4.5.2가 설치 안 되는 경우
10998정성태7/16/201621788.NET Framework: 598. C# - Excel 시트에 윈도우 폼 기능을 추가하는 방법 [1]파일 다운로드1
10997정성태7/16/201621103오류 유형: 340. HTTP Error 500.23 - Internal Server Error파일 다운로드1
10996정성태7/14/201626693Windows: 118. 유선 접속 상태에서 재부팅하면 무선 연결이 자동 연결 안되는 문제 [4]파일 다운로드1
10995정성태6/27/201620843VS.NET IDE: 109. Visual Studio 유료 버전 사용자의 주기적인 온라인 인증을 없애는 방법
10994정성태6/23/201620259개발 환경 구성: 285. 알고스팟(https://algospot.com)을 위한 Visual C++ 답안 작성 요령파일 다운로드1
10993정성태6/23/201621059.NET Framework: 597. 닷넷 메타데이터에 struct/class(값/참조 형식)의 구분이 있을까요?
10992정성태6/13/201618272오류 유형: 339. vbs 스크립트 실행 시 항상 실행 여부를 묻는 질문 창이 뜬다면?
10991정성태6/13/201622525오류 유형: 338. octave-gui 실행 시 "octave-gui.exe has stopped working" 오류
10990정성태6/13/201624076오류 유형: 337. missing type specifier - [type] assumed. Note: C++ does not support default-[type]
10989정성태6/7/201620521.NET Framework: 596. C# - WCF wsDualHttpBinding의 ClientBaseAddress 속성 - 두 번째 이야기
10988정성태6/3/201621497기타: 57. Outlook blocked access to the following potentially unsafe attachments
10987정성태6/2/201622547.NET Framework: 595. XLL 파일에 포함된 .NET 어셈블리를 추출하는 방법
10986정성태6/1/201622999.NET Framework: 594. C# - WCF wsDualHttpBinding의 ClientBaseAddress 속성
10985정성태6/1/201621539오류 유형: 336. An error occurred while ejecting 'DVD RW drive ...'
10984정성태5/31/201627193.NET Framework: 593. C# - wsDualHttpBinding WCF 예제 프로그램파일 다운로드1
10983정성태5/30/201621362VC++: 97. C++ 템플릿 remove_pointer, enable_if, is_pointer 사용 예제파일 다운로드1
10982정성태5/26/201619690오류 유형: 335. SQL Server Management Studio - The database ... is not accessible.
10981정성태5/24/201624739.NET Framework: 592. C# - Lights Out 퍼즐 풀기 [2]파일 다운로드1
10980정성태5/24/201621990VS.NET IDE: 108. Visual Studio 2013/2015를 위한 "Macros for Visual Studio"
10979정성태5/23/201625256.NET Framework: 591. C# - 조합(Combination) 예제 코드 - 두 번째 이야기파일 다운로드1
10978정성태5/23/201623872.NET Framework: 590. C# - 모든 경우의 수를 조합하는 코드 (2)파일 다운로드1
10977정성태5/23/201628331.NET Framework: 589. C# - 모든 경우의 수를 조합하는 코드 (1)파일 다운로드1
10976정성태5/20/201622720Math: 18. C# - 오일러 공식을 이용한 복소수 값의 라디안 회전파일 다운로드1
10975정성태5/20/201623113Math: 17. C# - 복소수 타입의 승수를 지원하는 Power 메서드파일 다운로드1
10974정성태5/20/201623670.NET Framework: 588. C# - OxyPlot 라이브러리로 복소수 표현파일 다운로드1
... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...