How to perform a rake task after startup?
Mia Lopez
I'm using Rails, and I'd like to perform a specific rake task on boot. I've made a shell script like so:
cd /path/to/my/app
rake db:backupwhich is symlinked in /etc/rc2.d/. The problem is that the script is run as root which means it doesn't have access to rake (I'm using bundler and rvm). I'd like to change to my user for the script, but can't work out how to do that successfully.
So, is there a way to make this run as my account, or is there a better way to get the rake task run after startup?
1 Answer
Add something like
if [ "$(id -nu)" != 'your_user' ]; then exec sudo -u 'your_user' $0
fiat the beginning of the script.
5