Score:0

What is the correct shell path to export in .profile for Mastodon and Rails?

pw flag

@steeldriver's answer to In a bash script, how do I change from root user to another user using su and then exit? works great for using sudo and su in a bash script, but a new issue has to do with the Rails path in the .profile file.

I'm running Mastodon and am trying to use a shell script to run all the different Rails commands and restart mastodon after changing files. Running all of the commands manually outside of the script works fine.

But in the script, the three Rails commands all throw the error bundle: command not found, even while the rest of the shell script runs and completes:

#!/bin/bash

sudo su -l mastodon -c '
  cd live
  RAILS_ENV=production bundle exec rake tmp:cache:clear
  RAILS_ENV=production bundle exec rails assets:generate_static_pages
  RAILS_ENV=production bundle exec rails assets:precompile
  exit
'
systemctl restart mastodon-*

I've added export RAILS_ENV=production to ~/.profile with no luck.

What is the correct path to export for Rails so that the commands will execute?

This could be related to this: "Mastodon default settings not sensibly usable, mastodon not a login user" https://github.com/NixOS/nixpkgs/issues/199029

Or is this a different issue?

~/.profile:

# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n 2> /dev/null || true

export RAILS_ENV=production
hr flag
Is the `bundle` command found when your in the `root` shell (before switching to user `madison`)? If so, a good starting point would be the outputs of `type -a bundle` and/or `which bundle` in that shell
BlueDogRanch avatar
pw flag
I should have thought of that :) bundle isn't in root shell, but when in the mastodon user shell, `type -a bundle` shows `bundle is /home/mastodon/.rbenv/shims/bundle`. So I added `export PATH="$HOME/.rbenv/shims/bundle:$PATH"` to .profile but still get the error.
hr flag
`PATH` should contain directories containing commands, not commands themselves. If you're having trouble finding the right place to put it, one option is to set `PATH="$PATH:$HOME/.rbenv/shims"` *inside* the `-c` argument
BlueDogRanch avatar
pw flag
Ok, using `sudo su -l mastodon -c PATH="$PATH:$HOME/.rbenv/shims" ' cd live ...` doesn't throw the error, but it blows by and doesn't execute the rails commands.
hr flag
No that's not right either, you'd want `sudo su -l mastodon -c 'PATH="$PATH:$HOME/.rbenv/shims"; cd live; ...'`
BlueDogRanch avatar
pw flag
That works! I didn't realize I now needed to add `;` after each command with path inside the c command. Add that as an answer.
hr flag
You need *some* kind of separator - the newlines in as posted in your question are equivalent.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.