0

@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

0 Answers0