Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daemonize #35

Closed
AlexWayfer opened this issue Oct 12, 2016 · 4 comments
Closed

Daemonize #35

AlexWayfer opened this issue Oct 12, 2016 · 4 comments

Comments

@AlexWayfer
Copy link
Member

AlexWayfer commented Oct 12, 2016

Hello!

How can I run filewatcher in background?

My case:

#!/usr/bin/env ruby

def bash(command)
  system "bash -c \"#{command}\""
end

bash "filewatcher 'some_files' 'some_command' &"
bash "tail -f some_log_file"

When I press Ctrl+C in tailfilewatcher is also stopping.

I want to stop tail, but not filewatcher.

Thanks!

@thomasfl
Copy link
Collaborator

The --restart option makes filewatcher run the command supplied as a parameter in the background:

    $ filewatcher --restart  "**/*.html" "webserver"

Every time an html file changes, filewatcher will kill the webserver process and start it again in a new process.

So if you want to run filewatcher in the background, you can actually supply filewatcher as a command to filewatcher itself. I haven't tested this, but it may look something like this:

    $ filewatcher --restart  "**/*.html" "$ filewatcher --restart  '**/*.html' 'tail -f some_log_file'"

If you wan't to get some hints on how to run things in the background, please have a look at

https://github.com/thomasfl/filewatcher/blob/master/bin/filewatcher

Processes are run in the background simply by using

  pid = Process.spawn(env, cmd)

I have to admit I am not sure what you are trying to accomplish.

@AlexWayfer
Copy link
Member Author

Okay, that's example for my case:

#!/usr/bin/env ruby

def bash(command)
    system "bash -c \"#{command}\""
end

def server(command)
    pumactl = "pumactl #{command} -F config/puma.rb"
    bash pumactl
    return unless %i(start restart).include?(command) && environment == 'development'
    bash 'pkill -f filewatcher'
    bash "filewatcher '**/*.{rb,ru,yml}' '#{pumactl}' > /dev/null &"
end

def monitor_server
    bash "tail -f log/{stdout,stderr} -q"
end

## Runtime
case ARGV[0]
when 'start'
    server :start
when 'stop'
    server :stop
when 'restart'
    server :restart
when 'monitor'
    monitor_server
when 'devel'
    server :restart
    puts 'Waiting for logs...'
    sleep 2
    monitor_server
end

@AlexWayfer
Copy link
Member Author

Processes without daemonizing binds to Ruby script, as I think (also with &, or Process.spawn). So… When I press Ctrl+C — it's stop all binded processes too. But… I want to stop tail, not filewatcher. It's must be self-daemonizing, as I think (as puma) for that. But how? Or is there some workarounds?

@AlexWayfer
Copy link
Member Author

Maybe that can be some helpful for your gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants