Given a process PID and a sequence of alternating signals and sleep durations, morta will perform the sequence against the PID until either the process is dead, or the sequence has completed.
Head to the morta releases and download the latest version for your platform.
Each download is a compressed archive (.tar.gz for Linux, .zip for macOS). Extract it, then copy the morta binary to /usr/local/bin and make sure it is executable via chmod +x /usr/local/bin/morta. From this point on, you can run morta update to update it automatically.
Let's use unicorn as an example, which is an HTTP server for Rack applications. Looking at its help page for signals, we can see the following signals defined for the master process:
| Signal | Result |
|---|---|
| QUIT | graceful shutdown, waits for workers to finish their current request before finishing |
| INT/TERM | quick shutdown, kills all workers immediately |
| KILL | terminate process immediately, uncatchable |
From this, a reasonable sequence of signals might be the following:
- send SIGQUIT to the master process if it exists
- wait 30 seconds or until master is dead, whichever comes first
- send SIGTERM to the master process if it exists
- wait 10 seconds or until master is dead, whichever comes first
- send SIGKILL to the master process if it exists
Assuming that the master unicorn process has a PID of 1234, you can then run the following to perform the above sequence:
$ morta -p 1234 -s "quit:30:term:10:kill"
You can then use this in your process manager to terminate the process as cleanly as possible. For example, if you're using systemd, you can add the following to your service definition:
ExecStop=-/usr/local/bin/morta -p $MAINPID -s "quit:30:term:10:kill"
Manually checks for and installs the latest version. Pass -f to install a specific version instead.
$ morta update [-f version]
Shows the version (and build date for released binaries).
$ morta version
