forked from takama/daemon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaemon_windows.go
87 lines (71 loc) · 2.05 KB
/
daemon_windows.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
85
86
87
// Copyright 2015 Igor Dolzhikov. All rights reserved.
// Use of this source code is governed by
// license that can be found in the LICENSE file.
// Package daemon windows version
package daemon
import (
"errors"
"fmt"
"os"
"path/filepath"
)
//TODO: on windws, color code is not working.
// windowsRecord - standard record (struct) for windows version of daemon package
type windowsRecord struct {
name string
description string
}
func newDaemon(name, description string) (Daemon, error) {
return &windowsRecord{name, description}, nil
}
// Install the service
func (windows *windowsRecord) Install() (string, error) {
installAction := "Install " + windows.description + ":"
return installAction + failed, errors.New("windows daemon is not supported")
}
// Remove the service
func (windows *windowsRecord) Remove() (string, error) {
removeAction := "Removing " + windows.description + ":"
return removeAction + failed, errors.New("windows daemon is not supported")
}
// Start the service
func (windows *windowsRecord) Start() (string, error) {
startAction := "Starting " + windows.description + ":"
return startAction + failed, errors.New("windows daemon is not supported")
}
// Stop the service
func (windows *windowsRecord) Stop() (string, error) {
stopAction := "Stopping " + windows.description + ":"
return stopAction + failed, errors.New("windows daemon is not supported")
}
// Status - Get service status
func (windows *windowsRecord) Status() (string, error) {
return "Status could not defined", errors.New("windows daemon is not supported")
}
// Get executable path
func execPath() (string, error) {
prog := os.Args[0]
p, err := filepath.Abs(prog)
if err != nil {
return "", err
}
fi, err := os.Stat(p)
if err == nil {
if !fi.Mode().IsDir() {
return p, nil
}
err = fmt.Errorf("%s is directory", p)
}
if filepath.Ext(p) == "" {
p += ".exe"
fi, err := os.Stat(p)
if err == nil {
if !fi.Mode().IsDir() {
return p, nil
}
err = fmt.Errorf("%s is directory", p)
}
}
return "", err
// return filepath.Abs(os.Args[0])
}