Port 8000 is in use by another program. Either identify and stop that program, or start the server

Bench restart gives below result.

bench restart
$ sudo supervisorctl restart frappe-bench-web:
frappe-bench-web:frappe-bench-frappe-web: stopped
frappe-bench-web:frappe-bench-frappe-web: started
$ sudo supervisorctl restart frappe-bench-workers:
frappe-bench-workers:frappe-bench-frappe-schedule: stopped
frappe-bench-workers:frappe-bench-frappe-short-worker-0: stopped
frappe-bench-workers:frappe-bench-frappe-long-worker-0: stopped
frappe-bench-workers:frappe-bench-frappe-schedule: started
frappe-bench-workers:frappe-bench-frappe-short-worker-0: started
frappe-bench-workers:frappe-bench-frappe-long-worker-0: started
INFO: A newer version of bench is available: 5.22.3 → 5.22.8
sigma@Design1:~/frappe-bench$

bench start gives below result.

bench start
19:45:26 system | redis_cache.1 started (pid=24253)
19:45:26 redis_cache.1 | 24258:C 21 Aug 2024 19:45:26.407 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19:45:26 redis_cache.1 | 24258:C 21 Aug 2024 19:45:26.407 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=24258, just started
19:45:26 redis_cache.1 | 24258:C 21 Aug 2024 19:45:26.407 # Configuration loaded
19:45:26 system | redis_queue.1 started (pid=24256)
19:45:26 redis_cache.1 | 24258:M 21 Aug 2024 19:45:26.408 * Increased maximum number of open files to 10032 (it was originally set to 1024).
19:45:26 system | web.1 started (pid=24259)
19:45:26 redis_cache.1 | 24258:M 21 Aug 2024 19:45:26.409 * Running mode=standalone, port=13000.
19:45:26 redis_cache.1 | 24258:M 21 Aug 2024 19:45:26.410 # Server initialized
19:45:26 redis_cache.1 | 24258:M 21 Aug 2024 19:45:26.410 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
19:45:26 redis_cache.1 | 24258:M 21 Aug 2024 19:45:26.410 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo madvise > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to ‘madvise’ or ‘never’).
19:45:26 system | socketio.1 started (pid=24264)
19:45:26 system | watch.1 started (pid=24267)
19:45:26 redis_queue.1 | 24261:C 21 Aug 2024 19:45:26.418 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19:45:26 redis_queue.1 | 24261:C 21 Aug 2024 19:45:26.418 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=24261, just started
19:45:26 redis_queue.1 | 24261:C 21 Aug 2024 19:45:26.418 # Configuration loaded
19:45:26 redis_cache.1 | 24258:M 21 Aug 2024 19:45:26.419 * Ready to accept connections
19:45:26 redis_queue.1 | 24261:M 21 Aug 2024 19:45:26.423 * Increased maximum number of open files to 10032 (it was originally set to 1024).
19:45:26 redis_queue.1 | 24261:M 21 Aug 2024 19:45:26.429 * Running mode=standalone, port=11000.
19:45:26 redis_queue.1 | 24261:M 21 Aug 2024 19:45:26.429 # Server initialized
19:45:26 redis_queue.1 | 24261:M 21 Aug 2024 19:45:26.429 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.
19:45:26 redis_queue.1 | 24261:M 21 Aug 2024 19:45:26.429 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo madvise > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to ‘madvise’ or ‘never’).
19:45:26 redis_queue.1 | 24261:M 21 Aug 2024 19:45:26.431 * Ready to accept connections
19:45:26 system | schedule.1 started (pid=24274)
19:45:26 system | worker.1 started (pid=24270)
19:45:27 watch.1 |
19:45:27 web.1 | Address already in use
19:45:27 web.1 | Port 8000 is in use by another program. Either identify and stop that program, or start the server with a different port.
19:45:27 system | web.1 stopped (rc=1)
19:45:27 system | sending SIGTERM to redis_cache.1 (pid 24253)
19:45:27 system | sending SIGTERM to redis_queue.1 (pid 24256)
19:45:27 system | sending SIGTERM to socketio.1 (pid 24264)
19:45:27 system | sending SIGTERM to watch.1 (pid 24267)
19:45:27 system | sending SIGTERM to schedule.1 (pid 24274)
19:45:27 system | sending SIGTERM to worker.1 (pid 24270)
19:45:27 system | worker.1 stopped (rc=-15)
19:45:27 redis_cache.1 | 24258:signal-handler (1724249727) Received SIGTERM scheduling shutdown…
19:45:27 redis_queue.1 | 24261:signal-handler (1724249727) Received SIGTERM scheduling shutdown…
19:45:27 redis_queue.1 | 24261:M 21 Aug 2024 19:45:27.338 # User requested shutdown…
19:45:27 redis_queue.1 | 24261:M 21 Aug 2024 19:45:27.338 * Removing the pid file.
19:45:27 redis_queue.1 | 24261:M 21 Aug 2024 19:45:27.338 # Redis is now ready to exit, bye bye…
19:45:27 system | watch.1 stopped (rc=-15)
19:45:27 system | schedule.1 stopped (rc=-15)
19:45:27 system | redis_queue.1 stopped (rc=-15)
19:45:27 system | socketio.1 stopped (rc=-15)
19:45:27 redis_cache.1 | 24258:M 21 Aug 2024 19:45:27.423 # User requested shutdown…
19:45:27 redis_cache.1 | 24258:M 21 Aug 2024 19:45:27.423 * Removing the pid file.
19:45:27 redis_cache.1 | 24258:M 21 Aug 2024 19:45:27.423 # Redis is now ready to exit, bye bye…
19:45:27 system | redis_cache.1 stopped (rc=-15)

We are unable to start our site at all suddenly, Kindly help.
This ERPNext installation has been done in WSL(Windows).

Hi @Sohailans:

Use this:
kill $(lsof -t -i :8000)

Maybe other ports (11000, 12000, 13000 … would be in use, so repeat it for each one)

Check this too, it’s really useful.

Hope this helps.

Thanks for the suggestion, one question pls - our erpnext instance is prev version 14, I think, we could not update due to some core changes.
So hope this Stop Bench script will not be conflicting with the prev versions?

Thanks so much.

Pls check the results below of the Stop Bench.

~/frappe-bench$ python3 stop.py
11000/tcp: 2472
Port 12000 already closed
13000/tcp: 2495
Port 9000 already closed
8000/tcp: 1613 1620 1622 1623 1624 1625 1627 1628 1629 1630
bench stopped

~/frappe-bench$ bench start
11:22:16 system | redis_cache.1 started (pid=2678)
11:22:16 system | redis_queue.1 started (pid=2681)
11:22:16 system | socketio.1 started (pid=2689)
11:22:16 redis_cache.1 | 2683:C 22 Aug 2024 11:22:16.097 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11:22:16 redis_cache.1 | 2683:C 22 Aug 2024 11:22:16.097 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=2683, just started
11:22:16 redis_cache.1 | 2683:C 22 Aug 2024 11:22:16.097 # Configuration loaded
11:22:16 redis_cache.1 | 2683:M 22 Aug 2024 11:22:16.098 * Increased maximum number of open files to 10032 (it was originally set to 1024).
11:22:16 redis_cache.1 | 2683:M 22 Aug 2024 11:22:16.098 # Could not create server TCP listening socket 127.0.0.1:13000: bind: Address already in use
11:22:16 system | redis_cache.1 stopped (rc=1)
11:22:16 system | watch.1 started (pid=2693)
11:22:16 redis_queue.1 | 2687:C 22 Aug 2024 11:22:16.101 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11:22:16 system | web.1 started (pid=2685)
11:22:16 system | schedule.1 started (pid=2690)
11:22:16 redis_queue.1 | 2687:C 22 Aug 2024 11:22:16.102 # Redis version=6.0.16, bits=64, commit=00000000, modified=0, pid=2687, just started
11:22:16 redis_queue.1 | 2687:C 22 Aug 2024 11:22:16.102 # Configuration loaded
11:22:16 redis_queue.1 | 2687:M 22 Aug 2024 11:22:16.102 * Increased maximum number of open files to 10032 (it was originally set to 1024).
11:22:16 redis_queue.1 | 2687:M 22 Aug 2024 11:22:16.103 # Could not create server TCP listening socket 127.0.0.1:11000: bind: Address already in use
11:22:16 system | redis_queue.1 stopped (rc=1)
11:22:16 system | worker.1 started (pid=2700)
11:22:16 system | sending SIGTERM to web.1 (pid 2685)
11:22:16 system | sending SIGTERM to socketio.1 (pid 2689)
11:22:16 system | sending SIGTERM to watch.1 (pid 2693)
11:22:16 system | sending SIGTERM to schedule.1 (pid 2690)
11:22:16 system | sending SIGTERM to worker.1 (pid 2700)
11:22:16 system | worker.1 stopped (rc=-15)
11:22:16 system | web.1 stopped (rc=-15)
11:22:16 system | socketio.1 stopped (rc=-15)
11:22:16 system | watch.1 stopped (rc=-15)
11:22:16 system | schedule.1 stopped (rc=-15)

~/frappe-bench$ bench restart
$ sudo supervisorctl restart frappe-bench-web:
frappe-bench-web:frappe-bench-frappe-web: stopped
frappe-bench-web:frappe-bench-frappe-web: started
$ sudo supervisorctl restart frappe-bench-workers:
frappe-bench-workers:frappe-bench-frappe-schedule: stopped
frappe-bench-workers:frappe-bench-frappe-short-worker-0: stopped
frappe-bench-workers:frappe-bench-frappe-long-worker-0: stopped
frappe-bench-workers:frappe-bench-frappe-schedule: started
frappe-bench-workers:frappe-bench-frappe-short-worker-0: started
frappe-bench-workers:frappe-bench-frappe-long-worker-0: started
INFO: A newer version of bench is available: 5.22.3 → 5.22.8

Still the same problem, erpnext is not getting started.

Also even after Bench Stop command, supervisorctl status shows that many processes are still running.
:~/frappe-bench$ sudo supervisorctl status
frappe-bench-redis:frappe-bench-redis-cache RUNNING pid 6248, uptime 0:01:35
frappe-bench-redis:frappe-bench-redis-queue RUNNING pid 6222, uptime 0:01:38
frappe-bench-web:frappe-bench-frappe-web RUNNING pid 6271, uptime 0:01:31
frappe-bench-workers:frappe-bench-frappe-long-worker-0 RUNNING pid 6102, uptime 0:02:01
frappe-bench-workers:frappe-bench-frappe-schedule RUNNING pid 6099, uptime 0:02:01
frappe-bench-workers:frappe-bench-frappe-short-worker-0 RUNNING pid 6101, uptime 0:02:01

Hi @Sohailans:

Just noticed that you are in a production scenario … so bench start is not needed. Supervisor manage the services and start them automatically. And seems it’s running properly.

Can you access to your site and apps?

We are unable to connect to our site at all.

Hi @Sohailans:

Are you using WSL?

yes its WSL

We tried this command and can you see the error, pls suggest, thanks in adv

/frappe-bench$ sudo bench setup production sigma
Setting Up prerequisites…
Setting Up supervisor…
supervisor.conf already exists and this will overwrite it. Do you want to continue? [y/N]: y
Setting Up NGINX…
nginx.conf already exists and this will overwrite it. Do you want to continue? [y/N]: n
Setting Up symlinks and reloading services…
$ /usr/bin/supervisorctl reread
No config updates to processes
$ /usr/bin/supervisorctl update
$ sudo /usr/sbin/nginx -t
nginx: [emerg] unknown log format “main” in /etc/nginx/conf.d/frappe-bench.conf:101
nginx: configuration file /etc/nginx/nginx.conf test failed
ERROR: sudo /usr/sbin/nginx -t
subprocess.CalledProcessError: Command ‘sudo /usr/sbin/nginx -t’ returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/local/bin/bench”, line 8, in
sys.exit(cli())
File “/usr/local/lib/python3.10/dist-packages/bench/cli.py”, line 132, in cli
bench_command()
File “/usr/local/lib/python3.10/dist-packages/bench/commands/setup.py”, line 108, in setup_production
setup_production(user=user, yes=yes)
File “/usr/local/lib/python3.10/dist-packages/bench/config/production_setup.py”, line 87, in setup_production
reload_nginx()
File “/usr/local/lib/python3.10/dist-packages/bench/config/production_setup.py”, line 205, in reload_nginx
exec_cmd(f"sudo {which(‘nginx’)} -t")
File “/usr/local/lib/python3.10/dist-packages/bench/utils/init.py”, line 158, in exec_cmd
raise CommandFailedError(cmd) from subprocess.CalledProcessError(return_code, cmd)
bench.exceptions.CommandFailedError: sudo /usr/sbin/nginx -t

INFO: A newer version of bench is available: 5.19.0 → 5.22.8

We followed this link : Unknown log format "main" - Nginx - Code with Karani

The below command was giving the error.

:~/frappe-bench$ sudo nginx -t
nginx: [emerg] unknown log format “main” in /etc/nginx/conf.d/frappe-bench.conf:101
nginx: configuration file /etc/nginx/nginx.conf test failed
sigma@Design1:~/frappe-bench$ cd sites

We followed the steps in the above link and it got resolved.
then we restarted the Bench and site started working.

Thanks to AVC and Karani.
All suggestions highly appreciated.

2 Likes

Hi @Sohailans

Anyway check your bench and frappe version. This issue has been fixed months/years ago …

1 Like