-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (51 loc) · 1.33 KB
/
Copy pathmain.go
File metadata and controls
58 lines (51 loc) · 1.33 KB
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
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
winswExampleConfig := `
<service>
<id>{{issue}}</id>
<name>{{issue}}</name>
<description>{{issue}}</description>
<executable>{{executable}}</executable>
<workingdirectory>{{workingdirectory}}</workingdirectory>
<stoptimeout>30 sec</stoptimeout>
<delayedAutoStart>true</delayedAutoStart>
<onfailure action="restart" delay="5000" />
<arguments>"0 0 0 * * *"</arguments>
</service>
`
winswConfigPath := "../winsw.xml"
var issue string
{
abs, err := filepath.Abs("../")
if err != nil {
panic(err)
}
issue = filepath.Base(abs)
}
execPath := fmt.Sprintf("../%s.exe", issue)
execAbsPath, err := filepath.Abs(execPath)
if err != nil {
panic(err)
}
_ = os.Remove(execPath)
output, err := exec.Command("go", "build", "-o", execPath, "../").CombinedOutput()
if err != nil {
fmt.Printf("output: `%s`\n", string(output))
panic(err)
}
winswConfig := winswExampleConfig
winswConfig = strings.ReplaceAll(winswConfig, "{{issue}}", issue)
winswConfig = strings.ReplaceAll(winswConfig, "{{executable}}", execAbsPath)
winswConfig = strings.ReplaceAll(winswConfig, "{{workingdirectory}}", filepath.Dir(execAbsPath))
err = os.WriteFile(winswConfigPath, []byte(winswConfig), os.ModePerm)
if err != nil {
panic(err)
}
}