mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
This patch changes the systemd backend and all associated interfaces (currently that's only the GPIO interface) to the new interface APIs. Since the systemd backend used the json-snippet hack (as a rough prototype to the new API) the changes are actually smaller than in the case of the mount backend. The JSON bridge is discarded and the GPIO interface now uses just one method to convey the need for a custom systemd service unit. Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
// -*- Mode: Go; indent-tabs-mode: t -*-
|
|
|
|
/*
|
|
* Copyright (C) 2016-2017 Canonical Ltd
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 3 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
package systemd
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
)
|
|
|
|
// Service describes a single systemd service file
|
|
type Service struct {
|
|
Description string
|
|
Type string
|
|
RemainAfterExit bool
|
|
ExecStart string
|
|
ExecStop string
|
|
}
|
|
|
|
func (s *Service) String() string {
|
|
var buf bytes.Buffer
|
|
if s.Description != "" {
|
|
buf.WriteString("[Unit]\n")
|
|
fmt.Fprintf(&buf, "Description=%s\n\n", s.Description)
|
|
}
|
|
buf.WriteString("[Service]\n")
|
|
if s.Type != "" {
|
|
fmt.Fprintf(&buf, "Type=%s\n", s.Type)
|
|
}
|
|
// "no" is the default in systemd so we don't neet to write it
|
|
if s.RemainAfterExit {
|
|
buf.WriteString("RemainAfterExit=yes\n")
|
|
}
|
|
if s.ExecStart != "" {
|
|
fmt.Fprintf(&buf, "ExecStart=%s\n", s.ExecStart)
|
|
}
|
|
if s.ExecStop != "" {
|
|
fmt.Fprintf(&buf, "ExecStop=%s\n", s.ExecStop)
|
|
}
|
|
fmt.Fprintf(&buf, "\n[Install]\nWantedBy=multi-user.target\n")
|
|
return buf.String()
|
|
}
|