takama / daemon

A daemon package for use with Go (golang) services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for LaunchAgents on macOSX

itskingori opened this issue · comments

Summary

I'd like to add support for LaunchAgents (user daemons in macOSX). Use case is I'd like to use this package to manage user daemons. Here's kind of the overview of the differences:

Screenshot 2020-04-15 at 16 08 55

Details

Currently this package supports only LaunchDaemons :

daemon/daemon.go

Lines 9 to 10 in aa76b00

This package is not provide implementation of user daemon,
accordingly must have root rights to install/remove service.

I'm wondering if you would consider adding support for LaunchAgents? Seems where we create the .plist file is the biggest difference (well, that and I guess permissions since it would run as the logged in user):

daemon/daemon_darwin.go

Lines 28 to 31 in aa76b00

// Standard service path for system daemons
func (darwin *darwinRecord) servicePath() string {
return "/Library/LaunchDaemons/" + darwin.name + ".plist"
}

I'd like to take a stab at adding support for this. So consider this a scoping exercise of sorts to:

  1. Gauge your interest - is this something you'd like me to contribute to your library?
  2. Get feedback on approach - before I write any code, wanna know: are you're ok with the approach below?

On approach, I'm thinking of updating darwinRecord to have an userAgent bool field ...

daemon/daemon_darwin.go

Lines 17 to 21 in aa76b00

type darwinRecord struct {
name string
description string
dependencies []string
}

Actual implementation might be slightly different but the idea is provide a way to know what type of deamon we want and then internally change the flow based on use case e.g. use /Library/LaunchAgents/ instead of /Library/LaunchDaemons/ when it's a user daemon, etc.

Lemme know what you think.

References

A very good proposal.

Alright, thanks. Will take create a PR and we can take it from there.

See PR #90.