0

So basically I have an app that uses selenium and seleniumwire to do some stuff. I'm using chromedriver. The installed chrome version (91.0.4472.114) and webdriver version (91.0.4472.101) are basically the same. When I'm starting the app with the terminal by issuing the command:

gunicorn --workers 3 --bind 0.0.0.0:5000 wsgi:create_app\(\) --preload

Everything works fine. But when I'm trying to use systemd to launch the app in the background I get the error I mentioned in the title (DevToolsActivePort file doesn't exist).

My systemd unit file:

[Unit]
Description=Gunicorn instance to serve some app
After=network.target

[Service]
User=myuser
Group=www-data
WorkingDirectory=/home/myuser/path-to-my-app
Environment="PATH=/home/myuser/path-to-my-app/venv/bin"
ExecStart=/home/myuser/path-to-my-app/venv/bin/gunicorn --workers 3 --bind unix:myapp.sock -m 007 wsgi:create_app() --preload

[Install]
WantedBy=multi-user.target

My chromedriver options:

user_agent = 'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0'
options_args = [
    f'user-agent={user_agent}',
    '--window-size=1920,1080',
    '--ignore-certificate-errors',
    '--allow-running-insecure-content',
    '--disable-extensions',
    '--start-maximized',
    '--disable-gpu',
    '--disable-dev-shm-usage',
    '--no-sandbox'
]

options = webdriver.ChromeOptions()
options.headless = True

for arg in options_args:
    options.add_argument(arg)

I tried all the solutions I could find on SO (mainly this) and other websites (which include setting the --no-sandbox and --disable-dev-shm-usage options) but without any luck. Also, setting --remote-debugging-port=xxx didn't help.

As a workaround, I'm currently using nohup to keep the app running after I quit SSH session but this is an unacceptable solution for me.

I know that this question is probably a duplicate but I couldn't find any solution that works for me. I'm happy to include all the details you need to solve this problem.

gribvirus74
  • 755
  • 6
  • 20
  • Were you able to resolve this issue? I am having the exact same problem, although I am using uWSGI rather than gunicorn. Still I am having the same experience. Please let me know. – vsapountzis Oct 27 '21 at 19:27
  • Unfortunately, I haven't. But I've managed to get this to work in some other (dirty) way. Basically, I have several bots that use selenium and they don't need to be accessible in the main app nor the app needs to have access to them. The only way those parties are communicating with each other is the database and redis. So I made another systemd service to fire up those bots with `subprocess` and then kill them all when the main app exits with some `pgrep` magic. I know it's not the best solution but it's working for 3 months now without any problems so I guess it's a good one after all. – gribvirus74 Oct 28 '21 at 15:37

0 Answers0