From 777204d72f9d184e4416f943d8a1a38051dfb5ae Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Mon, 16 Oct 2017 18:31:15 +0200 Subject: Update default syncthing port to 8386 Signed-off-by: Sebastien Douheret --- lib/syncthing/st.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/syncthing/st.go b/lib/syncthing/st.go index 660738d..6199a8f 100644 --- a/lib/syncthing/st.go +++ b/lib/syncthing/st.go @@ -58,7 +58,7 @@ func NewSyncThing(conf *xdsconfig.Config, log *logrus.Logger) *SyncThing { } if url == "" { - url = "http://localhost:8384" + url = "http://localhost:8386" } if url[0:7] != "http://" { url = "http://" + url -- cgit 1.2.3-korg From fa1a0fa5e47260349d2da761b499223d11324b58 Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Tue, 17 Oct 2017 00:04:36 +0200 Subject: Add xds-agent user systemd service file and install Signed-off-by: Sebastien Douheret --- Makefile | 15 ++++++---- agent-config.json.in | 9 ------ conf.d/etc/default/xds-agent | 5 ++++ conf.d/etc/profile.d/xds-agent.sh | 4 +++ conf.d/etc/xds-agent/config.json | 9 ++++++ conf.d/usr/lib/systemd/user/xds-agent.service | 9 ++++++ lib/xdsconfig/fileconfig.go | 19 ++---------- scripts/get-syncthing.sh | 4 +-- scripts/install.sh | 42 +++++++++++++++++++++++++++ xds-agent.service | 9 ------ 10 files changed, 82 insertions(+), 43 deletions(-) delete mode 100644 agent-config.json.in create mode 100644 conf.d/etc/default/xds-agent create mode 100644 conf.d/etc/profile.d/xds-agent.sh create mode 100644 conf.d/etc/xds-agent/config.json create mode 100644 conf.d/usr/lib/systemd/user/xds-agent.service create mode 100755 scripts/install.sh delete mode 100644 xds-agent.service (limited to 'lib') diff --git a/Makefile b/Makefile index ae5a69c..eb70258 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,9 @@ endif # for backward compatibility DESTDIR := $(INSTALL_DIR) -# Configurable variables for installation (default /usr/local/...) +# Configurable variables for installation (default /opt/AGL/xds/agent) ifeq ($(origin DESTDIR), undefined) - DESTDIR := /usr/local/bin + DESTDIR := /opt/AGL/xds/agent endif HOST_GOOS=$(shell go env GOOS) @@ -82,9 +82,10 @@ build: tools/syncthing/copytobin @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-agent$(EXT) -ldflags "$(GORELEASE) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" -gcflags "$(GO_GCFLAGS)" . package: clean tools/syncthing vendor build - @mkdir -p $(PACKAGE_DIR)/xds-agent - @cp agent-config.json.in $(PACKAGE_DIR)/xds-agent/agent-config.json + @mkdir -p $(PACKAGE_DIR)/xds-agent $(PACKAGE_DIR)/scripts @cp -a $(LOCAL_BINDIR)/* $(PACKAGE_DIR)/xds-agent + cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-agent + cp -r $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/scripts cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-agent .PHONY: package-all @@ -121,8 +122,10 @@ distclean: clean rm -rf $(LOCAL_BINDIR) tools glide.lock vendor $(ROOT_SRCDIR)/*.zip .PHONY: install -install: all - mkdir -p $(DESTDIR) && cp $(LOCAL_BINDIR)/* $(DESTDIR) +install: + @test -e $(LOCAL_BINDIR)/xds-agent$(EXT) || { echo "Please execute first: make all\n"; exit 1; } + @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; } + export DESTDIR=$(DESTDIR) && $(ROOT_SRCDIR)/scripts/install.sh vendor: tools/glide glide.yaml $(LOCAL_TOOLSDIR)/glide install --strip-vendor diff --git a/agent-config.json.in b/agent-config.json.in deleted file mode 100644 index 35d702d..0000000 --- a/agent-config.json.in +++ /dev/null @@ -1,9 +0,0 @@ -{ - "logsDir": "${HOME}/.xds/agent/logs", - "xds-apikey": "1234abcezam", - "syncthing": { - "home": "${HOME}/.xds/agent/syncthing-config", - "gui-address": "http://localhost:8386", - "gui-apikey": "1234abcezam" - } -} diff --git a/conf.d/etc/default/xds-agent b/conf.d/etc/default/xds-agent new file mode 100644 index 0000000..93d56cb --- /dev/null +++ b/conf.d/etc/default/xds-agent @@ -0,0 +1,5 @@ +# defaults file for XDS Agent +# this file is used for service environment in /usr/lib/systemd/user/xds-agent.service + +# Logging level (supported levels: panic, fatal, error, warn, info, debug) +LOG_LEVEL=info diff --git a/conf.d/etc/profile.d/xds-agent.sh b/conf.d/etc/profile.d/xds-agent.sh new file mode 100644 index 0000000..78eff4f --- /dev/null +++ b/conf.d/etc/profile.d/xds-agent.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +#---------- AGL xds-agent tool options Start ---------" +[ ":${PATH}:" != *":%%XDS_INSTALL_BIN_DIR%%:"* ] && export PATH=%%XDS_INSTALL_BIN_DIR%%:${PATH} diff --git a/conf.d/etc/xds-agent/config.json b/conf.d/etc/xds-agent/config.json new file mode 100644 index 0000000..35d702d --- /dev/null +++ b/conf.d/etc/xds-agent/config.json @@ -0,0 +1,9 @@ +{ + "logsDir": "${HOME}/.xds/agent/logs", + "xds-apikey": "1234abcezam", + "syncthing": { + "home": "${HOME}/.xds/agent/syncthing-config", + "gui-address": "http://localhost:8386", + "gui-apikey": "1234abcezam" + } +} diff --git a/conf.d/usr/lib/systemd/user/xds-agent.service b/conf.d/usr/lib/systemd/user/xds-agent.service new file mode 100644 index 0000000..1fd038b --- /dev/null +++ b/conf.d/usr/lib/systemd/user/xds-agent.service @@ -0,0 +1,9 @@ +[Unit] +Description=XDS Agent + +[Service] +EnvironmentFile=-/etc/default/xds-agent +ExecStart=/opt/AGL/xds/agent/xds-agent & + +[Install] +WantedBy=multi-user.target diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go index efe94bf..d936bbe 100644 --- a/lib/xdsconfig/fileconfig.go +++ b/lib/xdsconfig/fileconfig.go @@ -5,7 +5,6 @@ import ( "os" "os/user" "path" - "path/filepath" common "github.com/iotbzh/xds-common/golib" ) @@ -28,8 +27,7 @@ type FileConfig struct { // Order to determine which config file is used: // 1/ from command line option: "--config myConfig.json" // 2/ $HOME/.xds/agent/agent-config.json file -// 3/ /agent-config.json file -// 4/ /agent-config.json file +// 3/ /etc/xds-agent/config.json file func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) { @@ -41,20 +39,7 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) { searchIn = append(searchIn, path.Join(usr.HomeDir, ".xds", "agent", "agent-config.json")) } - searchIn = append(searchIn, "/etc/xds-agent/agent-config.json") - - exePath := os.Args[0] - ee, _ := os.Executable() - exeAbsPath, err := filepath.Abs(ee) - if err == nil { - exePath, err = filepath.EvalSymlinks(exeAbsPath) - if err == nil { - exePath = filepath.Dir(ee) - } else { - exePath = filepath.Dir(exeAbsPath) - } - } - searchIn = append(searchIn, path.Join(exePath, "agent-config.json")) + searchIn = append(searchIn, "/etc/xds-agent/config.json") var cFile *string for _, p := range searchIn { diff --git a/scripts/get-syncthing.sh b/scripts/get-syncthing.sh index 3455122..772c09a 100755 --- a/scripts/get-syncthing.sh +++ b/scripts/get-syncthing.sh @@ -43,7 +43,7 @@ if [ "$?" != 0 ]; then exit 1 fi -gpg -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1 +${GPG} -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1 tarball="syncthing-${GOOS_ST}-${GOARCH}-v${SYNCTHING_VERSION}.${TB_EXT}" \ && curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/${tarball}" -O \ @@ -94,4 +94,4 @@ else fi fi -echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}" \ No newline at end of file +echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}" diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..6f93f2b --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Install XDS agent as a user systemd service + +DESTDIR=${DESTDIR:-/opt/AGL/xds/agent} + +ROOT_SRCDIR=$(cd $(dirname "$0")/.. && pwd) + +install() { + mkdir -p ${DESTDIR} && cp ${ROOT_SRCDIR}/bin/* ${DESTDIR} || exit 1 + + cp ${ROOT_SRCDIR}/conf.d/etc/xds-agent /etc/ || exit 1 + cp ${ROOT_SRCDIR}/conf.d/etc/default/xds-agent /etc/default/ || exit 1 + + FILE=/etc/profile.d/xds-agent.sh + sed -e "s;%%XDS_INSTALL_BIN_DIR%%;${DESTDIR};g" ${ROOT_SRCDIR}/conf.d/${FILE} > ${FILE} || exit 1 + + FILE=/usr/lib/systemd/user/xds-agent.service + sed -e "s;/opt/AGL/xds/agent;${DESTDIR};g" ${ROOT_SRCDIR}/conf.d/${FILE} > ${FILE} || exit 1 + + echo "" + echo "To enable xds-agent service, execute: systemctl --user enable xds-agent" + echo "and to start xds-agent service, execute: systemctl --user start xds-agent" +} + +uninstall() { + rm -rf "${DESTDIR}" + rm -f /etc/xds-agent /etc/profile.d/xds-agent.sh /usr/lib/systemd/user/xds-agent.service +} + +if [ "$1" == "uninstall" ]; then + echo -n "Are-you sure you want to remove ${DESTDIR} [y/n]? " + read answer + if [ "${answer}" = "y" ]; then + uninstall + echo "xds-agent sucessfully uninstalled." + else + echo "Uninstall canceled." + fi +else + install +fi diff --git a/xds-agent.service b/xds-agent.service deleted file mode 100644 index 66788dc..0000000 --- a/xds-agent.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=XDS Agent - -[Service] -User=claneys -ExecStart=/opt/AGL/xds/agent/xds-agent & - -[Install] -WantedBy=multi-user.target -- cgit 1.2.3-korg