snappy: refactor ServiceDescription away #1114

Merged
merged 26 commits into from May 2, 2016

Conversation

Projects
None yet
3 participants
Contributor

zyga commented May 2, 2016

This branch, through successive small changes, entirely removes snappy.ServiceDescription since it can be completely derived from snap.AppInfo

zyga added some commits May 2, 2016

snappy: store and pass snap.AppInfo in ServiceDescription
Affected tests are changed to store the yet-unused AppInfo object

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: use ListenStream and SocketMode from AppInfo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: refactor GenSocketFile to take just snap.AppInfo
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Type, use App.Daemon
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.BusName, use App.BusName
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.AaProfile, use App.SecurityTag
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.UdevAppName, use App.SecurityTag
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Version, use App.Snap.Version
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.AppName
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.SnapName
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Revision
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Stat, use App.Command
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Stop, use App.Stop
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.PostStop, use App.PostStop
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.StopTimeout, use App.StopTimeout
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.{ListenStream,SocketMode}
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Socket use App.Socket
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.ServiceFileName
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.SocketFileName
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.SnapPath, compute locally from Mou…
…ntDir

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Restart, use App.RestartCond
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription.Description, generate locally
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: provide real description for .socket files
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: discard ServiceDescription, pass AppInfo directly
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy/services.go
-Description={{.Description}}
-After=snapd.frameworks.target{{ if .Socket }} {{.SocketFileName}}{{end}}
-Requires=snapd.frameworks.target{{ if .Socket }} {{.SocketFileName}}{{end}}
+Description=service {{.App.Name}} for snap {{.App.Snap.Name}} - autogenerated DO NO EDIT
@pedronis

pedronis May 2, 2016

Contributor

I would put as least the "DO NO EDIT" bit in a comment

@zyga

zyga May 2, 2016

Contributor

Good idea!

@zyga

zyga May 2, 2016

Contributor

Changed

snappy/services.go
X-Snappy=yes
[Service]
-ExecStart=/usr/bin/ubuntu-core-launcher {{.UdevAppName}} {{.AaProfile}} {{.FullPathStart}}
+ExecStart=/usr/bin/ubuntu-core-launcher {{.App.SecurityTag}} {{.App.SecurityTag}} {{.FullPathStart}}
Restart={{.Restart}}
WorkingDirectory=/var{{.SnapPath}}
@pedronis

pedronis May 2, 2016

Contributor

this should be {{.App.DataDir}} now, no?

@zyga

zyga May 2, 2016

Contributor

DataDir will be affected by root directory changes.

@pedronis

pedronis May 2, 2016

Contributor

well, then do like for SnapPath for now, but the /var is a hack making assumptions

@zyga

zyga May 2, 2016

Contributor

Done

snappy/services.go
serviceTemplate := `[Unit]
-Description={{.Description}} Socket Unit File
+Description=socket {{.App.Name}} for snap {{.App.Snap.Name}} - autogenerated DO NO EDIT
@niemeyer

niemeyer May 2, 2016

Contributor

Socket {{.App.Name}} for snap {{.App.Snap.Name}}

Capital-cased like other service/socket file, and no need to say auto-generated. These files usually come inside the package, and people are used to not fiddling with them.

@pedronis

pedronis May 2, 2016

Contributor

same about DO NO EDIT

@niemeyer

niemeyer May 2, 2016

Contributor

Hmm.. that will be a weird sentence depending on the name of the snap and app.

How about:

Socket for snap application {{.App.Snap.Name}}.{{.App.Name}}

@zyga

zyga May 2, 2016

Contributor

Yeah, that looks nicer.

@zyga

zyga May 2, 2016

Contributor

Changed

restartCond,
- desc.Type,
+ serviceStopTimeout(appInfo),
+ appInfo.Snap.Version,
@niemeyer

niemeyer May 2, 2016

Contributor

Why is App not being used for these?

@zyga

zyga May 2, 2016

Contributor

This is a separate refactor I'm already looking at. This is because dedicated fields are required by snapenv API today.

@pedronis

pedronis May 2, 2016

Contributor

the first falls back to a default timeout which is a piece of policy that is unclear if it belongs to snap/ but it could be done with other tools offered by templating starting from the value in App

@zyga

zyga May 2, 2016

Contributor

I plan to make a small refactoring branch that will move such assumptions to snap.yaml parsing. It is less harmful if defaults are applied in one spot only.

@niemeyer

niemeyer May 2, 2016

Contributor

Isn't this actually the same refactoring being done in this branch? I mean, this is just about using {{.App.Snap.Version}} in that template instead of {{Version}}, isn't it?

@pedronis

pedronis May 2, 2016

Contributor

I think he is talking about serviceStopTimeout, I have mixed feelings about making that a snap/ concern

+ // service file, this ensures that /snap/foo/1.0/bin/start
+ // is in the service file when the SetRoot() option
+ // is used
+ realBaseDir := stripGlobalRootDir(baseDir)
@pedronis

pedronis May 2, 2016

Contributor

given that u-d-f doesn't do this, this is mostly for the benefit of the tests wondering if there is some other way around that, anyway, may be for a later branch

@zyga

zyga May 2, 2016

Contributor

I kept this code around as-is but personally I think we should not do this. If you agree I can remove it and adjust tests (though tests will look more verbose)

zyga added some commits May 2, 2016

snappy: tweak generated descriptions
Move auto-generated from Description to a comment.  Use better wording
for the interesting part.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
snappy: don't hardcode /var, use AppInfo.DataDir
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Contributor

niemeyer commented May 2, 2016

LGTM

@pedronis pedronis merged commit e80ddfe into snapcore:master May 2, 2016

4 checks passed

Integration tests Success
Details
autopkgtest Success
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.02%) to 79.453%
Details

@zyga zyga deleted the zyga:all-roads-lead-to-apps branch Dec 12, 2016

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