Microsoft MVP성태의 닷넷 이야기
오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty [링크 복사], [링크+제목 복사],
조회: 6696
글쓴 사람
정성태 (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

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...
NoWriterDateCnt.TitleFile(s)
13626정성태5/15/202410494Phone: 15. C# MAUI - MediaElement Source 경로 지정 방법파일 다운로드1
13625정성태5/14/20249892닷넷: 2262. C# - Exception Filter 조건(when)을 갖는 catch 절의 IL 구조
13624정성태5/12/20249594Phone: 14. C# - MAUI에서 MediaElement 사용파일 다운로드1
13623정성태5/11/20249189닷넷: 2261. C# - 구글 OAuth의 JWT (JSON Web Tokens) 해석파일 다운로드1
13622정성태5/10/202410867닷넷: 2260. C# - Google 로그인 연동 (ASP.NET 예제)파일 다운로드1
13621정성태5/10/202410080오류 유형: 903. IISExpress - Failed to register URL "..." for site "..." application "/". Error description: Cannot create a file when that file already exists. (0x800700b7)
13620정성태5/9/20249499VS.NET IDE: 190. Visual Studio가 node.exe를 경유해 Edge.exe를 띄우는 경우
13619정성태5/7/202410103닷넷: 2259. C# - decimal 저장소의 비트 구조 [1]파일 다운로드1
13618정성태5/6/20249370닷넷: 2258. C# - double (배정도 실수) 저장소의 비트 구조파일 다운로드1
13617정성태5/5/202411007닷넷: 2257. C# - float (단정도 실수) 저장소의 비트 구조파일 다운로드1
13616정성태5/3/20249331닷넷: 2256. ASP.NET Core 웹 사이트의 HTTP/HTTPS + Dual mode Socket (IPv4/IPv6) 지원 방법파일 다운로드1
13615정성태5/3/202411021닷넷: 2255. C# 배열을 Numpy ndarray 배열과 상호 변환
13614정성태5/2/202410805닷넷: 2254. C# - COM 인터페이스의 상속 시 중복으로 메서드를 선언
13613정성태5/1/20249613닷넷: 2253. C# - Video Capture 장치(Camera) 열거 및 지원 포맷 조회파일 다운로드1
13612정성태4/30/202410560오류 유형: 902. Visual Studio - error MSB3021: Unable to copy file
13611정성태4/29/20249551닷넷: 2252. C# - GUID 타입 전용의 UnmanagedType.LPStruct - 두 번째 이야기파일 다운로드1
13610정성태4/28/202410467닷넷: 2251. C# - 제네릭 인자를 가진 타입을 생성하는 방법 - 두 번째 이야기
13609정성태4/27/202410493닷넷: 2250. PInvoke 호출 시 참조 타입(class)을 마샬링하는 [IN], [OUT] 특성파일 다운로드1
13608정성태4/26/202410904닷넷: 2249. C# - 부모의 필드/프로퍼티에 대해 서로 다른 자식 클래스 간에 Reflection 접근이 동작할까요?파일 다운로드1
13607정성태4/25/202410915닷넷: 2248. C# - 인터페이스 타입의 다중 포인터를 인자로 갖는 C/C++ 함수 연동
13606정성태4/24/202410856닷넷: 2247. C# - tensorflow 연동 (MNIST 예제)파일 다운로드1
13605정성태4/23/202412324닷넷: 2246. C# - Python.NET을 이용한 파이썬 소스코드 연동파일 다운로드1
13604정성태4/22/20249407오류 유형: 901. Visual Studio - Unable to set the next statement. Set next statement cannot be used in '[Exception]' call stack frames.
13603정성태4/21/202411163닷넷: 2245. C# - IronPython을 이용한 파이썬 소스코드 연동파일 다운로드1
13602정성태4/20/202410120닷넷: 2244. C# - PCM 오디오 데이터를 연속(Streaming) 재생 (Windows Multimedia)파일 다운로드1
13601정성태4/19/202410355닷넷: 2243. C# - PCM 사운드 재생(NAudio)파일 다운로드1
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...