User switching with `script/delayed_job` #292

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
5 participants

I've added options -u and -g which are used to perform permissions changes. This prevents having to jump through hoops in production when starting the daemon with something like upstart.

I noticed another pull request (#266) open for this, but I didn't like that it duplicated existing behavior in the daemons gem. I also fixed a Rails 3 deprecation warning in a different commit (grays@da07875), I didn't include it in the pull request because I don't want to make assumptions about why it wasn't already changed.

So, any hope of this?

Collaborator

betamatt commented Oct 14, 2011

Trying it out on DJ master w/ daemons 1.0.10. Can see the options getting set correctly but can't get it to change users when it daemonizes.

sudo ./script/delayed_job start -u matt
{:pid_dir=>"/Users/matt/projects/delayed_job_test/tmp/pids", :user=>"matt", :group=>"matt", :quiet=>true}
Process runs as root.

Works for me in production on linux with daemons 1.1.4

I'll investigate and see what could be causing it not to work.

Collaborator

betamatt commented Oct 14, 2011

Daemons gem version seems like a likely starting point. Edited: right, duh. That's pretty much what you were saying.

ambethia commented Dec 5, 2011

I finally had time to date a look at this, it's working fine in production for us, and in development:

 % sudo ./script/delayed_job start -u ambethia -g staff
Changing process privilege to ambethia:staff
delayed_job: process with pid 50798 started.

 % ps ux | grep 50798
ambethia 50798   0.2  2.4  2574612 102120   ??  S     6:46AM   0:01.62 delayed_job

What you might have noticed running as root was the sudo process, not the dj worker itself while the worker is spinning up:

root           50971   0.0  0.1  2468716   2360 s006  S+    6:54AM   0:00.02 sudo ./script/delayed_job start -u ambethia -g staff

Have you had a chance to look at this again yet? It's a really tiny change to Delayed::Command that just passes along an existing option Daemons already supports.

@albus522 albus522 commented on the diff Nov 5, 2012

lib/delayed/command.rb
@@ -78,7 +84,8 @@ def daemonize
def run_process(process_name, dir)
Delayed::Worker.before_fork
- Daemons.run_proc(process_name, :dir => dir, :dir_mode => :normal, :monitor => @monitor, :ARGV => @args) do |*args|
+ @options[:group] ||= @options[:user]
@albus522

albus522 Nov 5, 2012

Owner

I don't think this can be globally assumed. Does Daemons error if group is not given?

albus522 referenced this pull request Nov 5, 2012

Closed

UID/GID CLI flags #266

albus522 closed this Sep 24, 2014

Oh cool, this was committed, just without the @options[:group] ||= @options[:user] I had never noticed.

Thanks!

Edit: Oops, no it wasn't. Oh well.

Owner

albus522 commented Sep 24, 2014

If you still need/want this and want to update against master. Go for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment