Skip to content

Instantly share code, notes, and snippets.

@xseignard
Created November 29, 2015 19:01
Show Gist options
  • Select an option

  • Save xseignard/19be62730dc4629487ed to your computer and use it in GitHub Desktop.

Select an option

Save xseignard/19be62730dc4629487ed to your computer and use it in GitHub Desktop.
var chai = require('chai'),
should = chai.should(),
sinon = require('sinon'),
sinonChai = require('sinon-chai'),
proc = require('child_process'),
shutdown = require('../../src/tools/shutdown.js');
chai.use(sinonChai);
describe('shutdown()', function(){
beforeEach(function(){
sinon.stub(proc, 'exec');
});
afterEach(function(){
proc.exec.restore();
});
it('should call sync then shutdown shell cmd', function(){
var cbSpy = sinon.spy();
shutdown(cbSpy);
proc.exec.should.be.called;
proc.exec.invokeCallback();
cbSpy.should.be.called;
});
});
@xseignard

Copy link
Copy Markdown
Author
var proc = require('child_process');

/**
 * Shutdown properly the RPi, sync writings and then turn off
 * @param callback {function} callback to be passed when done
 */
var shutdown = function(callback) {
    proc.exec('sync', function(err) {
        proc.exec('shutdown -h now', function(err) {
            callback(err);
        });
    });
};

module.exports = shutdown;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment