-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
84 lines (68 loc) · 2.8 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright 2017 github.com/ucirello
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
Command runner is a very ugly and simple structured command executer that
monitor file changes to trigger process restarts.
Create a file name Procfile in the root of the project you want to run, and add
the following content:
workdir: $GOPATH/src/github.com/example/go-app
observe: *.go *.js
ignore: /vendor
build-server: make server
web-a: group=web restart=always waitfor=localhost:8888 ./server serve alpha
web-b: group=web restart=always waitfor=localhost:8888 ./server serve bravo
db: restart=failure waitfor=localhost:8888 ./server db
Special process types:
- workdir: the working directory. Environment variables are expanded. It follows
the same rules for exec.Command.Dir.
- observe: a space separated list of file patterns to scan for. It uses
filepath.Match internally. File patterns preceded with exclamation mark (!) will
not trigger builds.
- ignore: a space separated list of ignored directories relative to workdir,
typically vendor directories.
- build*: process type name prefixed by "build" are always executed first and in
order of declaration. On failure, they halt the initialization.
- waitfor (in process type): target hostname and port that the runner will probe
before starting the process type.
- restart (in process type): "always" will restart the process type at every
build; "fail" will restart the process type on failure; "temporary" will start
the service once and not restart it on rebuilds; "loop" will restart the process
when it naturally terminates.
- group (in process type): group of processes that depend on each other. If a
process type fails, it will halt all others in the same group. If the
"restart" parameter is not set to "always" or "fail", the affected process
types will halt and not restart.
- sticky (in build process types): a sticky build is not interrupted when file
changes are detected.
- optional (in process types): does not start this process unless explicit told
so. The process type must be part of a group.
*/
package main // import "cirello.io/runner"
import (
"log"
"os"
"path/filepath"
)
func main() {
log.SetFlags(0)
facet := filepath.Base(os.Args[0])
switch facet {
case "waitfor":
log.SetPrefix("waitfor: ")
waitfor()
default:
log.SetPrefix("runner: ")
run()
}
}