RERUN(1)
rerun(1) β okay bestie, this is the manual page for rerun, living in section 1 of your man pages, and it's about to change your whole dev workflow fr fr π
β¨ NAME β¨
rerun β run programs and restart them when your filesystem changes π
π¦ DESCRIPTION π¦
Okay so here's the whole vibe: Rerun launches your program, then justβ¦ watches the filesystem π. The second a relevant file changes, it restarts your program. That's it. That's the whole thing. Iconic behaviour, no notes.
It works for long-running processes (think apps) and short-running ones (think tests). Basically it's a no-frills command-line alternative to Guard, Shotgun, Autotest, etc. β except it doesn't need config files and it works on any command, not just Ruby programs. Versatility queen π
Rerun's whole advantage is its simple design. Because it uses exec and the standard Unix SIGINT and SIGKILL signals, you're sure the restarted app is really acting just like it did when you ran it from the command line the first time. No cap, that's the flex.
By default it watches files ending in:
rb,js,coffee,css,scss,sass,erb,html,haml,ru,yml,slim,md,feature,c,h
Use the --pattern option if you want to change that.
As of version 0.7.0, we use the Listen gem, which tries to use your OS's built-in facilities for monitoring the filesystem, so CPU use is very light β¨ (your laptop fans will thank you).
UPDATE: Now Rerun does work on Windows πͺ. Caveats though, and we're listing them, don't skip:
- not well-tested π
- after running, it may continue to slurp up some of your console input, so run it in a separate window, and/or use
--backgroundto disable on-the-fly commands, and/or pressqto quit instead of CTRL-C - you may need to install the
wdmgem manually:gem install wdm - You may see this persistent INFO error message; to remove it, use
--no-notify:INFO: Could not find files for the given pattern(s)
π USAGE π
rerun [options] [--] cmd
For example, if you're running a Sinatra app whose main file is app.rb:
rerun ruby app.rb
If the first part of the command is a .rb filename, then ruby is optional, so the above can also be accomplished like this:
rerun app.rb
Rails doesn't automatically notice all config file changes, so you can force it to restart when you change a config file like this:
rerun --dir config rails s
Or if you're using Thin to run a Rack app that's configured in config.ru but you want it on port 4000 and in debug mode, and only want to watch the app and web subdirectories:
rerun --dir app,web -- thin start --debug --port=4000 -R config.ru
The -- is to separate rerun options from cmd options. You can also use a quoted string for the command, e.g.
rerun --dir app "thin start --debug --port=4000 -R config.ru"
Rackup can also be used to launch a Rack server, so let's try that:
rerun -- rackup --port 4000 config.ru
Want to mimic [autotest](https://github.com/grosser/autotest)? Try
rerun -x rake
or
rerun -cx rspec
And if you're using [Spork](https://github.com/sporkrb/spork) with Rails, you need to [restart your spork server](https://github.com/sporkrb/spork/issues/201) whenever certain Rails environment files change, so why not put this in your Rakefile...
desc "run spork (via rerun)"
task :spork do
sh "rerun --pattern '{Gemfile,Gemfile.lock,spec/spec_helper.rb,.rspec,spec/factories/**,config/environment.rb,config/environments/test.rb,config/initializers/*.rb,lib/**/*.rb}' -- spork"
end
β¦and start using rake spork to launch your spork server? π
(If you're using Guard instead of Rerun, check out [guard-spork](https://github.com/guard/guard-spork) for a similar solution.)
How about regenerating your HTML files after every change to your [Erector](http://erector.rubyforge.org) widgets?
rerun -x erector --to-html my_site.rb
Use Heroku Cedar? rerun is now compatible with foreman π₯. Run all your Procfile processes locally and restart them all when necessary.
rerun foreman start
π OPTIONS π
These options can be specified on the command line and/or inside a .rerun config file (see below).
--dirβ directory (or directories) to watch (default ="."). Separate multiple paths with','and/or use multiple-doptions.--patternβ glob to match inside directory. This uses the RubyDirglob style β seehttp://www.ruby-doc.org/core/classes/Dir.html#M002322for details. By default it watches files ending in:rb,js,coffee,css,scss,sass,erb,html,haml,ru,yml,slim,md,feature,c,h. On top of this, it also ignores dotfiles,.tmpfiles, and some other files and directories (like.gitandlog). Runrerun --helpto see the actual list.--ignoreβ pattern file glob to ignore (can be set many times). To ignore a directory, you must append'/'e.g.--ignore 'coverage/'.- On top of
--patternand--ignore, we ignore any changes to files and dirs starting with a dot. π
- On top of
--signal(or-s) β use specified signal(s) (instead of the defaultTERM,INT,KILL) to terminate the previous process. You can use a comma-delimited list if you want to try a signal, wait up to 5 seconds for the process to die, then try again with a different signal, and so on. This may be useful for forcing the respective process to terminate as quickly as possible. (--signal KILLis the equivalent ofkill -9)--wait sec(or-w) β after asking the process to terminate, wait this long (in seconds) before either aborting, or trying the next signal in series. Default:2 sec--restart(or-r) β expect process to restart itself, using signalHUPby default (e.g.-r -s INTwill send aINTand then resume watching for changes)--exit(or-x) β expect the program to exit. With this option, rerun checks the return value; without it, rerun checks that the launched process is still running.--clear(or-c) β clear the screen before each run--background(or-b) β disable on-the-fly commands, allowing the process to be backgrounded--notify NOTIFIERβ usegrowlorosxornotify-sendfor notifications (see below)--no-notifyβ disable notifications--nameβ set the app name (for display)--force-pollingβ use polling instead of a native filesystem scan (useful for Vagrant)--quietβ silences most messages--verboseβ enables even more messages (unless you also specified--quiet, which overrides--verbose)
Also --version and --help, naturally. π
π CONFIG FILE π
If the current directory contains a file named .rerun, it will be parsed with the same rules as command-line arguments. Newlines are the same as any other whitespace, so you can stack options vertically, like this:
--quiet
--pattern **/*.{rb,js,scss,sass,html,md}
Options specified on the command line will override those in the config file. You can negate boolean options with --no-, so for example, with the above config file, to re-enable logging, you could say:
rerun --no-quiet rackup
If you're not sure what options are being overwritten, use --verbose and rerun will show you the final result of the parsing. Detective work, but make it cute π
π NOTIFICATIONS π
If you have growlnotify available on the PATH, it sends notifications to growl in addition to the console.
If you have terminal-notifier, it sends notifications to the OS X notification center in addition to the console.
If you have notify-send, it sends notifications to Freedesktop-compatible desktops in addition to the console.
If you have more than one available notification program, Rerun will pick one, or you can choose between them using --notify growl, --notify osx, --notify notify-send, etc.
If you have a notifier installed but don't want rerun to use it, set the --no-notify option.
Download [growlnotify here](http://growl.info/downloads.php#generaldownloads) now that Growl has moved to the App Store.
Install [terminal-notifier](https://github.com/julienXX/terminal-notifier) using gem install terminal-notifier. (You may have to put it in your system gemset and/or use sudo too.) Using Homebrew to install terminal-notifier is not recommended.
On Debian/Ubuntu, notify-send is availble in the libnotify-bin package. On other GNU/Linux systems, it might be in a package with a different name.
πΈ ON-THE-FLY COMMANDS πΈ
While the app is (re)running, you can make things happen by pressing keys:
rβ restart (as if a file had changed)fβ force restart (stop and start)cβ clear the screenxorqβ exit (just like control-C)pβ pause/unpause filesystem watching
If you're backgrounding or using Pry or a debugger, you might not want these keys to be trapped, so use the --background option. π
β SIGNALS β
The current algorithm for killing the process is:
- send [SIGTERM](http://en.wikipedia.org/wiki/SIGTERM) (or the value of the
--signaloption) - if that doesn't work after 2 seconds, send
SIGINT(aka control-C) - if that doesn't work after 2 more seconds, send
SIGKILL(akakill -9)
This seems like the most gentle and unixy way of doing things, but it does mean that if your program ignores SIGTERM, it takes an extra 2 to 4 seconds to restart. Patience is a virtue bestie π
If you want to use your own series of signals, use the --signal option. If you want to change the delay before attempting the next signal, use the --wait option.
π§ VAGRANT AND VIRTUALBOX π§
If running inside a shared directory using Vagrant and VirtualBox, you must pass the --force-polling option. You may also have to pass some extra --ignore options too; otherwise each scan can take 10 or more seconds on directories with a large number of files or subdirectories underneath it. π
π©Ή TROUBLESHOOTING π©Ή
π¦ Vagrant
Rerun will not pick up changes made to shared folders. This means that the common method of using Vagrant for an execution environment and using the /vagrant shared folder for source code will not work.
Instead, use [shotgun](https://rubygems.org/gems/shotgun).
π¦ zsh
If you are using zsh as your shell, and you are specifying your --pattern as */.rb, you may face this error
Errno::EACCES: Permission denied - <filename>
This is because */.rb gets expanded into the command by zsh instead of passing it through to rerun. The solution is to simply quote ('' or "") the pattern. i.e
rerun -p **/*.rb rake test
becomes
rerun -p "**/*.rb" rake test
That's the whole page bestie β go forth and let your dev server restart itself while you sip your lil drink π
This manual page is from the 2024-03-04 release of RERUN(1). Mwah, bye ππ
π¦ where this page comes from
- debian trixie: rerun 0.14.0-1 Β· MIT
- ubuntu noble: rerun 0.14.0-1 Β· MIT
- ubuntu questing: rerun 0.14.0-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms