리모트 서버에서 selenium 실행 실패
리눅스 서버에서 Python+Selenium 으로 주기적으로 돌아가는 작업을 만들어 두었다. 그런데 꽤나 아리송한 문제가 생긴다.
로그는 대충 아래와 같음.
(Message: session not created: Chrome failed to start: exited normally.
(chrome not reachable)
(The process started from chrome location /snap/어쩌고저쩌고/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x55c11185ad93 <unknown>
작업 서버는
로그를 더 상세하게 찍어보려 했지만 유용한 정보는 없었다. syslog, process list 등을 보며 동작을 상세하게 관찰하면,
Feb 1 14:11:26 myserver systemd[1]: Starting User Manager for UID 1002...
Feb 1 14:11:26 myserver systemd[15411]: Queued start job for default target Main User Target.
Feb 1 14:11:26 myserver systemd[15411]: Created slice User Application Slice.
Feb 1 14:11:26 myserver systemd[15411]: Reached target Paths.
Feb 1 14:11:26 myserver systemd[15411]: Reached target Timers.
Feb 1 14:11:26 myserver systemd[15411]: Starting D-Bus User Message Bus Socket...
Feb 1 14:11:26 myserver systemd[15411]: Listening on GnuPG network certificate management daemon.
Feb 1 14:11:26 myserver systemd[15411]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers).
Feb 1 14:11:26 myserver systemd[15411]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
Feb 1 14:11:26 myserver systemd[15411]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
Feb 1 14:11:26 myserver systemd[15411]: Listening on GnuPG cryptographic agent and passphrase cache.
Feb 1 14:11:26 myserver systemd[15411]: Listening on debconf communication socket.
Feb 1 14:11:26 myserver systemd[15411]: Listening on REST API socket for snapd user session agent.
Feb 1 14:11:26 myserver systemd[15411]: Listening on D-Bus User Message Bus Socket.
Feb 1 14:11:26 myserver systemd[15411]: Reached target Sockets.
Feb 1 14:11:26 myserver systemd[15411]: Reached target Basic System.
Feb 1 14:11:26 myserver systemd[1]: Started User Manager for UID 1002.
Feb 1 14:11:26 myserver systemd[1]: Started Session 39 of User dgoon.
Feb 1 14:11:26 myserver systemd[15411]: Reached target Main User Target.
Feb 1 14:11:26 myserver systemd[15411]: Startup finished in 54ms.
Feb 1 14:11:02 myserver systemd[1]: session-38.scope: Deactivated successfully.
Feb 1 14:11:12 myserver systemd[1]: Stopping User Manager for UID 1002...
Feb 1 14:11:12 myserver systemd[1558]: Stopped target Main User Target.
Feb 1 14:11:12 myserver systemd[1558]: Stopped target Basic System.
Feb 1 14:11:12 myserver systemd[1558]: Stopped target Paths.
Feb 1 14:11:12 myserver systemd[1558]: Stopped target Sockets.
Feb 1 14:11:12 myserver systemd[1558]: Stopped target Timers.
Feb 1 14:11:12 myserver systemd[1558]: Closed D-Bus User Message Bus Socket.
Feb 1 14:11:12 myserver systemd[1558]: Closed GnuPG network certificate management daemon.
Feb 1 14:11:12 myserver systemd[1558]: Closed GnuPG cryptographic agent and passphrase cache (access for web browsers).
Feb 1 14:11:12 myserver systemd[1558]: Closed GnuPG cryptographic agent and passphrase cache (restricted).
Feb 1 14:11:12 myserver systemd[1558]: Closed GnuPG cryptographic agent (ssh-agent emulation).
Feb 1 14:11:12 myserver systemd[1558]: Closed GnuPG cryptographic agent and passphrase cache.
Feb 1 14:11:12 myserver systemd[1558]: Closed debconf communication socket.
Feb 1 14:11:12 myserver systemd[1558]: Closed REST API socket for snapd user session agent.
Feb 1 14:11:12 myserver systemd[1558]: Removed slice User Application Slice.
Feb 1 14:11:12 myserver systemd[1558]: Reached target Shutdown.
Feb 1 14:11:12 myserver systemd[1558]: Finished Exit the Session.
Feb 1 14:11:12 myserver systemd[1558]: Reached target Exit the Session.
Feb 1 14:11:12 myserver systemd[1]: user@1002.service: Deactivated successfully.
Feb 1 14:11:12 myserver systemd[1]: Stopped User Manager for UID 1002.
Feb 1 14:11:12 myserver systemd[1]: Stopping User Runtime Directory /run/user/[UID]...
Feb 1 14:11:12 myserver systemd[1]: run-user-1002.mount: Deactivated successfully.
Feb 1 14:11:12 myserver systemd[1]: user-runtime-dir@1002.service: Deactivated successfully.
Feb 1 14:11:12 myserver systemd[1]: Stopped User Runtime Directory /run/user/1002.
Feb 1 14:11:12 myserver systemd[1]: Removed slice User Slice of UID 1002.
Feb 1 14:11:12 myserver systemd[1]: user-1002.slice: Consumed 2.495s CPU time.
=> chromium 이 왜 /run/user/[UID] 에 나 실행하고 있어요 정보를 쓸까? 내가 ssh 연결을 끊으면(tmux 세션이 남아있다고 할지라도!!) 사라지는 디렉토리인데. 아무래도 저 디렉토리를 유지시켜주는게 systemd --user 인 것 같다. XDG_RUNTIME_DIR 환경변수가 정체인듯...
=> 혹시 /run/user/[UID] 디렉토리가 없어서 실행을 못하는건가? 디렉토리가 없어지면 자동으로 다시 만들게 해봄 -> 실패
=> systemd --user 는 누가 왜 실행하는거지? 관련 문서를 정독하며 여러가지 수동 실행을 해봤지만 -> 실패
=> chromium 이 /run/user/[UID] 말고 다른데를 쓰도록 환경변수를 줘 보려 했는데 -> 실패
=> ssh 로그인을 하는 동안에는 된다고? tmux 세션에서 ssh localhost 해두면? -> 구리지만 되긴 된다!? 하지만 엔지니어의 영혼이 이건 아니지 않냐며 눈물을 흘리는데...
=> tmux를 crontab @reboot 가 아니라 user-level systemd service 로 만들어봄 -> 실패
대체 왜 snap 으로 설치한 chromium 은 내가 ssh 로그인을 하고 있는 동안에만 실행이 되는 것인가.
=> 아 진짜 모르겠다. blame installed chromium. Snap으로 설치했던 chromium-browser를 제거하고 google 공식 데비안 패키지 받아서 설치후 시도 -> 잘됨
하... 하......
이 문제는 나보다 훌륭한 분이 깔끔하게 설명해주면 밥을 사드리는 것으로... 내가 지금까지 관측한걸 기반으로는, 그냥 blame package 하고 넘어가야겠다. snap 동작을 잘 모르겠네...
-----
덧: 구글 크롬 설치하기