Microsoft MVP성태의 닷넷 이야기
오류 유형: 934. Azure - rm: cannot remove '...': Directory not empty [링크 복사], [링크+제목 복사],
조회: 2238
글쓴 사람
정성태 (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)
13861정성태1/11/2025455Windows: 276. 명령행에서 원격 서비스를 동기/비동기로 시작/중지
13860정성태1/10/2025509디버깅 기술: 216. WinDbg - 2가지 유형의 식 평가 방법(MASM, C++)
13859정성태1/9/2025596디버깅 기술: 215. Windbg - syscall 이후 실행되는 KiSystemCall64 함수 및 SSDT 디버깅
13858정성태1/8/2025656개발 환경 구성: 738. PowerShell - 원격 호출 시 "powershell.exe"가 아닌 "pwsh.exe" 환경으로 명령어를 실행하는 방법
13857정성태1/7/2025752C/C++: 187. Golang - 콘솔 응용 프로그램을 Linux 데몬 서비스를 지원하도록 변경파일 다운로드1
13856정성태1/6/2025815디버깅 기술: 214. Windbg - syscall 단계까지의 Win32 API 호출 (예: Sleep)
13855정성태12/28/20241435오류 유형: 941. Golang - os.StartProcess() 사용 시 오류 정리
13854정성태12/27/20241414C/C++: 186. Golang - 콘솔 응용 프로그램을 NT 서비스를 지원하도록 변경파일 다운로드1
13853정성태12/26/20241582디버깅 기술: 213. Windbg - swapgs 명령어와 (Ring 0 커널 모드의) FS, GS Segment 레지스터
13852정성태12/25/20241596디버깅 기술: 212. Windbg - (Ring 3 사용자 모드의) FS, GS Segment 레지스터파일 다운로드1
13851정성태12/23/20241514디버깅 기술: 211. Windbg - 커널 모드 디버깅 상태에서 사용자 프로그램을 디버깅하는 방법
13850정성태12/23/20241524오류 유형: 940. "Application Information" 서비스를 중지한 경우, "This file does not have an app associated with it for performing this action."
13849정성태12/20/20241558디버깅 기술: 210. Windbg - 논리(가상) 주소를 Segmentation을 거쳐 선형 주소로 변경
13848정성태12/18/20241784디버깅 기술: 209. Windbg로 알아보는 Prototype PTE파일 다운로드2
13847정성태12/18/20241676오류 유형: 939. golang - 빌드 시 "unknown directive: toolchain" 오류 빌드 시 이런 오류가 발생한다면?
13846정성태12/17/20241768디버깅 기술: 208. Windbg로 알아보는 Trans/Soft PTE와 2가지 Page Fault 유형파일 다운로드1
13845정성태12/16/20241958디버깅 기술: 207. Windbg로 알아보는 PTE (_MMPTE)
13844정성태12/14/20241833디버깅 기술: 206. Windbg로 알아보는 PFN (_MMPFN)파일 다운로드1
13843정성태12/13/20241869오류 유형: 938. Docker container 내에서 빌드 시 error MSB3021: Unable to copy file "..." to "...". Access to the path '...' is denied.
13842정성태12/12/20242264디버깅 기술: 205. Windbg - KPCR, KPRCB
13841정성태12/11/20242198오류 유형: 937. error MSB4044: The "ValidateValidArchitecture" task was not given a value for the required parameter "RemoteTarget"
13840정성태12/11/20241998오류 유형: 936. msbuild - Your project file doesn't list 'win' as a "RuntimeIdentifier"
13839정성태12/11/20241972오류 유형: 936. msbuild - error CS1617: Invalid option '12.0' for /langversion. Use '/langversion:?' to list supported values.
13838정성태12/4/20242244오류 유형: 935. Windbg - Breakpoint 0's offset expression evaluation failed.
13837정성태12/3/20242257디버깅 기술: 204. Windbg - 윈도우 핸들 테이블 (3) - Windows 10 이상인 경우
[1]  2  3  4  5  6  7  8  9  10  11  12  13  14  15  ...