mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
core: Chdir to executable location on Windows (#5115)
Since all Windows services are run from the Windows system directory, make it easier for users by switching to our program directory right after the start.
This commit is contained in:
parent
c28cd29fe7
commit
253d97c93d
1 changed files with 11 additions and 0 deletions
|
@ -15,6 +15,9 @@
|
||||||
package caddy
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2/notify"
|
"github.com/caddyserver/caddy/v2/notify"
|
||||||
"golang.org/x/sys/windows/svc"
|
"golang.org/x/sys/windows/svc"
|
||||||
)
|
)
|
||||||
|
@ -24,6 +27,14 @@ func init() {
|
||||||
if err != nil || !isService {
|
if err != nil || !isService {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Windows services always start in the system32 directory, try to
|
||||||
|
// switch into the directory where the caddy executable is.
|
||||||
|
execPath, err := os.Executable()
|
||||||
|
if err == nil {
|
||||||
|
_ = os.Chdir(filepath.Dir(execPath))
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
_ = svc.Run("", runner{})
|
_ = svc.Run("", runner{})
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue