Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How to perform a rake task after startup?

Writer 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:backup

which 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
fi

at the beginning of the script.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy