Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

foreverb

> 编程语言
Open source

Small daemon framework for ruby, with logging, error handler, scheduling and much more.

520 stars0 likes3 views
WebsiteGitHub

About

Small daemon framework for ruby, with logging, error handler, scheduling and much more.

Foreverb

Small daemon framework for ruby, with logging, error handler, scheduling and much more.

My inspiration was forever for node.js written by Charlie Robbins. My scheduling inspiration was taken from clockwork written by Adam Wiggins.

Why?

There are some alternatives, one of the best is resque, so why another daemons framework? In my servers I've several daemons and what I need is:

  • easily watch the process (memory, cpu)
  • easily manage exceptions
  • easily see logs
  • easily start/stop/restart daemon
  • no blocking jobs
  • no blocking queue

As like sinatra and padrino I need a thin framework to do these jobs in few seconds. This mean that:

  • I can create a new job quickly
  • I can watch, start, stop it quickly

So, if you have my needs, Forever can be the right choice for you.

Install:

bash
$ gem install foreverb

Deamon Example:

Place your script under your standard directory, generally on my env is bin or scripts.

In that case is: bin/foo

…

Assign right permission:

bash
$ chmod +x bin/foo

start the daemon:

bash
$ bin/foo

you should see an output like:

bash
$ bin/foo
=> Process demonized with pid 19538

you can stop it:

bash
$ bin/foo stop
=> Found pid 19538...
=> Killing process 19538...

Scheduling

You can use every method to schedule repetitive tasks.

Every allow the option :at to specify hour or minute and the option :last to specify when the every must start to loop.

:last: can be nil or a Time class. Default is 0.

:at: can be nil, a string or an array of formatted strings. Default is nil.

rb
every 1.second,   :at => '19:30'            # => every second since 19:30
every 1.minute,   :at => ':30'              # => every minute but first call wait xx:30
every 5.minutes,  :at => '18:'              # => every five minutes but first call was at 18:xx
every 1.day,      :at => ['18:30', '20:30'] # => every day only at 18:30 and 20:30
every 60.seconds, :last => Time.now         # => will be fired 60 seconds after you launch the app

Remember that :at:

  • accept only 24h format
  • you must always provide the colon :

So looking our example:

…

Running the example with the following code:

bash
$ examples/sample; tail -f -n 150 examples/log/sample.log; examples/sample stop

you should see:

…

Filters

In foreverb we have a couple of filters, before and after, like rspec you should be able to filter before :all or before :each.

rb
before :all do
  puts "This will be ran only at start"
end

before :each do
  puts "Do that before each job"
end

# ...  here jobs ...

after :all do
  puts "This will be ran only at shutdown"
end

after :each do
  puts "Do that after each job"
end

CLI

Help:

…

List daemons:

bash
$ foreverb list
     RUNNING  /Developer/src/Extras/githubwatcher/bin/githubwatcher
     RUNNING  /Developer/src/Extras/foreverb/examples/sample
Reading config from: /Users/DAddYE/.foreverb

Monitor daemons (with ps):

bash
$ foreverb list -m
PID   RSS     CPU    CMD
5528  168 Mb  0.1 %  Forever: /Developer/src/Extras/githubwatcher/bin/githubwatcher
5541  18 Mb   0.0 %  Forever: /Developer/src/Extras/foreverb/examples/sample

Stop daemon(s):

bash
$ foreverb stop foo
Do you want really stop Forever: bin/foo  with pid 19538? y
Killing process Forever: bin/foo  with pid 19538...

$ foreverb stop --all -y
Killing process Forever: /usr/bin/githubwatcher with pid 2824
Killing process Forever: examples/sample with pid 2836

Start daemon(s):

bash
$ foreverb start github
Do you want really start /Developer/src/Extras/githubwatcher/bin/githubwatcher? y
=> Found pid 5528...
=> Killing process 5528...
=> Process demonized with pid 14925 with Forever v.0.2.2

as for stop we allow --all and -y

Restart daemon(s)

bash
$ foreverb restart github
Do you want really restart /Developer/src/Extras/githubwatcher/bin/githubwatcher? y
=> Found pid 5528...
=> Killing process 5528...
=> Process demonized with pid 14925 with Forever v.0.2.2

as for stop we allow --all and -y

Tail logs

bash
$ foreverb tail github
[22/07 11:22:17] Quering git://github.com/DAddYE/lipsiadmin.git...
[22/07 11:22:17] Quering git://github.com/DAddYE/lightbox.git...
[22/07 11:22:17] Quering git://github.com/DAddYE/exception-notifier.git...
[22/07 11:22:17] Quering git://github.com/DAddYE/lipsiablog.git...
[22/07 11:22:17] Quering git://github.com/DAddYE/purple_ruby.git...

you can specify how many lines show with option -n, default is 150

Update config

This command would be helpful if you change pid log path, in this way the global config file ~/.foreverb will be update using latest informations from yours deamons

Note that you can personalize the config file setting FOREVER_PATH matching your needs.

bash
$ foreverb update github
Do you want really update config from /Developer/src/Extras/githubwatcher/bin/githubwatcher? y

as for stop we allow --all and -y

HACKS

Bundler

Bundler has the bad behavior to load Gemfile from your current path, so if your daemons (ex: githubwatcher) is shipped with their own Gemfile to prevent errors you must insert that line:

ruby
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) # edit matching your Gemfile path

Rails/Padrino prevent memory leaks

I highly suggest to use fork and before filters when you are using forever with frameworks, this since running same job on our ruby will eat a lot of ram, so the better way that I found is that:

rb
Forever.run :fork => true do
  before :each do
    require '/config/boot' # here the rails/padrino environment
  end

  every 10.seconds, :at => ['12:00', '00:00'] do
    Project.all(&:perform_long_task)
  end

  every 1.minute do
    Account.all.map(&:send_emails)
  end
end

This is similar to create a new process i.e.:

rb
Process.fork do
  require '/config/boot'
  my_long_jobs
  Project.all(&:perform_long_task)
end
Process.waitall

/etc/init.d script sample

Use the following script if you want foreverb to fire up all of your daemons at boot time in Linux:

…

You'll have to create one script per each user foreverb runs on. After creating the file, make it executable:

chmod +x /etc/init.d/foreverb-username

and add it to the system's boot:

  • RedHat:

    sudo /sbin/chkconfig --level 345 foreverb-username on
  • Debian/Ubuntu:

    sudo /usr/sbin/update-rc.d -f foreverb-username defaults
  • Gentoo:

    bash
    sudo rc-update add foreverb-username default

Extras

To see a most comprensive app running foreverb + growl see githubwatcher gem

Author

DAddYE, you can follow me on twitter @daddye or take a look at my site daddye.it

Copyright

Copyright (C) 2011 Davide D'Agostino - @daddye

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言