├── test.js ├── index.js ├── LICENSE ├── package.json ├── README.md └── .travis.yml /test.js: -------------------------------------------------------------------------------- 1 | var siginfo = require('.') 2 | var pkg = require('./package.json') 3 | 4 | var stop = siginfo(function () { 5 | console.dir({ 6 | version: pkg.version, 7 | uptime: process.uptime() 8 | }) 9 | }) 10 | 11 | process.stdout.resume() 12 | 13 | setTimeout(function () { 14 | stop() 15 | process.exit(0) 16 | }, 2000) 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = function (query, force) { 2 | var isAttached = false 3 | if (process.stderr.isTTY || force === true) { 4 | isAttached = true 5 | process.on('SIGINFO', onsiginfo) 6 | process.on('SIGUSR1', onsiginfo) 7 | } 8 | 9 | return function () { 10 | if (isAttached === true) { 11 | process.removeListener('SIGINFO', onsiginfo) 12 | process.removeListener('SIGUSR1', onsiginfo) 13 | isAttached = false 14 | } 15 | } 16 | 17 | function onsiginfo () { 18 | query() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017, Emil Bay 2 | 3 | Permission to use, copy, modify, and/or distribute this software for any 4 | purpose with or without fee is hereby granted, provided that the above 5 | copyright notice and this permission notice appear in all copies. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "siginfo", 3 | "version": "2.0.0", 4 | "description": "Utility module to print pretty messages on SIGINFO/SIGUSR1", 5 | "main": "index.js", 6 | "dependencies": {}, 7 | "devDependencies": { 8 | "standard": "^14.3.4" 9 | }, 10 | "scripts": { 11 | "test": "standard" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/emilbayes/siginfo.git" 16 | }, 17 | "keywords": [ 18 | "siginfo", 19 | "sigusr1", 20 | "ctrl", 21 | "t", 22 | "info", 23 | "progress", 24 | "inspect" 25 | ], 26 | "author": "Emil Bay ", 27 | "license": "ISC", 28 | "bugs": { 29 | "url": "https://github.com/emilbayes/siginfo/issues" 30 | }, 31 | "homepage": "https://github.com/emilbayes/siginfo#readme" 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `siginfo` 2 | 3 | [![Build Status](https://travis-ci.org/emilbayes/siginfo.svg?branch=master)](https://travis-ci.org/eemilbayes/siginfo) 4 | 5 | > Utility module to print pretty messages on SIGINFO/SIGUSR1 6 | 7 | `SIGINFO` on BSD / macOS and `SIGUSR1` on Linux, usually triggered by 8 | `Ctrl + T`, are by convention used to print information about 9 | a long running process internal state. Eg. `dd` will tell you how many blocks it 10 | has written and at what speed, while `xz` will tell you progress, compression 11 | ratio and estimated time remaining. 12 | 13 | This module wraps both signals, checks if the process is connected to TTY and 14 | lets you do whatever you want. 15 | 16 | ## Usage 17 | 18 | ```js 19 | var siginfo = require('siginfo') 20 | var pkg = require('./package.json') 21 | 22 | siginfo(function () { 23 | console.dir({ 24 | version: pkg.version, 25 | uptime: process.uptime() 26 | }) 27 | }) 28 | 29 | ``` 30 | 31 | ## API 32 | 33 | ### `var removeListener = siginfo(queryFn, [force])` 34 | 35 | `queryFn` can be used for whatever you want (logging, sending a UDP message, etc.). 36 | Setting `force = true` will attach the event handlers whether a TTY is present 37 | or not. 38 | 39 | ## Install 40 | 41 | ```sh 42 | npm install siginfo 43 | ``` 44 | 45 | ## License 46 | 47 | [ISC](LICENSE) 48 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | notifications: 2 | email: false 3 | language: node_js 4 | node_js: 5 | - node 6 | deploy: 7 | provider: npm 8 | email: 9 | secure: Y10Dvn9UbfpZPbulnl/e7dsiN/1xr06h7k6nJZyxRzr9Hh0UUFPism6k5CFaSegyPIF7sODNBQz4lvXIi2NwcvTLQruw5ehXW0NJ/G7x1TU94pzzhVJ31KBlRWzjKdvVTDsDzFxe5wKWxagPUTkieiIN9CWTQjafByNs3zbK8HL7cmu4Nc42JquVGbtpGgLs7Js+tY+WVB1dMQ4SfqpFgWjm2h05uyXCWHLK5amEAZJLP755lOVgMzw/jQGRg7J4vX4+eRE0r/g0v09x9FUU3ROEmJvqYa14CmGESRhSUyRlv4pnMIs/aK8ZDD8ia3eoTSvMJv8mzdvpkvKzWV1HSZFUX3QZVgWJEmeoF6XP+mdkWu5gnZVlOIBc8NANcS60Dr8QwF470xpPxsyAyf2o9UzX8Xy2qO8XNY/TykGO4soCfOEuVNdw5F9hHEldMHY8p9Z8EJSCn/xfM//LEvxRKREYsMqFtsnwUsv+qiAkHPSHXWQo6HYp+/xDchv63NxtjGHdPs9VpUFr1F8CxZjdis2HZfOnx51W0JIwNYlXNxeqC3WjRUqvRp2NknS982lRHCkHtZfHijGvMm7kj3QL+Ufc7pIfEGnMAKKiNv9kOryjQc29046pRZww9lWjrhoCeEPRhFbkgFV7Mo3bvOExstsSdRnOTlogCe4NviKOwfE= 10 | api_key: 11 | secure: cAmf8extX/sPl+sxC/6sWTmaiSGrXQY9C/lLg9c76Qn12MLysxDYgCRXfl8Az3RIbRuajq0SbyWXeDa/4wZc1PazuUGjZG82na+kuEDg8m5z0gLiJlhp60C0nj3WMJaRBRsOha1Jbs59eU3XNy+H0U5VczHrdw6v2yCHTlauhT/NYiPXMyKmTIJPB/X7gryFuXVhCPNdRBp3rPicbt0d68J+vWv9KNpjA1WB0WDUSl5rMUQbjjsRF2/DKj9WxXjmci+ac+/pCN3rQxgYZ0Ot5o5/RcWucc21ZdFgsLo8dq5YZDl/EQf/pPmkhquiiLRhiTyCBbEw1sDzYHTbTJThrukrZALg0on7XvxbXSQrxgc/IMJ/RT0PoGLEqyAZUSzGa6HPVlHUBt4LB3zgrswGmGUVkZmbiag0foIFeCKlydwEyBYfnFdRddxF6n3irft1l1NJ1HKNxKLnKvyt8iaOlGteXOOfLXzU17DgMgwTsZsvFmtFQcs6yolLHW9RnRTLf56+x/kJZ4kVJjHuyb/98pS4F7etJ2SpZqt1cVUFd/AYtnxL3jKiUhJLNL8hNUIH3eSpMfZUOUxGv1OWuwgyEhSONkITF2VPn4yuyxS23Ewq4LLj/u/9sPlLaGSN4Avaw21gi6L+M9x620sTZHYtNLniVMTAu6aPiM32zPreK2I= 12 | on: 13 | tags: true 14 | --------------------------------------------------------------------------------