-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add service cmd #3
Conversation
cmd/service/executor.go
Outdated
proc := cmd.Process | ||
procState := cmd.ProcessState |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though these are just shorthand variables. They should stand out more than hide. The indented var draws attention to the area near the call to Start
which is significant, but easy to gloss over when cluttered like this.
Besides, we use the multi-line var liberally throughout the code, so something something consistency too.
proc := cmd.Process | |
procState := cmd.ProcessState | |
var ( | |
proc = cmd.Process | |
procState = cmd.ProcessState | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, it's probably better to at least move procState into the error encountered branch where it's used. I'll reconsider this whole section later.
443f194
to
3fc5ecf
Compare
c4c1d44
to
d07faed
Compare
Ci is being a nuisance. Likely has to do with multi-line output from Edit: I was trying to rely more on the action expressions than shelling out to binaries; but it's easier to just use Ideally this would just work, but doesn't. - name: Setup specific Go version
uses: actions/setup-go@v2
with:
go-version: ${{ fromJSON($(go mod edit -json)).Go }} Even when used from seperate steps, the JSON data is truncated if multi-line. - name: Parse Go mod file
id: go_mod_parse
run: echo "::set-output name=go_mod_json::$(go mod edit -json)"
- name: Setup specific Go version
uses: actions/setup-go@v2
with:
go-version: ${{ fromJSON(steps.go_mod_parse.outputs.go_mod_json).Go }} With the setup seemingly working, I just need to link the jobs together correctly. |
4bc5f9b
to
47215f7
Compare
CI seems good enough for now. Unfortunately, it looks like the If it's not too difficult, those platforms should get a CI instance as well. |
c4f42b5
to
cf74628
Compare
Things in progress:
With the exception of bugfixes and refactoring, there shouldn't be much more to do in regards to spawning the daemon, or managing the system service.
When that's all out of the way, we should be able to start focusing on the portions of code which perform the actual file system binding. Giving the program the ability to fulfill the requests we've been preparing it to receive. The journal version of basically the same message but very verbose:I broke the macOS builds with the systemd patch to the `service` library, but resolved that [in this diff](https://github.com/djdv/service/compare/eb90fecf335399bac9202b2df592a9cf36f207d1...3b4ca4320e3c98c8c923bae54a8a04540300ec75?diff=split). This needs to be split up later, and ideally moved into more upstream PRs.The diff fixes the status issue with systemd on Linux (if the service is not installed Right now on macOS, we create the socket in We can initialize the parent directory with more lax permissions on service start to resolve this (like we currently do for the Windows implementation), however; launchd offers a Using the service property would give the service manager better comprehension and control over our service, allowing for things like starting the service on demand rather than say on boot. I tested this by modifying the plist directly, but there seems to be restrictions around Since the system service socket's path will change, our functions that look for it will have to change as well. While looking into this I realized we'll probably want to preserve (non-OS specific) arguments passed to On a launchd system, this should construct a launchd plist which tells the service manager to spawn a socket that starts the service on demand (when a client tries to connect to it,) rather than starting it at boot. We'd also retain the generic arguments provided like Combined, this would result in a launchd service that starts on demand and calls our daemon with its auto-stop arguments. *I know this is true for Start, but need to check how systemd and launchd deal with soft-stops like that. It might require patching the Considering the binary currently does nothing, none of this matters right now. For example, we could compose a hypothetical auto-mount service. You can imagine creating this auto-mount service with the condition of starting after login (as opposed to starting on init). Considering we don't have a config format defined yet, another example would be using your own. |
I made the modifications mentioned above to the service library we depend on. The code in this PR will need some changes to accommodate that feature too. While that change is minor, I developed some concerns with the way settings data is handled in the program generally. Keeping with the trend, I put more info than necessary in the block below. Mostly notes for myself that might be needed later, but obviously anyone interested can read them too. JournalAs with most programs, our API logic is set up to handle various parameters for the program. For example, the For reasons like the patch above, the API surface might have to change. We use an abstraction The We're going to have to start porting the One of the concerns I have at the moment is around how we expose fundamental settings to a client. For Something as simple as exporting I'm am worried about Go's type system in relation to some of this. It may or may not get in the way of some of the generic patterns I have in mind. E.g. Something concise like type Parameter struct{}
var someParameter = &Parameter{...}
var someIntValue, provided, err = someParameter.ArgFrom(request) is likely impossible to define when considering variable types. type StringParameter {...}
type IntParameter {...}
...
var someParameter = &IntParameter{...}
var someInt, provided, err = someParameter.From(request) or some equally explicit combination. Like maybe on the method side instead. someParameter.StringFrom(request) Ideally I'll be happy if I can get something that looks closer to this apiMaddr, provided, err := serviceMaddr.From(cmdline, env, conf, default) Where I'm going to mess around with this more later. I'm wondering if something conceptually similar to functional options would be applicable here. It's also possible (although unlikely) that we decide to use Whether this is worth the time or not, I'm not sure. Likely not worth it since these things don't change much and anything important is already in here. Anything new could just be added "by hand" upon request from actual users when they actually want/need to use them with these packages. |
Edit: It looks like I dropped commits during the rebase. ee3c99e is missing a few changes from its parent branch Resetting the branch, basically just squashing everything and rebasing it on the other branch that was reset. Old history is here: dd78d01 For now though I want to spawn a new branch off of this one, so it's getting pushed here and will be worked on after some progress on the other branch (relating to configuration and the mount interfaces). Responding to myself
Ended up with something close enough which I'm content with. func fileSystemServiceRun(request *cmds.Request, _ cmds.ResponseEmitter, env cmds.Environment) error {
var (
ctx = request.Context
settings = new(Settings)
unsetArgsChan, errs = parameters.ParseSettings(ctx, settings,
parameters.SettingsFromCmds(request),
parameters.SettingsFromEnvironment(),
)
unsetArgsSlice, err = parameters.AccumulateArgs(ctx, unsetArgs, errs)
)
if err != nil {
return err
}
... We should be able to add something like |
This all seems to work okay. There's some platform stuff that needs to be cleaned up, as well as general review and documentation. I'm going to try and move the cmds Executor and Environment into their own pkg, We'll see how this goes. |
Works but needs review.
82a961b had logical problems. We'd never have arguments to supply from the user if we're calling this function. And supplying them ourselves caused the service to expect the service socket directory to already exist (which it usually won't). Instead of telling the server what address to use and trusting it, we use an address provided by the server and try to dial it.
More journaling:
The separation using an intermediate Despite the CI failure, the current commit has worked pretty well for what it's intended for. The current issue with this code is mainly the shoddy tests. Which come as a result of poor orchestration capabilities. While implementing the new version of the mount-related code in the development branch, I have made changes to the code in this PR to remedy these problems. This PR/command however, is overly complicated. It deals both with the host OS service interfaces (like the service manager, systemd, launchd, et al.) as well as being the command which hosts/exposes our IPC API via a daemon process listening on sockets. I want to split this up so that the
All of this should simplify both the code and allow me to better test them separately. |
The comment above was done but it's in need of review. A new PR will replace this one since it's full of me talking to myself with outdated information. |
The
service
command acts both as the server command for our service, but also has subcommands that interface with the system service manager.Allowing the program to be registered with the host, and managed by it.
The service command may be called directly from the command line, either by a user to run interactively, or by the host to run in system service mode.
Client commands will try to find either of these instances by default. If not found, the executor will automatically try to launch an instance of the server. (The launched service shuts down and exits automatically later, if not busy)