Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following script which restarts god when I reboot my server (Ubuntu). How can I get god to start as the user "rails"?


# Provides:             god
# Required-Start:       $all
# Required-Stop:        $all
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    God


set -e

# Make sure the binary and the config file are present before proceeding
test -x /usr/bin/god || exit 0

# Create this file and put in a variable called GOD_CONFIG, pointing to
# your God configuration file
test -f /etc/default/god && . /etc/default/god
[ $GOD_CONFIG ] || exit 0

. /lib/lsb/init-functions


case "$1" in
    echo -n "Starting $DESC: "
    /bin/su rails -c '/usr/bin/god -c $GOD_CONFIG -P $PID -l $LOG'
    echo "$NAME."
    echo -n "Stopping $DESC: "
    kill `cat $PID`
    echo "$NAME."
    echo -n "Restarting $DESC: "
    kill `cat $PID`
    /bin/su rails -c '/usr/bin/god -c $GOD_CONFIG -P $PID -l $LOG'
    echo "$NAME."
    /bin/su rails -c '/usr/bin/god status'
    echo "Usage: god {start|stop|restart|status}"
    exit 1

exit $RETVAL

Any help with this would be awesome, as I'm a total n00b when it comes to servers.

share|improve this question
Running the following from terminal gives the correct result: "/bin/su rails -c '/usr/bin/god -c /home/rails/xxx/current/config/god.rb -P /home/rails/xxx/shared/pids/ -l /home/rails/xxx/shared/log/god.log'" Why won't this work in the script? – JimNeath Oct 2 '09 at 15:08
Both the pid and log files are both owned by the rails user. – JimNeath Oct 2 '09 at 15:09

The sudo command is used to run things as other users, for example:

sudo -u rails ls $someDir

So I think the following should work (Try it and see):

sudo -u rails /usr/bin/god -c $GOD_CONFIG -P /var/run/ -l /var/log/god.log

Also, check the sudo man page the god command depends on some environment variables being set...

share|improve this answer
Alas, this didn't work. God failed to start at all. Thanks anyway :) – JimNeath Oct 2 '09 at 13:02
Does it fail silently? ... it should work, maybe env variables? – Kyle Brandt Oct 2 '09 at 13:17
IS the rails user able to read that config file? – Kyle Brandt Oct 2 '09 at 13:19
Also, the rails user probably can't write the pid files in /var/run ... – Kyle Brandt Oct 2 '09 at 13:23
I couldn't tell you the if it fails silently or not. I'm just rebooting the box and seeing if god comes back up, as the right user. As I said, I'm a n00b :) – JimNeath Oct 2 '09 at 13:28

Check the permissions on your script. They should be world readable and executable.

Also, in a couple of places in your script, you have:

usr/bin/god ...

It should probably be:

/usr/bin/god ...
share|improve this answer
I originally copied the script from else where. I noticed the missing slashes when I pasted it before. Forgot to edit it. Thanks. – JimNeath Oct 2 '09 at 13:48
The script is already world readable/executable. It works fine as it currently is. I just need to change it to start up at the rails user. – JimNeath Oct 2 '09 at 14:23

This is generally accomplished in init scripts with su:

su rails -c "/usr/bin/god -c $GOD_CONFIG -P /var/run/ -l /var/log/god.log"

I haven't tested that, so I may have something weird wrong.

Also, assuming that it's been running as root so far, make sure that your pid and log files aren't owned by root and inaccessible to user rails.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.