Tengo un usuario que he agregado al grupo www-data . Tengo una configuración de servicio para ejecutar una API que inicia una instancia de Selenium. Puedo iniciar el código como mi usuario, pero la aplicación web no se inicia. Originalmente tuve problemas con Xvfb, pero después de agregar la ruta al entorno del archivo de servicio, se resolvió. Ahora tengo un problema similar con google-chrome que no se ejecuta.
Intenté agregar la ruta al entorno y cambiar los permisos en archivos y carpetas.
conferencia nginx
server { listen 443 ssl; root /usr/share/nginx/html; index index.html index.htm; server_name private; location / { proxy_pass http://127.0.0.1:8888; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } ssl_certificate /etc/letsencrypt/live/private/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/private/privkey.pem; # managed by Certbot } server { if ($host = private) { return 301 https://$host$request_uri; } # managed by Certbot listen 80 default_server; listen [::]:80 default_server; server_name private; return 404; # managed by Certbot } [Unit] Description=Gunicorn serving hrapi After=network.target [Service] User=artem Group=www-data WorkingDirectory=/home/artem/ucs Environment="PATH=/home/artem/env/bin:/usr/bin" ExecStart=/home/artem/env/bin/gunicorn --workers 3 --bind 127.0.0.1:8888 wsgi:app [Install] WantedBy=multi-user.target curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"fname": "ijay", "lname": "private", "addr": "private", "city": "scottsdale", "state":"AZ", "postal":"private", "ssn":"private"}' https://hrapi.domain.com/getreport Error:b'Traceback (most recent call last): File "/home/artem/ucs/get_report.py", line 158, in <module> b = UcsBot(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[7]) File "/home/artem/ucs/get_report.py", line 40, in __init__ self.driver = webdriver.Chrome(\'/home/artem/ucs/chromedriver\', chrome_options=options) File "/home/artem/env/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/home/artem/env/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/home/artem/env/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/home/artem/env/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/artem/env/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn\'t exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)Se supone que Selenium se inicia, y se inicia normalmente cuando ejecuto el script. Sin embargo, el script no se puede iniciar desde la API.
Además, me he asegurado de que mi Chrome y Chromedriver sean las versiones correctas. El script se ejecuta bien por sí mismo desde el usuario, como dije antes, pero no cuando se activa a través de la API.
Desde el registro detallado, parece que el problema sigue siendo los permisos como se sospecha. j
[1563464973.354][INFO]: Launching chrome: /usr/bin/google-chrome --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --load-extension=/tmp/.com.google.Chrome.rpiwaU/internal --log-level=0 --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.aQmopJ data:, /usr/bin/google-chrome: line 8: readlink: command not found /usr/bin/google-chrome: line 24: mkdir: command not found /usr/bin/google-chrome: line 45: exec: cat: not found /usr/bin/google-chrome: line 46: exec: cat: not found [1563464973.406][INFO]: [60f2bc8b762ce68091b9abc2d8476bf5] RESPONSE InitSession ERROR unknown error: Chrome failed to start: exited abnormally (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.) [1563464973.406][DEBUG]: Log type 'driver' lost 0 entries on destruction [1563464973.406][DEBUG]: Log type 'browser' lost 0 entries on destructionDespués de esto hice
sudo chown artem:www-data /usr/bin/google-chrome sudo chown artem:www-data /usr/bin/chromedriverSigue siendo el mismo problema.
# wsgi.py from api import app if __name__=="__main__": app.run()El script de inicio de Chrome /usr/bin/google-chrome tiene un problema, como lo indica /usr/bin/google-chrome: line 24: XXX: command not found :
[1563464973.354][INFO]: Launching chrome: /usr/bin/google-chrome [...] /usr/bin/google-chrome: line 8: readlink: command not found /usr/bin/google-chrome: line 24: mkdir: command not found /usr/bin/google-chrome: line 45: exec: cat: not found /usr/bin/google-chrome: line 46: exec: cat: not found Puede ser un problema simple $PATH , lo que significa que el servidor uWSGI no encuentra todos los comandos mencionados, readlink , etc. porque no tiene estos comandos dentro de la variable $PATH .
Advertencia: no permitiría que www-data acceda a todos los comandos XXX cambiando sus permisos, ¡esto sería un problema de seguridad importante en un servidor de producción!
En su lugar, sugiero mirar la siguiente pregunta SO: ¿Cómo corregir el error "usr/bin/google-chrome ya no se está ejecutando, por lo que ChromeDriver asume que Chrome se ha bloqueado" en Linux?
Alternativa : ¿Puedes resolver tu trabajo de alguna manera sin usar Chrome? ¿Cuáles son sus razones para iniciar un Chrome como servicio en un servidor web?
Agregue :/bin a su RUTA como se muestra a continuación:
Environment="PATH=/home/artem/env/bin:/usr/bin:/bin"
mkdir , readlink , etc. están en la ruta /bin que no está en la PATH modificada