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

Is there a way to get sup to run offlineimap as a background task? #537

Open
Panoplos opened this issue Jun 22, 2017 · 2 comments
Open

Is there a way to get sup to run offlineimap as a background task? #537

Panoplos opened this issue Jun 22, 2017 · 2 comments

Comments

@Panoplos
Copy link

I have offlineimap setup to stay connected and sync when I run it. It would be really cool if I could get sup run it automatically as a background task. This way they will both only be running on the computer when I need to use sup.

@Panoplos
Copy link
Author

OK, so I have figured out how to get this working with a the following startup.rb hook

offlineimapDir = File.expand_path '~/.sup/offlineimap'
if Dir.exist? offlineimapDir
  require 'fileutils'
  FileUtils.rm_r offlineimapDir
end
Dir.mkdir offlineimapDir
say "Running OfflineIMAP as background task."
pid = spawn('offlineimap', err: "#{offlineimapDir}/error.log", out: "#{offlineimapDir}/out.log")
Process.detach pid
open("#{offlineimapDir}/pid", 'w') do |f|
  f << pid
end

However, when I attempt to clean stuff up as follows in shutdown.rb, it is never called...

idFile = File.expand_path '~/.sup/offlineimap/pid'
if File.exist? pidFile
  begin
    Process.kill('SIGTERM', File.open(pidFile, &:readline).to_i)
  rescue 
    say "There was an issue ending the offlineimap background task."
  else
    say "Ended the offlineimap background task."
  end
  File.delete pidFile
else
  say "Houston, we have a problem! No pid file exists for the offlineimap background task."
end

Any reason this is not getting called?

@danc86
Copy link
Contributor

danc86 commented Jun 28, 2020

Your startup.rb and shutdown.rb hooks look fine to me. I also double-checked that sup executes those hooks correctly as documented. Are you sure your shutdown.rb is not getting called?

Bear in mind that say and debug and similar calls in the shutdown.rb hook will never be visible -- immediately after the shutdown hook runs, the log buffer is discarded and the curses display is reset. I found the only way to get a message out of shutdown.rb was to use STDERR.puts and run sup with stderr redirected to a file.

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

No branches or pull requests

2 participants