Nand is a simple CLI tool to make anything daemon by Ruby. Nand is the meaning of Nandemo of Japanese.
Nandemo of here is a executable file and shell command, a non-executable Ruby file.
For starting daemonize TARGET, You can just type
nand start TARGET.
You can stop by
nand stop TARGET.
nand status TARGET show it running status.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install nand
$ nand SUB_COMMAND TARGET [OPTION]
$ cd /any/path $ nand start sleep 1000 sleep is Start Success 
You can start TARGET by
Though OPTION(s) after TARGET is Nand option, OPTION(s) Nand is unknown,
will be handed over to TARGET.
1000 is handed over to
And Nand recognizes a shell command
sleep as TARGET name.
When TARGET is success to be a daemon process, Nand show TARGET namd and daemon
For the TARGET
sleep running status, Nand
status command show running status.
$ cd /any/path $ nand status sleep sleep is Running  by USER in /any/path
You can omit the TARGET name
sleep because you stay in
stop command stop daemon process with TARGET name.
$ nand stop sleep sleep is Stopped  $ nand status sleep sleep is Not Running in /any/path
You can also omit the TARGET name
status because you stay in
A Ruby File
forever_sleep.rb in current directory, you can make it daemon with
file name as TARGET name.
require 'nand/plugin' module Sample class ForeverSleep extend Plugin def self.executor(*argv) new(*argv) end def exec sleep end end end
$ nand start forever_sleep.rb -p Sample::ForeverSleep forever_sleep.rb is Start Success  $ nand stop forever_sleep.rb forever_sleep.rb is Stopped 
Nand can find the executor with exec method from defined class by
The class need to extend
Then then executor can become a daemon process as TARGET name
Avoid duplicated Nand Options
There are two ways to avoid duplicated Nand options for daemon's process options.
First, the options can be enclosed in "(double) or '(single) quatations.
$ nand start any.sh "--run_dir /tmp"
Others, you can put them after double dash(--).
$ nand start any.sh -- --run_dir /tmp
Pipes to Daemon Process
You can pipe to daemon process STDOUT and STDERR, STDIN by using Nand options
sleep_echo.sh as follows:
#!/bin/sh sleep $1 echo $2
Then you can start with Nand pipe option.
$ nand start sleep_echo.sh 100 '"foo bar baz"' --out out.log $ cat out.log foo bar baz
It is very important that you define the running directory with Nand option
A PID file is put in the running directory and daemon process change the running directory.
If you don't define the running directory, it is the current directory.
$ nand start sleep_echo.sh 100 abc --run_dir /tmp --out out.log
Prohibition of Duplicated Start
Basically, you can not start duplicated daemon process name.
$ nand start sleep 1000 sleep is Start Success  $ nand start sleep 1000 sleep is Start Failed [PID file exist /any/path/.nand_sleep.pid]
If you would like to start duplicated daemon process name, you can start in another run directory or as another daemon process name.
$ nand start sleep 1000 --run_dir /tmp sleep1 is Start Success  $ nand start sleep 1000 -n sleep1 sleep1 is Start Success  $ nand status -a sleep is Running  by USER in /run/dir sleep1 is Running  by USER in /run/dir sleep is Running  by USER in /tmp
Daemon process can automatically stop at the time limit, you defined.
$ nand start vmstat 5 --sec 600
vmstat will automatically stop after the lapse of 600 seconds.
If you defined Nand
-r option, when the daemon process downed,
it would restart.
$ nand start sleep 100 -r
sleep 100 will be down after 100 seconds, then
will restart soon.
nand stop, Nand send signal(SIGTERM) to daemon process group, and
wait for termination of daemon process. Your daemon process finish by receiving
You must not remove a PID file for Nand
It has be required to confirm integrity.
If you removed it, Nand output an error. Then you need to stop
the daemon process manually.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request