docs(README): update installation instructions for various distributions
This commit is contained in:
@@ -48,7 +48,7 @@ jobs:
|
|||||||
[ "$GOOS" = "windows" ] && EXT=".exe"
|
[ "$GOOS" = "windows" ] && EXT=".exe"
|
||||||
NAME="unitdore-${GOOS}-${GOARCH}${EXT}"
|
NAME="unitdore-${GOOS}-${GOARCH}${EXT}"
|
||||||
GOOS="$GOOS" GOARCH="$GOARCH" go build \
|
GOOS="$GOOS" GOARCH="$GOARCH" go build \
|
||||||
-ldflags "-X main.version=${VERSION}" \
|
-ldflags "-X github.com/warkanum/unitdore/cmd.version=${VERSION}" \
|
||||||
-o "$NAME" .
|
-o "$NAME" .
|
||||||
echo "Built $NAME"
|
echo "Built $NAME"
|
||||||
done
|
done
|
||||||
@@ -215,7 +215,7 @@ jobs:
|
|||||||
for GOARCH in amd64 arm64; do
|
for GOARCH in amd64 arm64; do
|
||||||
GOOS=linux GOARCH=$GOARCH go build \
|
GOOS=linux GOARCH=$GOARCH go build \
|
||||||
-trimpath \
|
-trimpath \
|
||||||
-ldflags "-X main.version=${PKGVER}" \
|
-ldflags "-X github.com/warkanum/unitdore/cmd.version=${PKGVER}" \
|
||||||
-o unitdore .
|
-o unitdore .
|
||||||
|
|
||||||
PKGDIR="unitdore_${PKGVER}_${GOARCH}"
|
PKGDIR="unitdore_${PKGVER}_${GOARCH}"
|
||||||
|
|||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Hein (Warky Devs)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
16
Makefile
16
Makefile
@@ -1,8 +1,8 @@
|
|||||||
BINARY := unitdore
|
BINARY := unitdore
|
||||||
INSTALL_DIR := /usr/local/bin
|
INSTALL_DIR := /usr/bin
|
||||||
CONFIG_DIR := /etc/unitdore
|
CONFIG_DIR := /etc/unitdore
|
||||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
LDFLAGS := -ldflags "-X main.version=$(VERSION)"
|
LDFLAGS := -ldflags "-X github.com/warkanum/unitdore/cmd.version=$(VERSION)"
|
||||||
|
|
||||||
.PHONY: all build install uninstall test lint clean release-version
|
.PHONY: all build install uninstall test lint clean release-version
|
||||||
|
|
||||||
@@ -42,17 +42,23 @@ lint:
|
|||||||
clean:
|
clean:
|
||||||
rm -f $(BINARY)
|
rm -f $(BINARY)
|
||||||
|
|
||||||
## release-version: bump patch version, tag, and push to trigger release workflow
|
## release-version: bump patch version, update source versions, commit, tag, and push
|
||||||
release-version:
|
release-version:
|
||||||
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
|
@CURRENT=$$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"); \
|
||||||
MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \
|
MAJOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'); \
|
||||||
MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \
|
MINOR=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'); \
|
||||||
PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \
|
PATCH=$$(echo $$CURRENT | sed 's/v\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'); \
|
||||||
NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
|
NEXT="v$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
|
||||||
|
PKGVER="$$MAJOR.$$MINOR.$$((PATCH + 1))"; \
|
||||||
echo "Current: $$CURRENT → Next: $$NEXT"; \
|
echo "Current: $$CURRENT → Next: $$NEXT"; \
|
||||||
|
sed -i "s/^var version = .*/var version = \"$$PKGVER\"/" cmd/root.go; \
|
||||||
|
sed -i "s/^pkgver=.*/pkgver=$$PKGVER/" pkg/arch/PKGBUILD; \
|
||||||
|
sed -i "s/^Version:.*/Version: $$PKGVER/" pkg/centos/unitdore.spec; \
|
||||||
|
git add cmd/root.go pkg/arch/PKGBUILD pkg/centos/unitdore.spec; \
|
||||||
|
git commit -m "chore(release): update package version to $$PKGVER"; \
|
||||||
git tag -a "$$NEXT" -m "Release $$NEXT"; \
|
git tag -a "$$NEXT" -m "Release $$NEXT"; \
|
||||||
git push origin "$$NEXT"; \
|
git push origin HEAD "$$NEXT"; \
|
||||||
echo "Pushed tag $$NEXT — release workflow triggered"
|
echo "Pushed $$NEXT — release workflow triggered"
|
||||||
|
|
||||||
## help: show this help
|
## help: show this help
|
||||||
help:
|
help:
|
||||||
|
|||||||
26
README.md
26
README.md
@@ -6,6 +6,32 @@ Unitdore bridges your container runtime (Podman, Docker) and systemd. It discove
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
**Arch Linux (AUR)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yay -S unitdore
|
||||||
|
```
|
||||||
|
|
||||||
|
**Debian / Ubuntu**
|
||||||
|
|
||||||
|
Download the `.deb` from the [releases page](https://git.warky.dev/wdevs/unitdore/releases) and install:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo dpkg -i unitdore_*.deb
|
||||||
|
```
|
||||||
|
|
||||||
|
**CentOS / AlmaLinux / Rocky Linux**
|
||||||
|
|
||||||
|
Download the `.rpm` from the [releases page](https://git.warky.dev/wdevs/unitdore/releases) and install:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo rpm -i unitdore-*.rpm
|
||||||
|
# or with dnf:
|
||||||
|
sudo dnf install unitdore-*.rpm
|
||||||
|
```
|
||||||
|
|
||||||
|
**From source**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
make build
|
make build
|
||||||
sudo make install
|
sudo make install
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func runInstall(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix, suffix, serviceUser := cfg.Prefix, cfg.Suffix, cfg.EffectiveServiceUser()
|
prefix, suffix := cfg.Prefix, cfg.Suffix
|
||||||
installed := 0
|
installed := 0
|
||||||
skipped := 0
|
skipped := 0
|
||||||
removed := 0
|
removed := 0
|
||||||
@@ -57,7 +57,7 @@ func runInstall(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if dryRun {
|
if dryRun {
|
||||||
content, err := systemd.Generate(u, prefix, suffix, serviceUser)
|
content, err := systemd.Generate(u, prefix, suffix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf(" ✗ %s: %v\n", u.Name, err)
|
fmt.Printf(" ✗ %s: %v\n", u.Name, err)
|
||||||
continue
|
continue
|
||||||
@@ -68,7 +68,7 @@ func runInstall(cmd *cobra.Command, args []string) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := systemd.Install(u, prefix, suffix, serviceUser); err != nil {
|
if err := systemd.Install(u, prefix, suffix); err != nil {
|
||||||
fmt.Printf(" ✗ failed: %s: %v\n", u.Name, err)
|
fmt.Printf(" ✗ failed: %s: %v\n", u.Name, err)
|
||||||
} else {
|
} else {
|
||||||
path, _ := systemd.UnitPath(u, prefix, suffix)
|
path, _ := systemd.UnitPath(u, prefix, suffix)
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var version = "dev"
|
||||||
|
|
||||||
var configPath string
|
var configPath string
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@@ -16,7 +18,7 @@ var rootCmd = &cobra.Command{
|
|||||||
|
|
||||||
It discovers running containers, stores them in a config file,
|
It discovers running containers, stores them in a config file,
|
||||||
and generates + manages systemd .service units for each one.`,
|
and generates + manages systemd .service units for each one.`,
|
||||||
Version: "0.1.0",
|
Version: version,
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
|
|||||||
@@ -63,10 +63,10 @@ func runUpdate(cmd *cobra.Command, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix, suffix, serviceUser := cfg.Prefix, cfg.Suffix, cfg.EffectiveServiceUser()
|
prefix, suffix := cfg.Prefix, cfg.Suffix
|
||||||
|
|
||||||
if systemd.IsInstalled(*u, prefix, suffix) {
|
if systemd.IsInstalled(*u, prefix, suffix) {
|
||||||
if err := systemd.Install(*u, prefix, suffix, serviceUser); err != nil {
|
if err := systemd.Install(*u, prefix, suffix); err != nil {
|
||||||
return fmt.Errorf("recreating service file: %w", err)
|
return fmt.Errorf("recreating service file: %w", err)
|
||||||
}
|
}
|
||||||
path, _ := systemd.UnitPath(*u, prefix, suffix)
|
path, _ := systemd.UnitPath(*u, prefix, suffix)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -28,18 +27,6 @@ type Config struct {
|
|||||||
Units []Unit `yaml:"units"`
|
Units []Unit `yaml:"units"`
|
||||||
Prefix string `yaml:"prefix,omitempty"` // prepended to generated service name, e.g. "prod-"
|
Prefix string `yaml:"prefix,omitempty"` // prepended to generated service name, e.g. "prod-"
|
||||||
Suffix string `yaml:"suffix,omitempty"` // appended to generated service name, e.g. "-svc"
|
Suffix string `yaml:"suffix,omitempty"` // appended to generated service name, e.g. "-svc"
|
||||||
ServiceUser string `yaml:"service_user,omitempty"` // User= in [Service] section; defaults to "unitdore"
|
|
||||||
}
|
|
||||||
|
|
||||||
// EffectiveServiceUser returns the configured service user, or the current OS user if unset.
|
|
||||||
func (c *Config) EffectiveServiceUser() string {
|
|
||||||
if c.ServiceUser != "" {
|
|
||||||
return c.ServiceUser
|
|
||||||
}
|
|
||||||
if u, err := user.Current(); err == nil {
|
|
||||||
return u.Username
|
|
||||||
}
|
|
||||||
return "root"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load reads and parses the config file at path.
|
// Load reads and parses the config file at path.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Maintainer: Hein (Warky Devs) <hein@warky.dev>
|
# Maintainer: Hein (Warky Devs) <hein@warky.dev>
|
||||||
pkgname=unitdore
|
pkgname=unitdore
|
||||||
pkgver=0.0.4
|
pkgver=0.0.5
|
||||||
pkgrel=1
|
pkgrel=1
|
||||||
pkgdesc="A door you open and close for container units — manage containers via systemd"
|
pkgdesc="A door you open and close for container units — manage containers via systemd"
|
||||||
arch=('x86_64' 'aarch64')
|
arch=('x86_64' 'aarch64')
|
||||||
@@ -20,7 +20,7 @@ build() {
|
|||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
go build \
|
go build \
|
||||||
-trimpath \
|
-trimpath \
|
||||||
-ldflags "-X main.version=$pkgver" \
|
-ldflags "-X github.com/warkanum/unitdore/cmd.version=$pkgver" \
|
||||||
-o "$pkgname" .
|
-o "$pkgname" .
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Name: unitdore
|
Name: unitdore
|
||||||
Version: 0.1.0
|
Version: 0.0.5
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: Manage container units via systemd
|
Summary: Manage container units via systemd
|
||||||
|
|
||||||
@@ -10,6 +10,8 @@ Source0: %{name}-%{version}.tar.gz
|
|||||||
BuildRequires: golang >= 1.23
|
BuildRequires: golang >= 1.23
|
||||||
Requires: systemd
|
Requires: systemd
|
||||||
|
|
||||||
|
%global debug_package %{nil}
|
||||||
|
|
||||||
%description
|
%description
|
||||||
Unitdore bridges your container runtime (Podman, Docker) and systemd.
|
Unitdore bridges your container runtime (Podman, Docker) and systemd.
|
||||||
It discovers running containers, stores them in a config file, and generates
|
It discovers running containers, stores them in a config file, and generates
|
||||||
@@ -22,24 +24,21 @@ and manages systemd .service units for each one.
|
|||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
go build \
|
go build \
|
||||||
-trimpath \
|
-trimpath \
|
||||||
-ldflags "-X main.version=%{version}" \
|
-ldflags "-X github.com/warkanum/unitdore/cmd.version=%{version}" \
|
||||||
-o %{name} .
|
-o %{name} .
|
||||||
|
|
||||||
%install
|
%install
|
||||||
# Binary
|
|
||||||
install -Dm755 %{name} %{buildroot}%{_bindir}/%{name}
|
install -Dm755 %{name} %{buildroot}%{_bindir}/%{name}
|
||||||
|
|
||||||
# Man page
|
|
||||||
install -Dm644 docs/unitdore.1 %{buildroot}%{_mandir}/man1/unitdore.1
|
install -Dm644 docs/unitdore.1 %{buildroot}%{_mandir}/man1/unitdore.1
|
||||||
|
install -Dm644 LICENSE %{buildroot}%{_licensedir}/%{name}/LICENSE
|
||||||
# Config dir
|
|
||||||
install -dm755 %{buildroot}%{_sysconfdir}/unitdore
|
install -dm755 %{buildroot}%{_sysconfdir}/unitdore
|
||||||
|
|
||||||
%files
|
%files
|
||||||
|
%license LICENSE
|
||||||
%{_bindir}/%{name}
|
%{_bindir}/%{name}
|
||||||
%{_mandir}/man1/unitdore.1*
|
%{_mandir}/man1/unitdore.1*
|
||||||
%dir %{_sysconfdir}/unitdore
|
%dir %{_sysconfdir}/unitdore
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
* Tue Apr 08 2026 Hein (Warky Devs) <hein@warky.dev> - 0.1.0-1
|
* Wed Apr 08 2026 Hein (Warky Devs) <hein@warky.dev> - 0.0.5-1
|
||||||
- Initial package
|
- Initial package
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ Package: unitdore
|
|||||||
Version: VERSION
|
Version: VERSION
|
||||||
Architecture: ARCH
|
Architecture: ARCH
|
||||||
Maintainer: Hein (Warky Devs) <hein@warky.dev>
|
Maintainer: Hein (Warky Devs) <hein@warky.dev>
|
||||||
|
Section: admin
|
||||||
|
Priority: optional
|
||||||
|
Homepage: https://git.warky.dev/wdevs/unitdore
|
||||||
Depends: systemd
|
Depends: systemd
|
||||||
Recommends: podman | docker.io
|
Recommends: podman | docker.io
|
||||||
Description: A door you open and close for container units
|
Description: A door you open and close for container units
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ const systemUnitTemplate = `# /etc/systemd/system/{{.ServiceName}}
|
|||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Unitdore: {{.Unit.Name}} ({{.Unit.Runtime}})
|
Description=Unitdore: {{.Unit.Name}} ({{.Unit.Runtime}})
|
||||||
After=network.target
|
After=network.target{{with .RuntimeService}} {{.}}
|
||||||
|
Requires={{.}}{{end}}
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User={{.ServiceUser}}
|
|
||||||
ExecStart={{.ExecStart}}
|
ExecStart={{.ExecStart}}
|
||||||
ExecStop={{.ExecStop}}
|
ExecStop={{.ExecStop}}
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
@@ -50,7 +50,7 @@ type templateData struct {
|
|||||||
Unit config.Unit
|
Unit config.Unit
|
||||||
ExecStart string
|
ExecStart string
|
||||||
ExecStop string
|
ExecStop string
|
||||||
ServiceUser string
|
RuntimeService string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceName returns the systemd service name for a unit, with optional prefix/suffix.
|
// ServiceName returns the systemd service name for a unit, with optional prefix/suffix.
|
||||||
@@ -59,7 +59,7 @@ func ServiceName(u config.Unit, prefix, suffix string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate produces the .service file content for a unit.
|
// Generate produces the .service file content for a unit.
|
||||||
func Generate(u config.Unit, prefix, suffix, serviceUser string) (string, error) {
|
func Generate(u config.Unit, prefix, suffix string) (string, error) {
|
||||||
execStart, execStop := buildExecCommands(u)
|
execStart, execStop := buildExecCommands(u)
|
||||||
|
|
||||||
data := templateData{
|
data := templateData{
|
||||||
@@ -67,7 +67,7 @@ func Generate(u config.Unit, prefix, suffix, serviceUser string) (string, error)
|
|||||||
Unit: u,
|
Unit: u,
|
||||||
ExecStart: execStart,
|
ExecStart: execStart,
|
||||||
ExecStop: execStop,
|
ExecStop: execStop,
|
||||||
ServiceUser: serviceUser,
|
RuntimeService: runtimeService(u.Runtime),
|
||||||
}
|
}
|
||||||
|
|
||||||
tmplStr := systemUnitTemplate
|
tmplStr := systemUnitTemplate
|
||||||
@@ -87,6 +87,15 @@ func Generate(u config.Unit, prefix, suffix, serviceUser string) (string, error)
|
|||||||
return buf.String(), nil
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// runtimeService returns the systemd service name that must be running for the
|
||||||
|
// given container runtime, or "" if none is required (e.g. daemonless podman).
|
||||||
|
func runtimeService(runtime string) string {
|
||||||
|
if runtime == "docker" {
|
||||||
|
return "docker.service"
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func buildExecCommands(u config.Unit) (start, stop string) {
|
func buildExecCommands(u config.Unit) (start, stop string) {
|
||||||
// If a custom command is provided, use it directly
|
// If a custom command is provided, use it directly
|
||||||
if u.Command != "" {
|
if u.Command != "" {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestGenerate_SystemUnit(t *testing.T) {
|
|||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := Generate(u, "", "", "unitdore")
|
content, err := Generate(u, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Generate() error: %v", err)
|
t.Fatalf("Generate() error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,13 @@ func TestGenerate_SystemUnit(t *testing.T) {
|
|||||||
t.Errorf("Generate() missing %q in output:\n%s", check, content)
|
t.Errorf("Generate() missing %q in output:\n%s", check, content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(content, "User=") {
|
||||||
|
t.Errorf("Generate() system unit should not contain User= directive:\n%s", content)
|
||||||
|
}
|
||||||
|
if strings.Contains(content, "Requires=") {
|
||||||
|
t.Errorf("Generate() podman system unit should not contain Requires= (podman is daemonless):\n%s", content)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenerate_UserUnit(t *testing.T) {
|
func TestGenerate_UserUnit(t *testing.T) {
|
||||||
@@ -70,7 +77,7 @@ func TestGenerate_UserUnit(t *testing.T) {
|
|||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := Generate(u, "", "", "unitdore")
|
content, err := Generate(u, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Generate() error: %v", err)
|
t.Fatalf("Generate() error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -101,7 +108,7 @@ func TestGenerate_CustomCommand(t *testing.T) {
|
|||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := Generate(u, "", "", "unitdore")
|
content, err := Generate(u, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Generate() error: %v", err)
|
t.Fatalf("Generate() error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -118,16 +125,21 @@ func TestGenerate_DockerRuntime(t *testing.T) {
|
|||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := Generate(u, "", "", "unitdore")
|
content, err := Generate(u, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Generate() error: %v", err)
|
t.Fatalf("Generate() error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.Contains(content, "ExecStart=/usr/bin/docker start redis") {
|
checks := []string{
|
||||||
t.Errorf("Generate() wrong ExecStart for docker:\n%s", content)
|
"ExecStart=/usr/bin/docker start redis",
|
||||||
|
"ExecStop=/usr/bin/docker stop redis",
|
||||||
|
"After=network.target docker.service",
|
||||||
|
"Requires=docker.service",
|
||||||
|
}
|
||||||
|
for _, check := range checks {
|
||||||
|
if !strings.Contains(content, check) {
|
||||||
|
t.Errorf("Generate() docker runtime missing %q in output:\n%s", check, content)
|
||||||
}
|
}
|
||||||
if !strings.Contains(content, "ExecStop=/usr/bin/docker stop redis") {
|
|
||||||
t.Errorf("Generate() wrong ExecStop for docker:\n%s", content)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +150,7 @@ func TestGenerate_UnknownRuntime(t *testing.T) {
|
|||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := Generate(u, "", "", "unitdore")
|
content, err := Generate(u, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Generate() should not error on unknown runtime: %v", err)
|
t.Fatalf("Generate() should not error on unknown runtime: %v", err)
|
||||||
}
|
}
|
||||||
@@ -155,7 +167,7 @@ func TestGenerate_WithPrefixSuffix(t *testing.T) {
|
|||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, err := Generate(u, "prod-", "-web", "unitdore")
|
content, err := Generate(u, "prod-", "-web")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Generate() error: %v", err)
|
t.Fatalf("Generate() error: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ func UnitPath(u config.Unit, prefix, suffix string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Install writes the .service file for a unit and reloads systemd.
|
// Install writes the .service file for a unit and reloads systemd.
|
||||||
func Install(u config.Unit, prefix, suffix, serviceUser string) error {
|
func Install(u config.Unit, prefix, suffix string) error {
|
||||||
content, err := Generate(u, prefix, suffix, serviceUser)
|
content, err := Generate(u, prefix, suffix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user