@mh-cbon/launchd-simple-api
Simple API to manage services via macosx launchd
Last updated 4 years ago by mh-cbon .
MIT · Original npm · Tarball · package.json
$ cnpm install @mh-cbon/launchd-simple-api 
SYNC missed versions from official npm registry.

launchd-simple-api

Simple API to manage services via macosx launchd

Install

npm i @mh-cbon/launchd-simple-api --save

Usage

var LaunchSimpleApi = require('@mh-cbon/launchd-simple-api')

var lsa = new LaunchSimpleApi()

// launchctl list
lsa.list(function (err, items) {
  console.log(items)
})

// find the service file definition,
// then convert it to a json object with plutil
lsa.describe("serviceId", function (err, info) {
  console.log(info)
})

// convert given service file to a json object with plutil
lsa.describeFile("/SystemLibrary/Myservice.plist", function (err, info) {
  console.log(info)
})

// find the service file definition,
// then, launchctl load /the/service/file.plist
lsa.load('fake', {disabled: false, force: false, domain: null, session:null}, function (err) {
  err && console.error(err);
})

// launchctl load /the/service/file.plist
var opts = {disabled: false, force: false, domain: null, session:null}
lsa.loadServiceFile('/SystemLibrary/Myservice.plist', opts, function (err) {
  err && console.error(err);
})

// find the service file definition,
// then, launchctl unload /the/service/file.plist
lsa.unload('fake', {disabled: false, domain: null, session:null}, function (err) {
  err && console.error(err);
})

// launchctl unload /the/service/file.plist
var opts = {disabled: false, domain: null, session:null}
lsa.unloadServiceFile('/SystemLibrary/Myservice.plist', opts, function (err) {
  err && console.error(err);
})

// Look up through each defaults macosx service definition directories
// and try to find for a file named such [service name].plist
lsa.findUnitFile('fake', function (err, list) {
  console.log(list)
})

// Test validity of the given plist service definition file
// plutil /SystemLibrary/Myservice.plist
lsa.testUnitFile('/SystemLibrary/Myservice.plist', function (err) {
  err && console.error(err);
})

// Convert given plist service file into a JSON object
// plutil -convert json -o - /SystemLibrary/Myservice.plist
lsa.convertUnitFile('/SystemLibrary/Myservice.plist', 'json', function (err, info) {
  err && console.error(err);
  console.log(info)
})

// Convert given JSON object into a valid plist content
// plutil -convert json -o - - (< JSON object into stdin)
lsa.convertJsonToPlist({some: 'object'}, function (err, info) {
  err && console.error(err);
  console.log(info)
})

// launhctl start serviceId
lsa.start('serviceId', function (err) {
  err && console.error(err);
})

// launhctl stop serviceId
lsa.stop('serviceId', function (err) {
  err && console.error(err);
})

// launhctl start serviceId
// launhctl stop serviceId
lsa.restart('serviceId', function (err) {
  err && console.error(err);
})

// Find all service file definition for given options
/*
domain === user         => ~/Library/LaunchAgents
domain === global
   jobType === agent    => /Library/LaunchAgents
   jobType === daemon   => /Library/LaunchDaemons
domain === system
   jobType === agent    => /System/Library/LaunchAgents
   jobType === daemon   => /System/Library/LaunchDaemons
*/
lsa.listUnitFiles({domain: 'global', jobType: 'agents'}, function (err, list) {
  console.log(list)
})

Install a service

var service = {
  domain: 'user',
  plist: {
    Label: 'fake',
    ProgramArguments: [
      '/Users/vagrant/node/node-v5.9.1-darwin-x64/bin/node',
      '/Users/vagrant/wd/utils/fake-service.js'
    ]
  }
}
lsa.install(service, function (err, results) {
  err && console.error(err);
  var serviceFile = '/Users/vagrant/Library/LaunchAgents/fake.plist';
  fs.readFile(serviceFile, function (err2, content){
    err2 && console.error(err2);
    console.log(content.toString())
  })
})

// find the corresponding service file, then deletes it
lsa.uninstall('fake', function (err, results) {
  err && console.error(err);
})

// deletes given service file definition
lsa.uninstallUnitFile('/Users/vagrant/Library/LaunchAgents/fake.plist', function (err, results) {
  err && console.error(err);
})

Read more

Current Tags

  • 1.3.4                                ...           latest (4 years ago)

19 Versions

  • 1.3.4                                ...           4 years ago
  • 1.3.3                                ...           4 years ago
  • 1.3.2                                ...           4 years ago
  • 1.3.1                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.12                                ...           4 years ago
  • 1.0.11                                ...           4 years ago
  • 1.0.10                                ...           4 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |