@@ -4,6 +4,7 @@ package main
44
55import (
66 "fmt"
7+ "io"
78 "os"
89
910 "github.com/rs/zerolog"
@@ -15,7 +16,7 @@ import (
1516 "github.com/cloudflare/cloudflared/logger"
1617)
1718
18- func runApp (app * cli.App , graceShutdownC chan struct {}) {
19+ func runApp (app * cli.App , _ chan struct {}) {
1920 app .Commands = append (app .Commands , & cli.Command {
2021 Name : "service" ,
2122 Usage : "Manages the cloudflared system service" ,
@@ -35,7 +36,7 @@ func runApp(app *cli.App, graceShutdownC chan struct{}) {
3536 },
3637 },
3738 })
38- app .Run (os .Args )
39+ _ = app .Run (os .Args )
3940}
4041
4142// The directory and files that are used by the service.
@@ -97,6 +98,7 @@ WantedBy=timers.target
9798var sysvTemplate = ServiceTemplate {
9899 Path : "/etc/init.d/cloudflared" ,
99100 FileMode : 0755 ,
101+ // nolint: dupword
100102 Content : `#!/bin/sh
101103# For RedHat and cousins:
102104# chkconfig: 2345 99 01
@@ -184,13 +186,11 @@ exit 0
184186` ,
185187}
186188
187- var (
188- noUpdateServiceFlag = & cli.BoolFlag {
189- Name : "no-update-service" ,
190- Usage : "Disable auto-update of the cloudflared linux service, which restarts the server to upgrade for new versions." ,
191- Value : false ,
192- }
193- )
189+ var noUpdateServiceFlag = & cli.BoolFlag {
190+ Name : "no-update-service" ,
191+ Usage : "Disable auto-update of the cloudflared linux service, which restarts the server to upgrade for new versions." ,
192+ Value : false ,
193+ }
194194
195195func isSystemd () bool {
196196 if _ , err := os .Stat ("/run/systemd/system" ); err == nil {
@@ -430,3 +430,38 @@ func uninstallSysv(log *zerolog.Logger) error {
430430 }
431431 return nil
432432}
433+
434+ func ensureConfigDirExists (configDir string ) error {
435+ ok , err := config .FileExists (configDir )
436+ if ! ok && err == nil {
437+ err = os .Mkdir (configDir , 0755 )
438+ }
439+ return err
440+ }
441+
442+ func copyFile (src , dest string ) error {
443+ srcFile , err := os .Open (src )
444+ if err != nil {
445+ return err
446+ }
447+ defer srcFile .Close ()
448+
449+ destFile , err := os .Create (dest )
450+ if err != nil {
451+ return err
452+ }
453+ ok := false
454+ defer func () {
455+ destFile .Close ()
456+ if ! ok {
457+ _ = os .Remove (dest )
458+ }
459+ }()
460+
461+ if _ , err := io .Copy (destFile , srcFile ); err != nil {
462+ return err
463+ }
464+
465+ ok = true
466+ return nil
467+ }
0 commit comments