ctxis / SnitchDNS

Database Driven DNS Server with a Web UI

Home Page:https://www.contextis.com/en/resources/tools/snitchdns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No such file or directory: 'which'

rwjack opened this issue · comments

Uhhhhhh, not sure how this is happening, but it seems flask is not picking up the vanilla env variables.

The following shows up in the Web UI upon logging into the admin account:

This clearly isn't working. We need a break.

Error Description
[Errno 2] No such file or directory: 'which'
Traceback (most recent call last):
File "/opt/snitch/venv/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/snitch/venv/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/opt/snitch/app/controllers/auth.py", line 131, in login_process
system.run_updates()
File "/opt/snitch/app/lib/base/system.py", line 45, in run_updates
self.__update_git_hash_version()
File "/opt/snitch/app/lib/base/system.py", line 49, in __update_git_hash_version
git_binary = self.shell.execute(['which', 'git'])
File "/opt/snitch/app/lib/base/shell.py", line 16, in execute
return self.__execute(command, wait)
File "/opt/snitch/app/lib/base/shell.py", line 20, in __execute
return subprocess.run(command, stdout=subprocess.PIPE).stdout.decode().strip()
File "/usr/lib/python3.9/subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.9/subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'which'

systemctl status snitchdns:
Notice the /usr/bin/env: 'bash': No such file or directory near the end

snitchdns.service - SnitchDNS Gunicorn
     Loaded: loaded (/opt/snitch/data/config/service/snitchdns.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-02-25 14:05:13 CET; 6min ago
    Process: 2309667 ExecStartPost=/opt/snitch/venv/bin/python3 -m flask snitch_start (code=exited, status=0/SUCCESS)
   Main PID: 2309666 (gunicorn)
      Tasks: 4 (limit: 1100)
     Memory: 184.1M
        CPU: 3.046s
     CGroup: /system.slice/snitchdns.service
             ├─2309666 /opt/snitch/venv/bin/python3 /opt/snitch/venv/bin/gunicorn --workers 3 --bind 12.0.0.2:8080 -m 007 wsg>
             ├─2309668 /opt/snitch/venv/bin/python3 /opt/snitch/venv/bin/gunicorn --workers 3 --bind 12.0.0.2:8080 -m 007 wsg>
             ├─2309669 /opt/snitch/venv/bin/python3 /opt/snitch/venv/bin/gunicorn --workers 3 --bind 12.0.0.2:8080 -m 007 wsg>
             └─2309670 /opt/snitch/venv/bin/python3 /opt/snitch/venv/bin/gunicorn --workers 3 --bind 12.0.0.2:8080 -m 007 wsg>

Feb 25 14:05:06 ho-dns systemd[1]: Starting SnitchDNS Gunicorn...
Feb 25 14:05:06 ho-dns gunicorn[2309666]: [2022-02-25 14:05:06 +0100] [2309666] [INFO] Starting gunicorn 20.1.0
Feb 25 14:05:06 ho-dns gunicorn[2309666]: [2022-02-25 14:05:06 +0100] [2309666] [INFO] Listening at: http://12.0.0.2:8080 (23>
Feb 25 14:05:06 ho-dns gunicorn[2309666]: [2022-02-25 14:05:06 +0100] [2309666] [INFO] Using worker: sync
Feb 25 14:05:06 ho-dns gunicorn[2309668]: [2022-02-25 14:05:06 +0100] [2309668] [INFO] Booting worker with pid: 2309668
Feb 25 14:05:06 ho-dns gunicorn[2309669]: [2022-02-25 14:05:06 +0100] [2309669] [INFO] Booting worker with pid: 2309669
Feb 25 14:05:07 ho-dns gunicorn[2309670]: [2022-02-25 14:05:07 +0100] [2309670] [INFO] Booting worker with pid: 2309670
Feb 25 14:05:08 ho-dns python3[2309671]: /usr/bin/env: ‘bash’: No such file or directory
Feb 25 14:05:13 ho-dns python3[2309667]: SnitchDNS - Starting daemon...
Feb 25 14:05:13 ho-dns systemd[1]: Started SnitchDNS Gunicorn.

/etc/systemd/system/snitchdns.service:

[Unit]
Description=SnitchDNS Gunicorn
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=30

[Service]
Restart=always
RestartSec=30
User=www-data
Group=www-data
WorkingDirectory=/opt/snitch
EnvironmentFile=/etc/environment
EnvironmentFile=/opt/snitch/data/config/env/snitch.conf
Environment="PATH=/opt/snitch/venv/bin:$PATH"
#ExecStart=/opt/snitch/venv/bin/gunicorn --workers 3 --bind 12.0.0.2:8080 --certfile=/opt/snitch/data/config/http/gunicorn.crt --keyfile=/opt/snitch/data/config/http/gunicorn.pem -m 007 wsgi:app
ExecStart=/opt/snitch/venv/bin/gunicorn --workers 3 --bind 12.0.0.2:8080 -m 007 wsgi:app
ExecStartPost=/opt/snitch/venv/bin/python3 -m flask snitch_start

[Install]
WantedBy=multi-user.target

Thanks for reporting this.

Are you running this on Debian by any chance? Can you check if /etc/environment is empty and if /etc/profile is setting the PATH instead? If that's the case, you can update EnvironmentFile=/etc/environment to point to /etc/profile and restart the service.

Good call on that one.
Yeah it's running on debian, I had some other issues before which required an environment file so it existed, but was empty.
The UI seems to be working now that the systemd unit is changed.

Excellent, I'll close this issue then - if anything else comes up please create a new one. Thanks.