[Rails] fork/exec /bin/app/rails: no such file or directory

I need to go to “Rails console”
$ flyctl ssh console -C “/bin/app/rails console”

show:
Connecting to top1.nearest.of.*****.internal… complete
fork/exec /bin/app/rails: no such file or directory

please help me thanks :worried:

Did you use fly launch to create the Rails app? If so I think that path is a bit off; See this doc:

I think path would be more like app/bin/rails <subcommand>

1 Like

I don’t know your app path, maybe /app/bin/rails console ?

1 Like

@jphenow

Maybe this path needs to be changed?


Path problem has been solved
but a new situation

Connecting to top1.nearest.of.*****.internal... complete
fork/exec /app/bin/rails: permission denied

please help thank you

I usually use flyctl ssh console to connect ssh then execute the command.

Use whoami to check username and ls -l /app/bin/rails to check execute file permission.

$ flyctl ssh console
Connecting to top1.nearest.of.*****.internal... complete
# ls -l /app/bin/rails
-rw-r--r-- 1 1001 121 145 Sep  1 15:03 /app/bin/rails
# whoami
root

@chloerei How to change permissions?
please help thank you

Not familiar with the rails Dockerfile, but a workaround could be adding this line to it

RUN chmod 755 /app/bin/rails
1 Like

bin/rails script need execute permission, use

chmod +x /app/bin/rails

to add execute permision.

If it works, run chmod +x bin/rails in your local project directory and commit to permanently fix this issue.

Scripts in bin directory all have execute permission by default.

1 Like

@chloerei @tj1 @jphenow
thank you for the help

I have successfully opened permissions
But I encountered a new situation
An error occurred:
/usr/bin/env: 'ruby.exe': No such file or directory

if I delete the following paragraph
bin\rails :
#!/usr/bin/env ruby.exe
An error occurred:
fork/exec /app/bin/rails: exec format error

please help thank you

Change to:

#!/usr/bin/env ruby

Are you develop on windows? Differences between development and production environments can cause many problems. I recommend use WSL2 or Docker to run a linux environment.

1 Like

@chloerei i use windows OS

Loading production environment (Rails 6.1.6.1)
irb(main):001:0>

amazing!
You are amazing!!
Thanks for your help!!! :kissing_heart:

@jedi - glad you are up and running! I’ve fixed the docs.

The changes you made will be undone the next time you deploy. Try adding the following to your Dockerfile so that the changes will be applied for you automatically each time you deploy:

sed -i 's/ruby.exe/ruby/' app/bin/*
chmod +x app/bin/*

Place these lines immediately after the COPY . . line. I’ll modify flyctl to do this automatically going forward, and that will change will be available within a few days.

1 Like

@rubys


image

Unable to deploy after changes :joy:

Oops! Sorry about that. Add the word RUN before each of those lines:

RUN sed -i 's/ruby.exe/ruby/' app/bin/*
RUN chmod +x app/bin/*

RUN sed -i 's/ruby.exe/ruby/' app/bin/*
RUN chmod +x app/bin/*

@rubys
Still can’t deploy :sweat_smile:

Eek! Need more coffee. Since this is after the WORKDIR line earlier in the Dockerfile, the file names need to be either relative to the WORKDIR or be absolute. Let’s make them absolute:

RUN sed -i 's/ruby.exe/ruby/' /app/bin/*
RUN chmod +x /app/bin/*
1 Like

@rubys

Set up successfully !! thank you :+1:

But I’m having trouble again…

The following cannot be used :

flyctl ssh console -c "/app/bin/rails db:migrate"
flyctl ssh console -c "/app/bin/rails db:rollback"

The following can be used :

flyctl ssh console -C "/app/bin/rails console"
flyctl ssh console -C "/app/bin/rails help"

please help thank you :face_with_spiral_eyes:

The option needs to be an uppercase -C.

Adding another line to your Dockerfile may help. I’ve cleaned it up and tested it this time:

RUN chmod +x /app/bin/* && \
    sed -i 's/ruby.exe/ruby/' /app/bin/* && \
    sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*

Hope this gets you up an running! If you continue to have problems, can you paste the contents of your bin/rails file?

1 Like

I noticed this error in the guide as well, I made a PR:

1 Like

@rubys

you are an amazing magician :tada:
According to your parameter changes, all commands can be successfully executed! !

Thank you very much for your assistance! :+1:

Content you need: (bin\rails)

#!/usr/bin/env ruby.exe
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative "../config/boot"
require "rails/commands"