The user sven2 seeks help executing Rails commands from the host Bash to automate user cleanup in a Discourse installation. They encounter Redis connection issues when using launcher run app and later face command execution errors with docker exec. pfaffman suggests using docker exec instead of launcher. supermathie clarifies that the issue stems from incorrect command quoting, explaining that rails console should be passed as a single argument and recommending rails runner for one-off commands. sven2 acknowledges the solution and thanks the community.
I want to execute automated user clean up tasks from the host Bash. Manually, I run
/var/discourse/launcher enter app
rails c
UserDestroyer.new(Discourse.system_user).destroy(User.find_by_username_or_email("user@example.com"), delete_posts: false)
I have a long list of user names from a text file that need to be removed. Manually executing this is not reasonable. I tried to wrap the deletion command in a bash script. When executing rails c with the launcher app subcommand, the Redis connection fails:
/var/discourse/launcher run app "echo \"User.find_by_username_or_email('user@example.com')\" | rails c"
Failed to report error: Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL) 2 Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL) subscribe failed, reconnecting in 1 second.
However, when I compare the environments with export between launcher enter app and launcher run app, they look pretty much identical. What am I missing? launcher run starts in / while launcher enter directly enters /var/www/discourse. Using a cd before executing rails does not help.
This is expected; you are telling docker to execute the binary /usr/local/bin/rails console in the container. That is, a single file with an embedded space. This file doesn’t exist.
consider the following:
○ → docker run -i debian /bin/echo hello
hello
○ → docker run -i debian '/bin/echo hello'
docker: Error response from daemon: OCI runtime create failed: container_linux.go:367: starting container process caused: exec: "/bin/echo hello": stat /bin/echo hello: no such file or directory: unknown.
ERRO[0000] error waiting for container: context canceled
Quote the command the same way as if you were executing from inside the container: