DESTDIR_WWW := $(INSTALL_WEBAPP_DIR)
endif
-# Configurable variables for installation (default /usr/local/...)
+# Configurable variables for installation (default /opt/AGL/...)
ifeq ($(origin DESTDIR), undefined)
- DESTDIR := /usr/local/bin
+ DESTDIR := /opt/AGL/xds/server
endif
ifeq ($(origin DESTDIR_WWW), undefined)
DESTDIR_WWW := $(DESTDIR)/www
cat config.json.in \
| sed -e s,"webapp/dist","$(DESTDIR_WWW)",g \
| sed -e s,"\./bin","",g \
- > $(DESTDIR)/config.json
+ > $(DESTDIR)/config.json.in
.PHONY: install
install:
mkdir -p $(DESTDIR_WWW) \
&& cp -a webapp/dist/* $(DESTDIR_WWW)
-.PHONY: package
-package: clean
+.PHONY: _package
+_package: clean
make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www
cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-server
rm -f $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE)
(cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
-.PHONY: package-all
-package-all:
+# On support Linux for now
+.PHONY: package
+package:
@echo "# Build linux amd64..."
- GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
+ GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile _package
make -f $(ROOT_SRCDIR)/Makefile clean
+.PHONY: package-all
+package-all: package
+
vendor: tools/glide glide.yaml
$(LOCAL_TOOLSDIR)/glide install --strip-vendor
/lib/systemd/system/xds-server.service
```
-This Systemd service starts a bash script `/usr/local/bin/xds-server-start.sh`
+This Systemd service starts a bash script `/opt/AGL/xds/server/xds-server-start.sh`
If you needed you can change default setting by defining specific environment
variables in `/etc/default/xds-server`.
-For example to control log level, just set LOGLEVEL env variable knowing that
+For example to control log level, just set LOG_LEVEL env variable knowing that
supported *level* are: panic, fatal, error, warn, info, debug.
```bash
seb@laptop ~$ ssh -p 2222 devel@localhost
-devel@docker ~$ echo 'LOGLEVEL=debug' | sudo tee --append /etc/default/xds-server > /dev/null
+devel@docker ~$ echo 'LOG_LEVEL=debug' | sudo tee --append /etc/default/xds-server > /dev/null
devel@docker ~$ sudo systemctl restart xds-server.service
devel@docker ~$ tail -f /tmp/xds-server/logs/xds-server.log
```
seb@laptop ~$ ssh -p 2222 devel@localhost
# Install ARM64 SDK (automatic download)
-devel@docker ~$ sudo /usr/local/bin/xds-utils/install-agl-sdks.sh --arch aarch64
+devel@docker ~$ sudo /opt/AGL/xds/server/xds-utils/install-agl-sdks.sh --arch aarch64
# Install Intel corei7-64 SDK (using an SDK tarball that has been built or downloaded manually)
-devel@docker ~$ sudo /usr/local/bin/xds-utils/install-agl-sdks.sh --arch corei7-64 --file /tmp/poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-
+devel@docker ~$ sudo /opt/AGL/xds/server/xds-utils/install-agl-sdks.sh --arch corei7-64 --file /tmp/poky-agl-glibc-x86_64-agl-demo-platform-crosssdk-corei7-64-toolchain-
3.99.1+snapshot.sh
```
make all
```
-And to install `xds-server` (by default in `/usr/local/bin`):
+And to install `xds-server` (by default in `/opt/AGL/xds/server`):
```bash
make install
Here is the logic to determine which `config.json` file will be used:
1. from command line option: `--config myConfig.json`
-1. `$HOME/.xds/config.json` file
-1. `<current dir>/config.json` file
+1. `$HOME/.xds-server/config.json` file
+1. `/etc/xds-server/config.json` file
1. `<xds-server executable dir>/config.json` file
Supported fields in configuration file are (all fields are optional and example
{
"httpPort": 8000,
"webAppDir": "webapp/dist",
- "shareRootDir": "${HOME}/.xds/projects",
+ "shareRootDir": "${HOME}/.xds-server/projects",
"logsDir": "/tmp/logs",
"sdkRootDir": "/xdt/sdk",
"syncthing": {
"binDir": "./bin",
- "home": "${HOME}/.xds/syncthing-config",
+ "home": "${HOME}/.xds-server/syncthing-config",
"gui-address": "http://localhost:8384",
"gui-apikey": "123456789",
}
# this file is used for service environment in /lib/systemd/system/xds-server.service
# JSON config file to use
-#APP_CONFIG=/home/devel/.config/xds/server/config.json
+APP_CONFIG=/home/devel/.config/xds/server/config.json
# Logging level (supported levels: panic, fatal, error, warn, info, debug)
-#LOG_LEVEL=info
+LOG_LEVEL=info
# Filename where logs will be redirected (default stdout)
-#LOG_FILENAME=/tmp/xds/logs/xds-server.logs
+LOG_FILENAME=/tmp/xds-server/logs/xds-server.log
{
"webAppDir": "www",
"httpPort": "8000",
- "shareRootDir": "${HOME}/.xds/share",
- "logsDir": "/tmp/xds-server/logs",
+ "shareRootDir": "${HOME}/.xds-server/projects",
"sdkRootDir": "/xdt/sdk",
"syncthing": {
"binDir": "",
- "home": "${HOME}/.xds/syncthing-config",
+ "home": "${HOME}/.xds-server/syncthing-config",
"gui-address": "http://localhost:8384"
}
}
User=devel
Type=forking
EnvironmentFile=-/etc/default/xds-server
-ExecStart=/opt/AGL/xds/xds-server-start.sh
+ExecStart=/opt/AGL/xds/server/xds-server-start.sh
+ExecStop=/opt/AGL/xds/server/xds-server-stop.sh
[Install]
WantedBy=multi-user.target
{
- "webAppDir": "webapp/dist",
+ "webAppDir": "www",
"httpPort": "8000",
- "shareRootDir": "${HOME}/.xds/share",
+ "shareRootDir": "${HOME}/.xds-server/projects",
"logsDir": "/tmp/xds-server/logs",
"sdkRootDir": "/xdt/sdk",
"syncthing": {
"binDir": "./bin",
- "home": "${HOME}/.xds/syncthing-config",
+ "home": "${HOME}/.xds-server/syncthing-config",
"gui-address": "http://localhost:8384"
}
}
if binDir == "" {
if binDir, err = filepath.Abs(filepath.Dir(os.Args[0])); err != nil {
- binDir = "/usr/local/bin"
+ binDir = "/opt/AGL/bin"
}
}
// Serve in the background
serveError := make(chan error, 1)
go func() {
- fmt.Printf("Web Server running on localhost:%s ...\n", s.cfg.FileConf.HTTPPort)
+ msg := fmt.Sprintf("Web Server running on localhost:%s ...\n", s.cfg.FileConf.HTTPPort)
+ s.log.Infof(msg)
+ fmt.Printf(msg)
serveError <- http.ListenAndServe(":"+s.cfg.FileConf.HTTPPort, s.router)
}()
"fmt"
"io"
"os"
+ "path/filepath"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
ShareRootDir: DefaultShareDir,
SdkRootDir: DefaultSdkRootDir,
HTTPPort: DefaultPort,
+ LogsDir: "",
},
Log: log,
}
}
c.Log.Infoln("Share root directory: ", c.FileConf.ShareRootDir)
+ // Where Logs are redirected:
+ // default 'stdout' (logfile option default value)
+ // else use file (or filepath) set by --logfile option
+ // that may be overwritten by LogsDir field of config file
+ logF := c.Options.LogFile
+ logD := c.FileConf.LogsDir
+ if logF != "stdout" {
+ if logD != "" {
+ lf := filepath.Base(logF)
+ if lf == "" || lf == "." {
+ lf = "xds-server.log"
+ }
+ logF = filepath.Join(logD, lf)
+ } else {
+ logD = filepath.Dir(logF)
+ }
+ }
+ if logD == "" || logD == "." {
+ logD = "/tmp/xds/logs"
+ }
+ c.Options.LogFile = logF
+ c.FileConf.LogsDir = logD
+
if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) {
if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
return nil, fmt.Errorf("Cannot create logs dir: %v", err)
}
}
+ c.Log.Infoln("Logs file: ", c.Options.LogFile)
c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)
return &c, nil
const (
// ConfigDir Directory in user HOME directory where xds config will be saved
- ConfigDir = ".xds"
+ ConfigDir = ".xds-server"
// GlobalConfigFilename Global config filename
GlobalConfigFilename = "config.json"
// FoldersConfigFilename Folders config filename
// readGlobalConfig reads configuration from a config file.
// Order to determine which config file is used:
// 1/ from command line option: "--config myConfig.json"
-// 2/ $HOME/.xds/config.json file
-// 3/ <current_dir>/config.json file
+// 2/ $HOME/.xds-server/config.json file
+// 3/ /etc/xds-server/config.json file
// 4/ <xds-server executable dir>/config.json file
func readGlobalConfig(c *Config, confFile string) error {
searchIn = append(searchIn, path.Join(usr.HomeDir, ConfigDir,
GlobalConfigFilename))
}
- cwd, err := os.Getwd()
- if err == nil {
- searchIn = append(searchIn, path.Join(cwd, "config.json"))
- }
- exePath, err := filepath.Abs(filepath.Dir(os.Args[0]))
+
+ searchIn = append(searchIn, "/etc/xds-server/config.json")
+
+ exePath := os.Args[0]
+ exeAbsPath, err := filepath.Abs(os.Args[0])
if err == nil {
- searchIn = append(searchIn, path.Join(exePath, "config.json"))
+ exePath, err = filepath.EvalSymlinks(exeAbsPath)
+ if err == nil {
+ exePath = filepath.Dir(exePath)
+ } else {
+ exePath = filepath.Dir(exeAbsPath)
+ }
}
+ searchIn = append(searchIn, path.Join(exePath, "config.json"))
var cFile *string
for _, p := range searchIn {
// No config file found
return nil
}
-
c.Log.Infof("Use config file: %s", *cFile)
// TODO move on viper package to support comments in JSON and also
if fCfg.HTTPPort == "" {
fCfg.HTTPPort = c.FileConf.HTTPPort
}
+ if fCfg.LogsDir == "" {
+ fCfg.LogsDir = c.FileConf.LogsDir
+ }
// Resolve webapp dir (support relative or full path)
fCfg.WebAppDir = strings.Trim(fCfg.WebAppDir, " ")
if !strings.HasPrefix(fCfg.WebAppDir, "/") && exePath != "" {
+ cwd, _ := os.Getwd()
+
// Check first from current directory
- for _, rootD := range []string{cwd, exePath} {
+ for _, rootD := range []string{exePath, cwd} {
ff := path.Join(rootD, fCfg.WebAppDir, "index.html")
if common.Exists(ff) {
fCfg.WebAppDir = path.Join(rootD, fCfg.WebAppDir)
os.Exit(0)
}
+// Helper function to log message on both stdout and logger
+func logPrint(ctx *Context, format string, args ...interface{}) {
+ fmt.Printf(format, args...)
+ if ctx.Log.Out != os.Stdout {
+ ctx.Log.Infof(format, args...)
+ }
+}
+
// XDS Server application main routine
func xdsApp(cliCtx *cli.Context) error {
var err error
}
ctx.Config = cfg
- // Logs redirected into a file when logsDir is set
- logfilename := cliCtx.GlobalString("logfile")
+ // Logs redirected into a file when logfile option or logsDir config is set
ctx.Config.LogVerboseOut = os.Stderr
if ctx.Config.FileConf.LogsDir != "" {
- if logfilename != "stdout" {
- if logfilename == "" {
- logfilename = "xds-server.log"
- }
- // is it an absolute path ?
- logFile := logfilename
- if logfilename[0] == '.' || logfilename[0] != '/' {
- logFile = filepath.Join(ctx.Config.FileConf.LogsDir, logfilename)
- }
- fmt.Printf("Logging file: %s\n", logFile)
+ if ctx.Config.Options.LogFile != "stdout" {
+ logFile := ctx.Config.Options.LogFile
+
fdL, err := os.OpenFile(logFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
if err != nil {
msgErr := fmt.Sprintf("Cannot create log file %s", logFile)
return cli.NewExitError(msgErr, int(syscall.EPERM))
}
ctx.Log.Out = fdL
+
+ logPrint(ctx, "Logging file: %s\n", logFile)
}
logFileHTTPReq := filepath.Join(ctx.Config.FileConf.LogsDir, "xds-server-verbose.log")
- fmt.Printf("Logging file for HTTP requests: %s\n", logFileHTTPReq)
fdLH, err := os.OpenFile(logFileHTTPReq, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
if err != nil {
msgErr := fmt.Sprintf("Cannot create log file %s", logFileHTTPReq)
return cli.NewExitError(msgErr, int(syscall.EPERM))
}
ctx.Config.LogVerboseOut = fdLH
+
+ logPrint(ctx, "Logging file for HTTP requests: %s\n", logFileHTTPReq)
}
// Create syncthing instance when section "syncthing" is present in config.json
if err != nil {
return cli.NewExitError(err, -4)
}
- fmt.Printf("Syncthing started (PID %d)\n", ctx.SThgCmd.Process.Pid)
+ logPrint(ctx, "Syncthing started (PID %d)\n", ctx.SThgCmd.Process.Pid)
ctx.Log.Infof("Starting Syncthing-inotify...")
ctx.SThgInotCmd, err = ctx.SThg.StartInotify()
if err != nil {
return cli.NewExitError(err, -4)
}
- fmt.Printf("Syncthing-inotify started (PID %d)\n", ctx.SThgInotCmd.Process.Pid)
+ logPrint(ctx, "Syncthing-inotify started (PID %d)\n", ctx.SThgInotCmd.Process.Pid)
// Establish connection with local Syncthing (retry if connection fail)
- fmt.Printf("Establishing connection with Syncthing...\n")
+ logPrint(ctx, "Establishing connection with Syncthing...\n")
time.Sleep(2 * time.Second)
maxRetry := 30
retry := maxRetry
[ "$ID" = "" ] && ID=0
-docker ps -a |grep "$IMAGE" > /dev/null
-[ "$?" = "0" ] && { echo "Image name already exist ! (use -h option to read help)"; exit 1; }
-
-
USER=$(id -un)
echo "Using instance ID #$ID (user $(id -un))"
NAME=agl-xds-$(hostname|cut -f1 -d'.')-$ID-$USER
+docker ps -a |grep "$NAME" > /dev/null
+[ "$?" = "0" ] && { echo "Image name already exist ! (use -h option to read help)"; exit 1; }
+
MIRRORDIR=$HOME/ssd/localmirror_$ID
XDTDIR=$HOME/ssd/xdt_$ID
SHAREDDIR=$HOME/$DOCKER_USER/docker/share
fi
if ($FORCE); then
- echo "Stoping xds-server..."
- docker exec --user $DOCKER_USER ${NAME} bash -c "/usr/local/bin/xds-server-stop.sh" || exit 1
+ echo "Stopping xds-server..."
+ docker exec -t ${NAME} bash -c "systemctl stop xds-server" || exit 1
sleep 1
echo "Starting xds-server..."
- docker exec --user $DOCKER_USER ${NAME} bash -c "nohup /usr/local/bin/xds-server-start.sh" || exit 1
+ docker exec -t ${NAME} bash -c "systemctl start xds-server" || exit 1
fi
echo "Copying your identity to container $NAME"
count=0
while [ $res -ne 0 ] && [ $count -le $max ]; do
sleep 1
- docker exec ${NAME} bash -c "systemctl status ssh" 2>/dev/null 1>&2
+ docker exec ${NAME} bash -c "systemctl status ssh" 2>/dev/null 1>&2
res=$?
echo -n "."
count=$(expr $count + 1);
#!/bin/bash
-# Configurable variables
-[ -z "$BINDIR" ] && BINDIR=/usr/local/bin
-[ -z "$XDS_CONFFILE" ] && XDS_CONFFILE=$HOME/.xds/config.json
-[ -z "$XDS_SHAREDIR" ] && XDS_SHAREDIR=$HOME/.xds/share
-[ -z "$ST_CONFDIR" ] && ST_CONFDIR=$HOME/.xds/syncthing-config
-[ -z "$XDS_WWWDIR" ] && XDS_WWWDIR=webapp/dist
-[ -z "$LOGLEVEL" ] && LOGLEVEL=info
-[ -z "$LOGDIR" ] && LOGDIR=/tmp/xds-server/logs
-[ -z "PORT_SRV" ] && PORT_SRV=8000
-[ -z "$PORT_GUI" ] && PORT_GUI=8384
-[ -z "$API_KEY" ] && API_KEY="1234abcezam"
-[ -z "$UPDATE_XDS_TARBALL" ] && UPDATE_XDS_TARBALL=1
-
-[[ -f $BINDIR/xds-server ]] || { echo "Cannot find xds-server in BINDIR !"; exit 1; }
-
-# Create config.json file when needed
-if [ ! -f "${XDS_CONFFILE}" ]; then
- mv ${XDS_CONFFILE} ${XDS_CONFFILE}.old
- [ ! -f "$XDS_WWWDIR/index.html" ] && XDS_WWWDIR=$BINDIR/www-xds-server
- [ ! -f "$XDS_WWWDIR/index.html" ] && XDS_WWWDIR=/var/www/xds-server
- [ ! -f "$XDS_WWWDIR/index.html" ] && { echo "Cannot determine XDS-server webapp directory."; exit 1; }
- cat <<EOF > ${XDS_CONFFILE}
-{
- "HTTPPort": ${PORT_SRV},
- "webAppDir": "${XDS_WWWDIR}",
- "shareRootDir": "${XDS_SHAREDIR}",
- "logsDir": "${LOGDIR}",
- "sdkRootDir": "/xdt/sdk",
- "syncthing": {
- "binDir": "${BINDIR}",
- "home": "${ST_CONFDIR}",
- "gui-address": "http://localhost:${PORT_GUI}",
- "gui-apikey": "${API_KEY}"
- }
-}
-EOF
-fi
-
-echo "### Configuration in config.json: "
-cat ${XDS_CONFFILE}
-echo ""
-
-mkdir -p ${LOGDIR}
-LOG_XDS=${LOGDIR}/xds-server.log
-
-# Download xds-agent tarball
-if [ "${UPDATE_XDS_TARBALL}" = 1 ]; then
- SCRIPT_GET_XDS_TARBALL=$BINDIR/xds-utils/get-xds-agent.sh
- if [ ! -f ${SCRIPT_GET_XDS_TARBALL} ]; then
- SCRIPT_GET_XDS_TARBALL=$(dirname $0)/xds-utils/get-xds-agent.sh
- fi
- if [ -f ${SCRIPT_GET_XDS_TARBALL} ]; then
- TARBALLDIR=${XDS_WWWDIR}/assets/xds-agent-tarballs
- [ ! -d "$TARBALLDIR" ] && TARBALLDIR=$BINDIR/www-xds-server/assets/xds-agent-tarballs
- [ ! -d "$TARBALLDIR" ] && TARBALLDIR=$(grep webAppDir ~/.xds/config.json|cut -d '"' -f 4)/assets/xds-agent-tarballs
- if [ -d "$TARBALLDIR" ]; then
- DEST_DIR=$TARBALLDIR $SCRIPT_GET_XDS_TARBALL
- else
- echo "WARNING: cannot download / update xds-agent tarballs (DESTDIR error)"
- fi
- else
- echo "WARNING: cannot download / update xds-agent tarballs"
- fi
-fi
-
+BINDIR=/opt/AGL/bin
+[[ -f $BINDIR/xds-server ]] || BINDIR=$(which xds-server)
+[[ -f $BINDIR/xds-server ]] || BINDIR=/usr/local/bin ;# for backward compat
+[[ -f $BINDIR/xds-server ]] || { echo "Cannot find xds-server executable !"; exit 1; }
echo "### Start XDS server"
-echo "nohup $BINDIR/xds-server --config $XDS_CONFFILE -log $LOGLEVEL > $LOG_XDS 2>&1"
-if [ "$1" != "-dryrun" ]; then
- nohup $BINDIR/xds-server --config $XDS_CONFFILE -log $LOGLEVEL > $LOG_XDS 2>&1 &
- pid_xds=$(jobs -p)
- echo "pid=${pid_xds}"
-fi
-
-exit 0
+nohup $BINDIR/xds-server $* &
+exit $?
# XXX - may be cleanup
# Used as temporary HACK while waiting merge of #165
#[ -z "$SYNCTHING_INOTIFY_VERSION" ] && { SYNCTHING_INOTIFY_VERSION=master; SYNCTHING_INOTIFY_CMID=af6fbf9d63f95a0; }
-[ -z "$DESTDIR" ] && DESTDIR=/usr/local/bin
+[ -z "$DESTDIR" ] && DESTDIR=/opt/AGL/xds/server
[ -z "$TMPDIR" ] && TMPDIR=/tmp
[ -z "$GOOS" ] && GOOS=$(go env GOOS)
[ -z "$GOARCH" ] && GOARCH=$(go env GOARCH)
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}"