-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
187 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
device-files/ | ||
virsh-device-daemon | ||
virsh-device-daemon-win64.exe | ||
vendor/*/ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,26 @@ | ||
build: | ||
GOOS=linux GOARCH=amd64 go build github.com/fapiko/virsh-device-daemon | ||
GOOS=windows GOARCH=amd64 go build -o virsh-device-daemon-win64.exe github.com/fapiko/virsh-device-daemon | ||
build-prep: | ||
rm -rf target | ||
mkdir target | ||
|
||
build-linux64: build-prep | ||
GOOS=linux GOARCH=amd64 go build -o target/virsh-device-daemon github.com/fapiko/virsh-device-daemon | ||
|
||
build: build-linux64 | ||
GOOS=windows GOARCH=amd64 go build -o target/virsh-device-daemon-win64.exe github.com/fapiko/virsh-device-daemon | ||
|
||
deb: build-linux64 | ||
cp -r build/deb target/ | ||
mkdir -p target/deb/usr/sbin | ||
chmod 0755 target/virsh-device-daemon | ||
mv target/virsh-device-daemon target/deb/usr/sbin | ||
find ./target/deb -type d | xargs chmod 0755 | ||
fakeroot dpkg-deb --build target/deb | ||
mv target/deb.deb target/virsh-device-daemon_0.1.0_amd64.deb | ||
|
||
test-deb: deb | ||
cp -r build/docker target/ | ||
cp target/virsh-device-daemon_0.1.0_amd64.deb target/docker/ | ||
docker build -t virsh-device-daemon target/docker | ||
|
||
shell-test-deb: | ||
docker run -it virsh-device-daemon /bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Package: virsh-device-daemon | ||
Version: 0.1.0 | ||
Maintainer: Lucas Jandrew <[email protected]> | ||
Architecture: amd64 | ||
Depends: | ||
Description: This is a service which manages attaching and detaching devices to virtual machines using VIRSH. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/sh | ||
# postinst script for virsh-device-daemon | ||
# | ||
# see: dh_installdeb(1) | ||
|
||
set -e | ||
|
||
# summary of how this script can be called: | ||
# * <postinst> `configure' <most-recently-configured-version> | ||
# * <old-postinst> `abort-upgrade' <new version> | ||
# * <conflictor's-postinst> `abort-remove' `in-favour' <package> | ||
# <new-version> | ||
# * <postinst> `abort-remove' | ||
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour' | ||
# <failed-install-package> <version> `removing' | ||
# <conflicting-package> <version> | ||
# for details, see http://www.debian.org/doc/debian-policy/ or | ||
# the debian-policy package | ||
|
||
service=virsh-device-daemon | ||
user=vdd | ||
group=vdd | ||
userdesc="Virsh Device Daemon" | ||
|
||
# create group | ||
if ! getent group ${group} >/dev/null; then | ||
addgroup --system ${group} | ||
fi | ||
|
||
# create user | ||
if ! getent passwd ${user} >/dev/null; then | ||
adduser --system --ingroup ${group} --home /var/lib/${user} \ | ||
--no-create-home --gecos "${userdesc}" \ | ||
--disabled-login ${user} | ||
fi | ||
|
||
# attach to libvirtd group | ||
if ! getent group libvirtd | grep ${user}; then | ||
usermod -a -G libvirtd ${user} | ||
fi | ||
|
||
mkdir -p /var/log/${service} | ||
mkdir -p /etc/${service} | ||
chmod 2750 /etc/${service} | ||
chown -R ${user}:adm /var/log/${service} | ||
chown -R ${user}:${group} /etc/${service} | ||
|
||
# Update profile to enable autocompletion | ||
. /etc/profile | ||
|
||
case "$1" in | ||
configure) | ||
if test -z "$2"; then | ||
# This is a fresh install of the package. | ||
|
||
# On a fresh install, we want to limit permissions on the | ||
# log directory to the owner and the group. Others won't | ||
# have any access to log files: this is in case sensitive | ||
# data are accidentally logged (like process crash data). | ||
chmod 2750 /var/log/${service} | ||
else | ||
# The package was already configured: it's an upgrade over | ||
# a previously installed version, or it's an install over | ||
# a non-purged version (i.e. deinstalled but configuration | ||
# files and data are still there). | ||
true | ||
fi | ||
;; | ||
|
||
abort-upgrade|abort-remove|abort-deconfigure) | ||
;; | ||
|
||
*) | ||
echo "postinst called with unknown argument \`$1'" >&2 | ||
exit 1 | ||
;; | ||
esac | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM ubuntu:16.04 | ||
|
||
COPY virsh-device-daemon_0.1.0_amd64.deb virsh-device-daemon_0.1.0_amd64.deb | ||
RUN dpkg -i virsh-device-daemon_0.1.0_amd64.deb && \ | ||
rm virsh-device-daemon_0.1.0_amd64.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"gopkg.in/yaml.v1" | ||
) | ||
|
||
/* | ||
Config holds the configuration data for running the app in daemon mode | ||
*/ | ||
type Config struct { | ||
Name string `yaml:"name"` | ||
Devices string `yaml:"devices"` | ||
DeviceFiles []string `yaml:"-"` | ||
} | ||
|
||
func parseConfig(path string) (*Config, error) { | ||
configData, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config := &Config{} | ||
err = yaml.Unmarshal(configData, config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if config.Devices != "" { | ||
files, err := ioutil.ReadDir(config.Devices) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, f := range files { | ||
if f.IsDir() == false { | ||
config.DeviceFiles = append(config.DeviceFiles, fmt.Sprintf("%s%s%s", | ||
config.Devices, string(os.PathSeparator), f.Name())) | ||
} | ||
} | ||
} | ||
|
||
return config, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters