Skip to content

Commit

Permalink
Merge pull request #14 from funbox/develop
Browse files Browse the repository at this point in the history
Version 0.9.0
  • Loading branch information
andyone authored Apr 3, 2017
2 parents 986241f + 7c8e047 commit 40a8ca6
Show file tree
Hide file tree
Showing 18 changed files with 877 additions and 367 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ before_install:

script:
- make test
- make bin
- make all
- ./init-exporter --version
- ./init-exporter-converter --version
30 changes: 18 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,47 @@ PREFIX?=/usr

########################################################################################

.PHONY = all clean install uninstall deps deps-glide test
.PHONY = all clean install uninstall deps deps-glide test upstart-playground systemd-playground

########################################################################################

all: bin
all: init-exporter init-exporter-converter

init-exporter:
go build init-exporter.go

init-exporter-converter:
go build init-exporter-converter.go

deps:
go get -v pkg.re/check.v1
go get -v pkg.re/essentialkaos/ek.v7
go get -v pkg.re/essentialkaos/go-simpleyaml.v1
go get -v pkg.re/yaml.v2
go get -d -v pkg.re/check.v1
go get -d -v pkg.re/essentialkaos/ek.v7
go get -d -v pkg.re/essentialkaos/go-simpleyaml.v1
go get -d -v pkg.re/yaml.v2

deps-glide:
glide install

bin:
go build init-exporter.go

fmt:
find . -name "*.go" -exec gofmt -s -w {} \;

test:
go test ./... -covermode=count
go test ./procfile ./export -covermode=count

install:
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp init-exporter $(DESTDIR)$(PREFIX)/sbin/
cp init-exporter $(DESTDIR)$(PREFIX)/bin/
cp init-exporter-converter $(DESTDIR)$(PREFIX)/bin/
cp common/init-exporter.conf $(DESTDIR)/etc/

uninstall:
rm -f $(DESTDIR)$(PREFIX)/sbin/init-exporter
rm -f $(DESTDIR)$(PREFIX)/bin/init-exporter
rm -f $(DESTDIR)$(PREFIX)/bin/init-exporter-converter
rm -rf $(DESTDIR)/etc/init-exporter.conf

clean:
rm -f init-exporter
rm -f init-exporter-converter

upstart-playground:
docker build -f ./Dockerfile.upstart -t upstart-playground . && docker run -ti --rm=true upstart-playground /bin/bash
Expand Down
42 changes: 32 additions & 10 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (
// App props
const (
APP = "init-exporter"
VER = "0.8.0"
VER = "0.9.0"
DESC = "Utility for exporting services described by Procfile to init system"
)

// Supported arguments list
// Supported arguments
const (
ARG_PROCFILE = "p:procfile"
ARG_APP_NAME = "n:appname"
Expand All @@ -46,11 +46,13 @@ const (
ARG_VERSION = "v:version"
)

// Config properies list
// Config properies
const (
MAIN_RUN_USER = "main:run-user"
MAIN_RUN_GROUP = "main:run-group"
MAIN_PREFIX = "main:prefix"
PROCFILE_VERSION1 = "procfile:version1"
PROCFILE_VERSION2 = "procfile:version2"
PATHS_WORKING_DIR = "paths:working-dir"
PATHS_HELPER_DIR = "paths:helper-dir"
PATHS_SYSTEMD_DIR = "paths:systemd-dir"
Expand Down Expand Up @@ -150,12 +152,12 @@ func checkForRoot() {
user, err = system.CurrentUser()

if err != nil {
fmt.Println(err.Error())
printError(err.Error())
os.Exit(1)
}

if !user.IsRoot() {
fmt.Println("This utility must have superuser privileges (root)")
printError("This utility must have superuser privileges (root)")
os.Exit(1)
}
}
Expand Down Expand Up @@ -272,10 +274,10 @@ func validateConfig() {
errs := knf.Validate(validators)

if len(errs) != 0 {
fmt.Println("Errors while config validation:")
printError("Errors while config validation:")

for _, err := range errs {
fmt.Printf(" %v\n", err)
printError(" %v\n", err)
}

os.Exit(1)
Expand Down Expand Up @@ -326,6 +328,16 @@ func installApplication(appName string) {
printErrorAndExit(err.Error())
}

if app.ProcVersion == 1 && !knf.GetB(PROCFILE_VERSION1, true) {
printError("Proc format version 1 support is disabled")
os.Exit(1)
}

if app.ProcVersion == 2 && !knf.GetB(PROCFILE_VERSION2, true) {
printError("Proc format version 2 support is disabled")
os.Exit(1)
}

if arg.GetB(ARG_DRY_START) {
os.Exit(0)
}
Expand Down Expand Up @@ -412,10 +424,20 @@ func detectProvider(format string) (string, error) {
}
}

// printError prints error message to console
func printError(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...)
}

// printError prints warning message to console
func printWarn(f string, a ...interface{}) {
fmtc.Fprintf(os.Stderr, "{y}"+f+"{!}\n", a...)
}

// printErrorAndExit print error mesage and exit with exit code 1
func printErrorAndExit(message string, a ...interface{}) {
log.Crit(message)
fmt.Printf(message+"\n", a...)
func printErrorAndExit(f string, a ...interface{}) {
log.Crit(f, a...)
printError(f, a...)
os.Exit(1)
}

Expand Down
8 changes: 8 additions & 0 deletions common/init-exporter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
# Prefix used for exported units and helpers
prefix: fb-

[procfile]

# Enable/disable support of version 1 proc files
version1: false

# Enable/disable support of version 2 proc files
version2: true

[paths]

# Working dir
Expand Down
22 changes: 19 additions & 3 deletions common/init-exporter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

Summary: Utility for exporting services described by Procfile to init system
Name: init-exporter
Version: 0.8.0
Version: 0.9.0
Release: 0%{?dist}
Group: Development/Tools
License: MIT
Expand Down Expand Up @@ -70,8 +70,14 @@ Utility for exporting services described by Procfile to init system.
%setup -q

%build
export GOPATH=$(pwd)
export GOPATH=$(pwd)

pushd src/github.com/funbox/%{name}
%{__make} %{?_smp_mflags}
popd

go build -o %{name} src/github.com/funbox/%{name}/%{name}.go
go build -o %{name}-converter src/github.com/funbox/%{name}/%{name}-converter.go

%install
rm -rf %{buildroot}
Expand All @@ -82,7 +88,11 @@ install -dm 755 %{buildroot}%{_logdir}/%{name}
install -dm 755 %{buildroot}%{_loc_prefix}/%{name}
install -dm 755 %{buildroot}%{_localstatedir}/local/%{name}/helpers

install -pm 755 %{name} %{buildroot}%{_bindir}/
install -pm 755 src/github.com/funbox/%{name}/%{name} \
%{buildroot}%{_bindir}/

install -pm 755 src/github.com/funbox/%{name}/%{name}-converter \
%{buildroot}%{_bindir}/

ln -sf %{_bindir}/%{name} %{buildroot}%{_bindir}/upstart-export
ln -sf %{_bindir}/%{name} %{buildroot}%{_bindir}/systemd-export
Expand All @@ -101,12 +111,18 @@ rm -rf %{buildroot}
%dir %{_logdir}/%{name}
%dir %{_localstatedir}/local/%{name}/helpers
%{_bindir}/init-exporter
%{_bindir}/init-exporter-converter
%{_bindir}/upstart-export
%{_bindir}/systemd-export

###############################################################################

%changelog
* Fri Mar 31 2017 Anton Novojilov <[email protected]> - 0.9.0-0
- Format support configuration feature
- Pre and post commands support
- Added format converter

* Thu Mar 09 2017 Anton Novojilov <[email protected]> - 0.8.0-0
- ek package updated to v7

Expand Down
Loading

0 comments on commit 40a8ca6

Please sign in to comment.