@@ -31,7 +31,6 @@ import (
3131 "context"
3232 "errors"
3333 "fmt"
34- "html/template"
3534 "os"
3635 "os/exec"
3736 "os/signal"
@@ -51,12 +50,6 @@ import (
5150 "golang.org/x/sys/unix"
5251)
5352
54- type serviceOptions struct {
55- ConfigFile string
56- MountPath string
57- ServiceUser string
58- }
59-
6053func createDaemon (
6154 pipeline * internal.Pipeline ,
6255 ctx context.Context ,
@@ -211,28 +204,19 @@ Requires=network-online.target
211204
212205[Service]
213206# User service will run as.
214- User={{.ServiceUser}}
207+ User=%s
215208
216209# Under the hood
217210Type=forking
218- ExecStart=/usr/bin/cloudfuse mount {{.MountPath}} --config-file={{.ConfigFile}} -o allow_other
219- ExecStop=/usr/bin/fusermount -u {{.MountPath}} -z
211+ ExecStart=/usr/bin/cloudfuse mount %s --config-file=%s -o allow_other
212+ ExecStop=/usr/bin/fusermount -u %s -z
220213
221214[Install]
222215WantedBy=multi-user.target
223216`
224- config := serviceOptions {
225- ConfigFile : configPath ,
226- MountPath : mountPath ,
227- ServiceUser : serviceUser ,
228- }
229-
230- tmpl , err := template .New ("service" ).Parse (serviceTemplate )
231- if err != nil {
232- return "" , fmt .Errorf ("could not create a new service file: [%s]" , err .Error ())
233- }
217+ serviceContent := fmt .Sprintf (serviceTemplate , serviceUser , mountPath , configPath , mountPath )
234218 serviceName , serviceFilePath := getService (mountPath )
235- err = os .Remove (serviceFilePath )
219+ err : = os .Remove (serviceFilePath )
236220 if err != nil && ! os .IsNotExist (err ) {
237221 return "" , fmt .Errorf ("failed to replace the service file [%s]" , err .Error ())
238222 }
@@ -243,7 +227,7 @@ WantedBy=multi-user.target
243227 return "" , fmt .Errorf ("could not create new service file: [%s]" , err .Error ())
244228 }
245229
246- err = tmpl . Execute ( newFile , config )
230+ _ , err = newFile . WriteString ( serviceContent )
247231 if err != nil {
248232 return "" , fmt .Errorf ("could not create new service file: [%s]" , err .Error ())
249233 }
0 commit comments