'\" t .\" Title: rerun .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.20 .\" Date: 2024-03-04 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" .TH "RERUN" "1" "2024-03-04" "\ \&" "\ \&" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" rerun \- run programs and restarts them on filesystem changes .SH "DESCRIPTION" .sp Rerun launches your program, then watches the filesystem. If a relevant file changes, then it restarts your program. .sp Rerun works for both long\-running processes (e.g. apps) and short\-running ones (e.g. tests). It\(cqs basically a no\-frills command\-line alternative to Guard, Shotgun, Autotest, etc. that doesn\(cqt require config files and works on any command, not just Ruby programs. .sp Rerun\(cqs advantage is its simple design. Since it uses \f(CRexec\fP and the standard Unix \f(CRSIGINT\fP and \f(CRSIGKILL\fP signals, you\(cqre sure the restarted app is really acting just like it was when you ran it from the command line the first time. .sp By default it watches files ending in: \f(CRrb,js,coffee,css,scss,sass,erb,html,haml,ru,yml,slim,md,feature,c,h\fP. Use the \f(CR\-\-pattern\fP option if you want to change this. .sp As of version 0.7.0, we use the Listen gem, which tries to use your OS\(cqs built\-in facilities for monitoring the filesystem, so CPU use is very light. .sp \fBUPDATE\fP: Now Rerun \fBdoes\fP work on Windows. Caveats: * 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 \f(CR\-\-background\fP to disable on\-the\-fly commands, and/or press \f(CRq\fP to quit instead of CTRL\-C * you may need to install the \f(CRwdm\fP gem manually: \f(CRgem install wdm\fP * You may see this persistent \f(CRINFO\fP error message; to remove it, use`\-\-no\-notify`: * \f(CRINFO: Could not find files for the given pattern(s)\fP .SH "USAGE" .sp .if n .RS 4 .nf .fam C rerun [options] [\-\-] cmd .fam .fi .if n .RE .sp For example, if you\(cqre running a Sinatra app whose main file is \f(CRapp.rb\fP: .sp .if n .RS 4 .nf .fam C rerun ruby app.rb .fam .fi .if n .RE .sp If the first part of the command is a \f(CR.rb\fP filename, then \f(CRruby\fP is optional, so the above can also be accomplished like this: .sp .if n .RS 4 .nf .fam C rerun app.rb .fam .fi .if n .RE .sp Rails doesn\(cqt automatically notice all config file changes, so you can force it to restart when you change a config file like this: .sp .if n .RS 4 .nf .fam C rerun \-\-dir config rails s .fam .fi .if n .RE .sp Or if you\(cqre using Thin to run a Rack app that\(cqs configured in config.ru but you want it on port 4000 and in debug mode, and only want to watch the \f(CRapp\fP and \f(CRweb\fP subdirectories: .sp .if n .RS 4 .nf .fam C rerun \-\-dir app,web \-\- thin start \-\-debug \-\-port=4000 \-R config.ru .fam .fi .if n .RE .sp The \f(CR\-\-\fP is to separate rerun options from cmd options. You can also use a quoted string for the command, e.g. .sp .if n .RS 4 .nf .fam C rerun \-\-dir app "thin start \-\-debug \-\-port=4000 \-R config.ru" .fam .fi .if n .RE .sp Rackup can also be used to launch a Rack server, so let\(cqs try that: .sp .if n .RS 4 .nf .fam C rerun \-\- rackup \-\-port 4000 config.ru .fam .fi .if n .RE .sp Want to mimic [autotest](\c .URL "https://github.com/grosser/autotest" "" ")?" Try .sp .if n .RS 4 .nf .fam C rerun \-x rake .fam .fi .if n .RE .sp or .sp .if n .RS 4 .nf .fam C rerun \-cx rspec .fam .fi .if n .RE .sp And if you\(cqre using [Spork](\c .URL "https://github.com/sporkrb/spork" "" ")" with Rails, you need to [restart your spork server](\c .URL "https://github.com/sporkrb/spork/issues/201" "" ")" whenever certain Rails environment files change, so why not put this in your Rakefile... .sp .if n .RS 4 .nf .fam C desc "run spork (via rerun)" task :spork do sh "rerun \-\-pattern \*(Aq{Gemfile,Gemfile.lock,spec/spec_helper.rb,.rspec,spec/factories/**,config/environment.rb,config/environments/test.rb,config/initializers/*.rb,lib/**/*.rb}\*(Aq \-\- spork" end .fam .fi .if n .RE .sp and start using \f(CRrake spork\fP to launch your spork server? .sp (If you\(cqre using Guard instead of Rerun, check out [guard\-spork](\c .URL "https://github.com/guard/guard\-spork" "" ")" for a similar solution.) .sp How about regenerating your HTML files after every change to your [Erector](\c .URL "http://erector.rubyforge.org" "" ")" widgets? .sp .if n .RS 4 .nf .fam C rerun \-x erector \-\-to\-html my_site.rb .fam .fi .if n .RE .sp Use Heroku Cedar? \f(CRrerun\fP is now compatible with \f(CRforeman\fP. Run all your Procfile processes locally and restart them all when necessary. .sp .if n .RS 4 .nf .fam C rerun foreman start .fam .fi .if n .RE .SH "OPTIONS" .sp These options can be specified on the command line and/or inside a \f(CR.rerun\fP config file (see below). .sp \f(CR\-\-dir\fP directory (or directories) to watch (default = "."). Separate multiple paths with \*(Aq,\*(Aq and/or use multiple \f(CR\-d\fP options. .sp \f(CR\-\-pattern\fP glob to match inside directory. This uses the Ruby Dir glob style \(em see \c .URL "http://www.ruby\-doc.org/core/classes/Dir.html#M002322" "" "" for details. By default it watches files ending in: \f(CRrb,js,coffee,css,scss,sass,erb,html,haml,ru,yml,slim,md,feature,c,h\fP. On top of this, it also ignores dotfiles, \f(CR.tmp\fP files, and some other files and directories (like \f(CR.git\fP and \f(CRlog\fP). Run \f(CRrerun \-\-help\fP to see the actual list. .sp \f(CR\-\-ignore pattern\fP file glob to ignore (can be set many times). To ignore a directory, you must append \f(CR\*(Aq/\fB\*(Aq\fP e.g. \f(CR\-\-ignore \*(Aqcoverage/\fP\*(Aq\fP. .sp .if n .RS 4 .nf .fam C *On top of \-\-pattern and \-\-ignore, we ignore any changes to files and dirs starting with a dot.* .fam .fi .if n .RE .sp \f(CR\-\-signal\fP (or \f(CR\-s\fP) use specified signal(s) (instead of the default \f(CRTERM,INT,KILL\fP) 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. (\f(CR\-\-signal KILL\fP is the equivalent of \f(CRkill \-9\fP) .sp \f(CR\-\-wait sec\fP (or \f(CR\-w\fP) after asking the process to terminate, wait this long (in seconds) before either aborting, or trying the next signal in series. Default: 2 sec .sp \f(CR\-\-restart\fP (or \f(CR\-r\fP) expect process to restart itself, using signal HUP by default (e.g. \f(CR\-r \-s INT\fP will send a INT and then resume watching for changes) .sp \f(CR\-\-exit\fP (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. .sp \f(CR\-\-clear\fP (or \-c) clear the screen before each run .sp \f(CR\-\-background\fP (or \-b) disable on\-the\-fly commands, allowing the process to be backgrounded .sp \f(CR\-\-notify NOTIFIER\fP use \f(CRgrowl\fP or \f(CRosx\fP or \f(CRnotify\-send\fP for notifications (see below) .sp \f(CR\-\-no\-notify\fP disable notifications .sp \f(CR\-\-name\fP set the app name (for display) .sp \f(CR\-\-force\-polling\fP use polling instead of a native filesystem scan (useful for Vagrant) .sp \f(CR\-\-quiet\fP silences most messages .sp \f(CR\-\-verbose\fP enables even more messages (unless you also specified \f(CR\-\-quiet\fP, which overrides \f(CR\-\-verbose\fP) .sp Also \f(CR\-\-version\fP and \f(CR\-\-help\fP, naturally. .SH "CONFIG FILE" .sp If the current directory contains a file named \f(CR.rerun\fP, 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: .sp .if n .RS 4 .nf .fam C \-\-quiet \-\-pattern **/*.{rb,js,scss,sass,html,md} .fam .fi .if n .RE .sp Options specified on the command line will override those in the config file. You can negate boolean options with \f(CR\-\-no\-\fP, so for example, with the above config file, to re\-enable logging, you could say: .sp .if n .RS 4 .nf .fam C rerun \-\-no\-quiet rackup .fam .fi .if n .RE .sp If you\(cqre not sure what options are being overwritten, use \f(CR\-\-verbose\fP and rerun will show you the final result of the parsing. .SH "NOTIFICATIONS" .sp If you have \f(CRgrowlnotify\fP available on the \f(CRPATH\fP, it sends notifications to growl in addition to the console. .sp If you have \f(CRterminal\-notifier\fP, it sends notifications to the OS X notification center in addition to the console. .sp If you have \f(CRnotify\-send\fP, it sends notifications to Freedesktop\-compatible desktops in addition to the console. .sp If you have more than one available notification program, Rerun will pick one, or you can choose between them using \f(CR\-\-notify growl\fP, \f(CR\-\-notify osx\fP, \f(CR\-\-notify notify\-send\fP, etc. .sp If you have a notifier installed but don\(cqt want rerun to use it, set the \f(CR\-\-no\-notify\fP option. .sp Download [growlnotify here](\c .URL "http://growl.info/downloads.php#generaldownloads" "" ")" now that Growl has moved to the App Store. .sp Install [terminal\-notifier](\c .URL "https://github.com/julienXX/terminal\-notifier" "" ")" using \f(CRgem install terminal\-notifier\fP. (You may have to put it in your system gemset and/or use \f(CRsudo\fP too.) Using Homebrew to install terminal\-notifier is not recommended. .sp On Debian/Ubuntu, \f(CRnotify\-send\fP is availble in the \f(CRlibnotify\-bin\fP package. On other GNU/Linux systems, it might be in a package with a different name. .SH "ON\-THE\-FLY COMMANDS" .sp While the app is (re)running, you can make things happen by pressing keys: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBr\fP \(em restart (as if a file had changed) .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBf\fP \(em force restart (stop and start) .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBc\fP \(em clear the screen .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBx\fP or \fBq\fP \(em exit (just like control\-C) .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} \fBp\fP \(em pause/unpause filesystem watching .RE .sp If you\(cqre backgrounding or using Pry or a debugger, you might not want these keys to be trapped, so use the \f(CR\-\-background\fP option. .SH "SIGNALS" .sp The current algorithm for killing the process is: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} send [SIGTERM](\c .URL "http://en.wikipedia.org/wiki/SIGTERM" "" ")" (or the value of the \f(CR\-\-signal\fP option) .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} if that doesn\(cqt work after 2 seconds, send SIGINT (aka control\-C) .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ . sp -1 . IP \(bu 2.3 .\} if that doesn\(cqt work after 2 more seconds, send SIGKILL (aka kill \-9) .RE .sp 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. .sp If you want to use your own series of signals, use the \f(CR\-\-signal\fP option. If you want to change the delay before attempting the next signal, use the \f(CR\-\-wait\fP option. .SH "VAGRANT AND VIRTUALBOX" .sp If running inside a shared directory using Vagrant and VirtualBox, you must pass the \f(CR\-\-force\-polling\fP option. You may also have to pass some extra \f(CR\-\-ignore\fP options too; otherwise each scan can take 10 or more seconds on directories with a large number of files or subdirectories underneath it. .SH "TROUBLESHOOTING" .SS "Vagrant" .sp 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 \f(CR/vagrant\fP shared folder for source code will not work. .sp Instead, use [shotgun](\c .URL "https://rubygems.org/gems/shotgun" "" ")." .SS "zsh" .sp If you are using \f(CRzsh\fP as your shell, and you are specifying your \f(CR\-\-pattern\fP as \f(CR\fB*/\fP.rb\fP, you may face this error .sp .if n .RS 4 .nf .fam C Errno::EACCES: Permission denied \- .fam .fi .if n .RE .sp This is because \f(CR\fB*/\fP.rb\fP gets expanded into the command by \f(CRzsh\fP instead of passing it through to rerun. The solution is to simply quote (\*(Aq\*(Aq or "") the pattern. i.e .sp .if n .RS 4 .nf .fam C rerun \-p **/*.rb rake test .fam .fi .if n .RE .sp becomes .sp .if n .RS 4 .nf .fam C rerun \-p "**/*.rb" rake test .fam .fi .if n .RE