Skip to content

Commit 1cd356a

Browse files
Add commands on Windows to remount as either user or system (#490)
* Add enable remount with system or user on Windows * Add unmount command * First pass on using windows service for system startup * Fix build * Fix issues with service starting correctly. * Fix error messages * Finish windows service start tool * Final changes * Cleanup documentation and simplify some logic
1 parent efe8ad4 commit 1cd356a

File tree

16 files changed

+398
-89
lines changed

16 files changed

+398
-89
lines changed

.goreleaser.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ builds:
4141
ldflags:
4242
- -s -w -X github.com/Seagate/cloudfuse/common.GitCommit={{.Commit}} -X github.com/Seagate/cloudfuse/common.CommitDate={{ .CommitDate }}
4343

44+
- id: windows-service
45+
main: ./tools/windows-service/main.go
46+
binary: windows-service
47+
goos:
48+
- windows
49+
goarch:
50+
- amd64
51+
env:
52+
- CGO_ENABLED=0
53+
flags:
54+
- -trimpath
55+
- -buildmode=pie
56+
mod_timestamp: "{{ .CommitTimestamp }}"
57+
ldflags:
58+
- -s -w -X github.com/Seagate/cloudfuse/common.GitCommit={{.Commit}} -X github.com/Seagate/cloudfuse/common.CommitDate={{ .CommitDate }}
59+
4460
- id: windows-health-monitor
4561
main: ./tools/health-monitor/main.go
4662
binary: cfusemon
@@ -181,6 +197,7 @@ archives:
181197
- windows
182198
- windows-startup
183199
- windows-health-monitor
200+
- windows-service
184201
formats: ["zip"]
185202
files:
186203
- LICENSE
@@ -196,7 +213,9 @@ archives:
196213
- id: windows_no_gui
197214
ids:
198215
- windows
216+
- windows-startup
199217
- windows-health-monitor
218+
- windows-service
200219
formats: ["zip"]
201220
name_template: "{{ .ProjectName }}_no_gui_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
202221
files:

build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ else
2121
rm -rf windows-startup
2222
go build -o windows-startup.exe ./tools/windows-startup/
2323

24+
# Build Windows Service Tool
25+
rm -rf windows-service
26+
go build -o windows-service.exe ./tools/windows-service/
27+
2428
# Build cloudfuse
2529
rm -rf cloudfuse.exe
2630
go build -o cloudfuse.exe

build/windows_installer_build.iss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Source: "..\gui\dist\cloudfuseGUI_Windows\_internal\*"; DestDir: "{app}\_interna
5151
Source: "..\cloudfuse.exe"; DestDir: "{app}"; Flags: ignoreversion
5252
Source: "..\cfusemon.exe"; DestDir: "{app}"; Flags: ignoreversion
5353
Source: "..\windows-startup.exe"; DestDir: "{app}"; Flags: ignoreversion
54+
Source: "..\windows-service.exe"; DestDir: "{app}"; Flags: ignoreversion
5455
Source: "..\NOTICE"; DestDir: "{app}"; Flags: ignoreversion
5556
Source: "..\LICENSE"; DestDir: "{app}"; Flags: ignoreversion
5657
Source: "..\README.md"; DestDir: "{app}"; Flags: ignoreversion
@@ -128,7 +129,7 @@ var
128129
begin
129130
if CurUninstallStep = usUninstall then
130131
begin
131-
// Install the Cloudfuse Startup Tool
132+
// Uninstall the Cloudfuse Startup Tool
132133
if not Exec(ExpandConstant('{app}\{#MyAppExeCLIName}'), 'service uninstall', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
133134
begin
134135
SuppressibleMsgBox('Failed to remove cloudfuse as a service.', mbError, MB_OK, IDOK);

build/windows_installer_build_no_gui.iss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Name: "{userappdata}\{#MyAppName}"; Flags: uninsalwaysuninstall
4545
Source: "..\cloudfuse.exe"; DestDir: "{app}"; Flags: ignoreversion
4646
Source: "..\cfusemon.exe"; DestDir: "{app}"; Flags: ignoreversion
4747
Source: "..\windows-startup.exe"; DestDir: "{app}"; Flags: ignoreversion
48+
Source: "..\windows-service.exe"; DestDir: "{app}"; Flags: ignoreversion
4849
Source: "..\NOTICE"; DestDir: "{app}"; Flags: ignoreversion
4950
Source: "..\LICENSE"; DestDir: "{app}"; Flags: ignoreversion
5051
Source: "..\README.md"; DestDir: "{app}"; Flags: ignoreversion
@@ -115,7 +116,7 @@ var
115116
begin
116117
if CurUninstallStep = usUninstall then
117118
begin
118-
// Install the Cloudfuse Startup Tool
119+
// Uninstall the Cloudfuse Startup Tool
119120
if not Exec(ExpandConstant('{app}\{#MyAppExeCLIName}'), 'service uninstall', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
120121
begin
121122
SuppressibleMsgBox('Failed to remove cloudfuse as a service.', mbError, MB_OK, IDOK);

cmd/mount.go

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,24 @@ type mountOptions struct {
6666
MountPath string
6767
ConfigFile string
6868

69-
DryRun bool
70-
Logging LogOptions `config:"logging"`
71-
Components []string `config:"components"`
72-
Foreground bool `config:"foreground"`
73-
NonEmpty bool `config:"nonempty"`
74-
DefaultWorkingDir string `config:"default-working-dir"`
75-
CPUProfile string `config:"cpu-profile"`
76-
MemProfile string `config:"mem-profile"`
77-
PassPhrase string `config:"passphrase"`
78-
SecureConfig bool `config:"secure-config"`
79-
DynamicProfiler bool `config:"dynamic-profile"`
80-
ProfilerPort int `config:"profiler-port"`
81-
ProfilerIP string `config:"profiler-ip"`
82-
MonitorOpt monitorOptions `config:"health_monitor"`
83-
WaitForMount time.Duration `config:"wait-for-mount"`
84-
LazyWrite bool `config:"lazy-write"`
85-
EnableRemount bool
69+
DryRun bool
70+
Logging LogOptions `config:"logging"`
71+
Components []string `config:"components"`
72+
Foreground bool `config:"foreground"`
73+
NonEmpty bool `config:"nonempty"`
74+
DefaultWorkingDir string `config:"default-working-dir"`
75+
CPUProfile string `config:"cpu-profile"`
76+
MemProfile string `config:"mem-profile"`
77+
PassPhrase string `config:"passphrase"`
78+
SecureConfig bool `config:"secure-config"`
79+
DynamicProfiler bool `config:"dynamic-profile"`
80+
ProfilerPort int `config:"profiler-port"`
81+
ProfilerIP string `config:"profiler-ip"`
82+
MonitorOpt monitorOptions `config:"health_monitor"`
83+
WaitForMount time.Duration `config:"wait-for-mount"`
84+
LazyWrite bool `config:"lazy-write"`
85+
EnableRemountUser bool
86+
EnableRemountSystem bool
8687

8788
// v1 support
8889
Streaming bool `config:"streaming"`
@@ -273,7 +274,6 @@ var mountCmd = &cobra.Command{
273274
FlagErrorHandling: cobra.ExitOnError,
274275
RunE: func(_ *cobra.Command, args []string) error {
275276
options.MountPath = common.ExpandPath(args[0])
276-
configFileProvided := options.ConfigFile != ""
277277
common.MountPath = options.MountPath
278278

279279
if options.ConfigFile == "" {
@@ -321,7 +321,7 @@ var mountCmd = &cobra.Command{
321321
return errors.New("config file does not exist")
322322
}
323323
// mount using WinFSP, and persist on reboot
324-
err = createMountInstance(options.EnableRemount)
324+
err = createMountInstance(options.EnableRemountUser, options.EnableRemountSystem)
325325
if err != nil {
326326
return fmt.Errorf("failed to mount instance [%s]", err.Error())
327327
}
@@ -492,14 +492,8 @@ var mountCmd = &cobra.Command{
492492
return Destroy(fmt.Sprintf("failed to initialize new pipeline :: To authenticate using MSI with object-ID, ensure Azure CLI is installed. Alternatively, use app/client ID or resource ID for authentication. [%s]", err.Error()))
493493
}
494494

495-
errorMessage := ""
496-
if !configFileProvided {
497-
errorMessage += "config file not provided."
498-
} else {
499-
errorMessage += "Config file " + options.ConfigFile + " not found."
500-
}
501-
log.Err("mount : "+errorMessage+" failed to initialize new pipeline [%v]", err)
502-
return Destroy(fmt.Sprintf("%s failed to initialize new pipeline [%s]", errorMessage, err.Error()))
495+
log.Err("mount : failed to initialize new pipeline [%v]", err)
496+
return Destroy(fmt.Sprintf("mount : failed to initialize new pipeline [%s]", err.Error()))
503497
}
504498

505499
// Dry run ends here
@@ -745,8 +739,11 @@ func init() {
745739
mountCmd.Flags().Lookup("basic-remount-check").Hidden = true
746740

747741
if runtime.GOOS == "windows" {
748-
mountCmd.Flags().BoolVar(&options.EnableRemount, "enable-remount", true, "Remount mount on server restart.")
749-
config.BindPFlag("enable-remount", mountCmd.Flags().Lookup("enable-remount"))
742+
mountCmd.Flags().BoolVar(&options.EnableRemountSystem, "enable-remount-system", false, "Remount container on server restart. Mount will restart on reboot.")
743+
config.BindPFlag("enable-remount-system", mountCmd.Flags().Lookup("enable-remount-system"))
744+
745+
mountCmd.Flags().BoolVar(&options.EnableRemountUser, "enable-remount-user", false, "Remount container on server restart for current user. Mount will restart on current user log in.")
746+
config.BindPFlag("enable-remount-user", mountCmd.Flags().Lookup("enable-remount-user"))
750747
}
751748

752749
mountCmd.PersistentFlags().StringSliceVarP(&options.LibfuseOptions, "o", "o", []string{}, "FUSE options.")

cmd/mount_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,6 @@ func sigusrHandler(pipeline *internal.Pipeline, ctx context.Context) daemon.Sign
131131
}
132132

133133
// stub for compilation
134-
func createMountInstance(bool) error {
134+
func createMountInstance(bool, bool) error {
135135
return nil
136136
}

cmd/mount_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ func createDaemon(pipeline *internal.Pipeline, ctx context.Context, pidFileName
4242
}
4343

4444
// Use WinFSP to mount and if successful, add instance to persistent mount list
45-
func createMountInstance(enableRemount bool) error {
45+
func createMountInstance(enableRemountUser bool, enableRemountSystem bool) error {
4646
err := winservice.StartMount(options.MountPath, options.ConfigFile, encryptedPassphrase)
4747
if err != nil {
4848
return err
4949
}
5050
// Add the mount to the JSON file so it persists on restart.
51-
if enableRemount {
52-
err = winservice.AddMountJSON(options.MountPath, options.ConfigFile)
51+
if enableRemountUser || enableRemountSystem {
52+
err = winservice.AddMountJSON(options.MountPath, options.ConfigFile, enableRemountSystem)
5353
if err != nil {
5454
return fmt.Errorf("failed to add entry to json file [%s]", err.Error())
5555
}

0 commit comments

Comments
 (0)