Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Upstart config for running thin (or anything else, I guess) through rbenv Chances are your OS hasn't enables so-called user jobs by default and you'll have to edit the upstart config for this to work. I've included the upstart config file I've used. Upstart also won't run any user jobs by default because they won't hav been loaded into its syste…
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only the root user can own the Upstart name -->
<policy user="root">
<allow own="com.ubuntu.Upstart" />
</policy>
<!-- Permit the root user to invoke all of the methods on Upstart, its jobs
or their instances, and to get and set properties. -->
<policy user="root">
<allow send_destination="com.ubuntu.Upstart"
send_interface="org.freedesktop.DBus.Properties" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Job" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Instance" />
</policy>
<!-- This is the part letting regular users control jobs -->
<policy context="default">
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Job" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Instance" />
</policy>
<!-- Allow any user to introspect Upstart's interfaces, to obtain the
values of properties (but not set them) and to invoke selected
methods on Upstart and its jobs that are used to walk information. -->
<policy context="default">
<allow send_destination="com.ubuntu.Upstart"
send_interface="org.freedesktop.DBus.Introspectable" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="org.freedesktop.DBus.Properties"
send_type="method_call" send_member="Get" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="org.freedesktop.DBus.Properties"
send_type="method_call" send_member="GetAll" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6"
send_type="method_call" send_member="GetJobByName" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6"
send_type="method_call" send_member="GetAllJobs" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Job"
send_type="method_call" send_member="GetInstance" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Job"
send_type="method_call" send_member="GetInstanceByName" />
<allow send_destination="com.ubuntu.Upstart"
send_interface="com.ubuntu.Upstart0_6.Job"
send_type="method_call" send_member="GetAllInstances" />
</policy>
</busconfig>
# http://bradleyayers.blogspot.com/2011/10/upstart-user-jobs-on-ubuntu-1110.html
author 'Bradley Ayers'
description 'Enables user job "start on" stanzas to be honored at boot'
task
# initctl doesn't work before dbus starts
start on started dbus
script
cat /etc/passwd | while read line
do
user=`echo $line | cut -d: -f1`
home=`echo $line | cut -d: -f6`
if [ -d "$home/.init" ]
then
su $user -c "initctl status rc-sysinit"
fi
done
# dbus seems to start pretty late, so user jobs should listen on this
# event rather than on net-device-up or anything.
initctl emit user-jobs
end script
description "App server"
start on user-jobs #Emitted by load-user-jobs.conf
stop on runlevel [016]
env HOME=/home/username #HOME won't be set, so set it manually
#expect fork #You could uncomment this to have upstart monitor the real PID, but the bash PID works all the same
exec /bin/bash -l /home/username/bin/service.sh
#!/bin/bash -l
rbenv shell 1.9.3-p392 #Or whatever version you want
cd /home/username/appdir #The app with the config.ru
sleep 3 #Just because
# -A is because for some reason, thin's autodetect doesn't work when executed like this
thin start -p8000 -edevelopment -Arack > /home/username/appdir/thin.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment