Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,38 @@ const (
winExeName = "tacticalrmm.exe"
winSvcName = "tacticalrmm"
meshSvcName = "mesh agent"
etcConfig = "/etc/tacticalagent"
nixAgentDir = "/opt/tacticalagent"
nixMeshDir = "/opt/tacticalmesh"
nixAgentBin = nixAgentDir + "/tacticalagent"
nixAgentBinDir = nixAgentDir + "/bin"
nixAgentEtcDir = nixAgentDir + "/etc"
nixMeshAgentBin = nixMeshDir + "/meshagent"
macPlistPath = "/Library/LaunchDaemons/tacticalagent.plist"
macPlistName = "tacticalagent"
defaultMacMeshSvcDir = "/usr/local/mesh_services"
)

// Unix paths are prefixed with installPrefix so the agent can run on systems where /etc and /opt are read-only.
// I.e. NixOS, TrueNAS Scale, diskless images.
var (
installPrefix = ""
etcConfig = "/etc/tacticalagent"
nixAgentDir = "/opt/tacticalagent"
nixMeshDir = "/opt/tacticalmesh"
nixAgentBin = nixAgentDir + "/tacticalagent"
nixAgentBinDir = nixAgentDir + "/bin"
nixAgentEtcDir = nixAgentDir + "/etc"
nixMeshAgentBin = nixMeshDir + "/meshagent"
)

// SetInstallPrefix relocates the Unix agent/config/mesh trees under a single
// writable root. Must be called before Agent.New or any install/read path so
// the derived paths observe the prefix.
func SetInstallPrefix(prefix string) {
installPrefix = strings.TrimRight(prefix, "/")
etcConfig = installPrefix + "/etc/tacticalagent"
nixAgentDir = installPrefix + "/opt/tacticalagent"
nixMeshDir = installPrefix + "/opt/tacticalmesh"
nixAgentBin = nixAgentDir + "/tacticalagent"
nixAgentBinDir = nixAgentDir + "/bin"
nixAgentEtcDir = nixAgentDir + "/etc"
nixMeshAgentBin = nixMeshDir + "/meshagent"
}

var defaultWinTmpDir = filepath.Join(os.Getenv("PROGRAMDATA"), "TacticalRMM")
var winMeshDir = filepath.Join(os.Getenv("PROGRAMFILES"), "Mesh Agent")
var natsCheckin = []string{"agent-hello", "agent-agentinfo", "agent-disks", "agent-winsvc", "agent-publicip", "agent-wmi"}
Expand Down
1 change: 1 addition & 0 deletions agent/agent_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (a *Agent) osString() string {
func NewAgentConfig() *rmm.AgentConfig {
viper.SetConfigName("tacticalagent")
viper.SetConfigType("json")
viper.AddConfigPath(filepath.Dir(etcConfig))
viper.AddConfigPath("/etc/")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ func main() {
proxy := flag.String("proxy", "", "Use a http proxy")
insecure := flag.Bool("insecure", false, "Insecure for testing only")
natsport := flag.String("natsport", "", "nats standard port")
installPrefix := flag.String("install-prefix", os.Getenv("INSTALL_PREFIX"), "Unix install path prefix. Defaults to $INSTALL_PREFIX")
flag.Parse()

if *installPrefix != "" {
agent.SetInstallPrefix(*installPrefix)
}

if *ver {
agent.ShowVersionInfo(version)
return
Expand Down
Loading