Method: RunInBackground.delete

Defined in:
lib/run_in_background.rb

.delete(name) ⇒ Object

Delete service/daemon.
If running then stop and delete.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/run_in_background.rb', line 296

def RunInBackground.delete name
  if not exists? name
    raise ArgumentError.new("Daemon #{name} doesn't exists")
  elsif running? name
    stop name
  end
  if OS == :WINDOWS
    Service.delete name
  else  # OS == :LINUX
    opts = {:app_name => name,
            :ARGV => ['zap'],
            :dir_mode => :normal,
            :dir => Params['pid_dir']
    }
    # Current process, that creates daemon, will transfer control to the Daemons library.
    # So to continue working with current process, daemon creation initiated from separate process.
    # It looks that it holds only for start command
    #pid = fork do
    Daemons.run "", opts
    #end
    #Process.waitpid pid
  end
  0.upto(TIMEOUT) do
    unless exists? name
      puts "daemon/service #{name} deleted\n"
      Log.debug1("daemon/service #{name} deleted")
      return
    end
    sleep 1
  end
  # if got here then something gone wrong and daemon/service wasn't deleted in timely manner
  Log.error("daemon/service #{name} wasn't deleted in timely manner")
Log.flush
  raise "daemon/service #{name} wasn't deleted in timely manner"
end