npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mh-cbon/launchd-simple-api

v1.3.4

Published

Simple API to manage services via macosx launchd

Downloads

32

Readme

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

  • http://launchd.info/
  • https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html
  • https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html
  • http://alvinalexander.com/mac-os-x/launchd-examples-launchd-plist-file-examples-mac