railway shellimmediately closes (trying to run
createsuperuserfor Django Project)
5 months ago
Hi team!
I'm having trouble accessing the shell for my Django server via the railway shell
CLI command: https://docs.railway.com/reference/cli-api#shell
I've logged in, linked to the project, selected the service, and it seems to open the shell but then closes after just a couple of seconds without doing anything else:
****@MacBookPro ~ % railway shell
Entering subshell with Railway variables available. Type 'exit' to exit.
****@MacBookPro ~ %
For some context, this comes up as I'm trying to add an admin user to my Django
App deployment wity: python manage.py createsuperuser
I've also tried the railway run
CLI command with railway run python manage.py createsuperuser
, but I then just get:
***@MacBookPro ~ % railway run python manage.py createsuperuser
No such file or directory (os error 2)
4 Replies
5 months ago
Hello,
You would indeed be in the shell, it is a local shell so it's going to use the same shell process as the parent shell.
Same with railway run
it runs commands locally with the linked service variables available, so you would need python installed locally and run the commands from within your project folder.
https://docs.railway.com/reference/cli-api#shell
https://docs.railway.com/reference/cli-api#run
Best,
Brody
Status changed to Awaiting User Response Railway • 6 months ago
5 months ago
Hey Brody, thanks for getting back to me so quickly!
Apologies if I'm being a little slow with understanding: so railway shell
will only let you run a shell locally with the same environment variables used in the app you've deployed, but not a shell on the actual server being used to host that app on Railway - is that correct?
What I'm looking for is something similar to using an admin console or SSH on the actual app server. Is that possible?
Status changed to Awaiting Railway Response Railway • 5 months ago
5 months ago
Hello,
That is correct! local only shell with your service variables available.
Unfortunately we do not provide a way for you to get a shell into a deployment... yet, but it is planned to be released by the end of the current quarter!
Please upvote this thread so that you can be notified when we ship the feature! -
https://help.railway.com/feedback/allow-ssh-access-to-containers-via-cli-e4985f6f
Best,
Brody
Status changed to Awaiting User Response Railway • 5 months ago
5 months ago
Thanks Brody.
but it is planned to be released by the end of the current quarter!
That's awesome to hear. This'd be super useful.
PS. For anyone else reading this and wondering how to use the python manage.py createsuperuser --no-input
command for their Django app in the meantime, I found two workarounds. Either:
Add it to the Pre-deploy Command under the app server settings, ensuring you set the super user credentials as environment variables on your app server
Add it to the start command string in your
railway.json
file (also making sure you set your env variables)
Status changed to Awaiting Railway Response Railway • 5 months ago
Status changed to Solved brody • 5 months ago