From a2e4c91a95a6337dead5c28898b32621774a83a9 Mon Sep 17 00:00:00 2001 From: jeffail Date: Fri, 17 Apr 2015 23:30:30 +0000 Subject: [PATCH] Add new supervisor example config --- Makefile | 28 +++++++++------ README.md | 6 ++-- config/leaps_ace_example.yaml | 4 +-- config/leaps_example.yaml | 4 +-- config/leaps_files.yaml | 4 +-- config/leaps_mysql.yaml | 4 +-- config/leaps_postgres.yaml | 4 +-- config/leaps_share.yaml | 10 ++++-- docs | 2 +- leaps.go | 12 ++++--- scripts/README.md | 51 ++++++++++++++++++++++++++-- scripts/init.d/leaps | 4 +-- scripts/install-linux.sh | 29 ---------------- scripts/supervisor/conf.d/leaps.conf | 5 +++ scripts/uninstall-linux.sh | 18 ---------- 15 files changed, 101 insertions(+), 84 deletions(-) delete mode 100755 scripts/install-linux.sh create mode 100644 scripts/supervisor/conf.d/leaps.conf delete mode 100755 scripts/uninstall-linux.sh diff --git a/Makefile b/Makefile index f01b9e4..70d1420 100644 --- a/Makefile +++ b/Makefile @@ -36,21 +36,21 @@ GOFLAGS := -ldflags "-X github.com/jeffail/util.version $(VERSION) \ help: @echo "Leaps build system, run one of the following commands:" @echo "" - @echo " make build : Build the service and generate client libraries" + @echo " make build : Build the service and generate client libraries" @echo "" - @echo " make lint : Run linting on both .go and .js files" - @echo " make check : Run unit tests on both Golang and JavaScript code" + @echo " make lint : Run linting on both .go and .js files" + @echo " make check : Run unit tests on both Golang and JavaScript code" @echo "" - @echo " make package : Package the service, scripts and client libraries" - @echo " into a .tar.gz archive for all supported operating" - @echo " systems" + @echo " make package : Package the service, scripts and client libraries" + @echo " into a .tar.gz archive for all supported operating" + @echo " systems" @echo "" - @echo " make clean : Clean the repository of any built/generated files" + @echo " make clean : Clean the repository of any built/generated files" build: check @mkdir -p $(JS_BIN) - @echo "building $(BIN)/$(PROJECT)" + @echo ""; echo " -- Building $(BIN)/$(PROJECT) -- "; @go build -o $(BIN)/$(PROJECT) $(GOFLAGS) @cp $(BIN)/$(PROJECT) $$GOPATH/bin @echo "copying/compressing js libraries into $(JS_BIN)" @@ -60,12 +60,14 @@ build: check GOLINT=$(shell golint .) lint: + @echo ""; echo " -- Linting Golang and JavaScript files -- "; @gofmt -w . && go tool vet ./**/*.go && echo "$(GOLINT)" && test -z "$(GOLINT)" && jshint $(JS_PATH)/*.js check: lint + @echo ""; echo " -- Unit testing Golang and JavaScript files -- "; @go test ./... @cd $(JS_PATH); find . -maxdepth 1 -name "test_*" -exec nodeunit {} \; - @echo ""; echo " -- Testing complete -- "; echo ""; + @echo ""; echo " -- Testing complete -- "; clean: @find $(GOPATH)/pkg/*/github.com/jeffail -name $(PROJECT).a -delete @@ -76,12 +78,14 @@ PLATFORMS = "darwin/amd64/" "freebsd/amd64/" "freebsd/arm/7" "freebsd/arm/5" "li multiplatform_builds = $(foreach platform, $(PLATFORMS), \ plat="$(platform)" armspec="$${plat\#*/}" \ GOOS="$${plat%/*/*}" GOARCH="$${armspec%/*}" GOARM="$${armspec\#*/}"; \ - bindir="$(BIN)/$${GOOS}_$${GOARCH}$${GOARM}" exepath="$${bindir}/$(PROJECT)"; \ + bindir="$(BIN)/$${GOOS}_$${GOARCH}$${GOARM}" exepath="$${bindir}/bin/$(PROJECT)"; \ echo "building $${exepath} with GOOS=$${GOOS}, GOARCH=$${GOARCH}, GOARM=$${GOARM}"; \ - mkdir -p "$$bindir"; GOOS=$$GOOS GOARCH=$$GOARCH GOARM=$$GOARM go build -o "$$exepath" $(GOFLAGS); \ + mkdir -p "$${bindir}/bin"; \ + GOOS=$$GOOS GOARCH=$$GOARCH GOARM=$$GOARM go build -o "$$exepath" $(GOFLAGS); \ ) multiplat: build + @echo ""; echo " -- Building multiplatform binaries -- "; @$(multiplatform_builds) package_builds = $(foreach platform, $(PLATFORMS), \ @@ -95,6 +99,7 @@ package_builds = $(foreach platform, $(PLATFORMS), \ cp -LR "./config" "./releases/$(VERSION)/$(PROJECT)"; \ cp -LR "./static" "./releases/$(VERSION)/$(PROJECT)"; \ cp -LR "./scripts" "./releases/$(VERSION)/$(PROJECT)"; \ + cp -LR "./docs" "./releases/$(VERSION)/$(PROJECT)"; \ cd "./releases/$(VERSION)"; \ tar -czf "$${a_name}.tar.gz" "./$(PROJECT)"; \ rm -r "./$(PROJECT)"; \ @@ -102,4 +107,5 @@ package_builds = $(foreach platform, $(PLATFORMS), \ ) package: multiplat + @echo ""; echo " -- Packaging multiplatform archives -- "; @$(package_builds) diff --git a/README.md b/README.md index fe26a24..b763192 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Leaps is a single binary, with no runtime dependencies, everything is set throug ```bash tar -xvf ./leaps-linux_amd64-v0.1.2.tar.gz cd leaps -./leaps -c ./config/leaps_example.yaml +./bin/leaps -c ./config/leaps_example.yaml ``` and then visit: http://localhost:8001 to play with an example server. @@ -21,10 +21,10 @@ To generate a configuration file of all default values: ```bash # for a JSON file -./leaps --print-json +./bin/leaps --print-json # for a YAML file -./leaps --print-yaml +./bin/leaps --print-yaml ``` ##Customizing your service diff --git a/config/leaps_ace_example.yaml b/config/leaps_ace_example.yaml index f1ca819..190952b 100644 --- a/config/leaps_ace_example.yaml +++ b/config/leaps_ace_example.yaml @@ -25,13 +25,13 @@ http_server: static_path: / socket_path: /socket address: :8001 - www_dir: ./static/example_ace + www_dir: ../static/example_ace binder: bind_send_timeout_ms: 10 stats_server: static_path: / stats_path: /stats address: :4040 - www_dir: ./static/stats + www_dir: ../static/stats stat_timeout_ms: 200 request_timeout_s: 10 diff --git a/config/leaps_example.yaml b/config/leaps_example.yaml index 51552be..0065e4f 100644 --- a/config/leaps_example.yaml +++ b/config/leaps_example.yaml @@ -25,13 +25,13 @@ http_server: static_path: / socket_path: /socket address: :8001 - www_dir: ./static/example + www_dir: ../static/example binder: bind_send_timeout_ms: 10 stats_server: static_path: / stats_path: /stats address: :4040 - www_dir: ./static/stats + www_dir: ../static/stats stat_timeout_ms: 200 request_timeout_s: 10 diff --git a/config/leaps_files.yaml b/config/leaps_files.yaml index d5bb6c5..2315374 100644 --- a/config/leaps_files.yaml +++ b/config/leaps_files.yaml @@ -21,13 +21,13 @@ http_server: static_path: / socket_path: /socket address: :8001 - www_dir: ./static/example_file + www_dir: ../static/example_file binder: bind_send_timeout_ms: 10 stats_server: static_path: / stats_path: /stats address: :4040 - www_dir: ./static/stats + www_dir: ../static/stats stat_timeout_ms: 200 request_timeout_s: 10 diff --git a/config/leaps_mysql.yaml b/config/leaps_mysql.yaml index 54fe5b2..64468e6 100644 --- a/config/leaps_mysql.yaml +++ b/config/leaps_mysql.yaml @@ -30,13 +30,13 @@ http_server: static_path: / socket_path: /socket address: :8001 - www_dir: ./static/example + www_dir: ../static/example binder: bind_send_timeout_ms: 10 stats_server: static_path: / stats_path: /stats address: :4040 - www_dir: ./static/stats + www_dir: ../static/stats stat_timeout_ms: 200 request_timeout_s: 10 diff --git a/config/leaps_postgres.yaml b/config/leaps_postgres.yaml index 6262642..cb26449 100644 --- a/config/leaps_postgres.yaml +++ b/config/leaps_postgres.yaml @@ -30,13 +30,13 @@ http_server: static_path: / socket_path: /socket address: :8001 - www_dir: ./static/example + www_dir: ../static/example binder: bind_send_timeout_ms: 10 stats_server: static_path: / stats_path: /stats address: :4040 - www_dir: ./static/stats + www_dir: ../static/stats stat_timeout_ms: 200 request_timeout_s: 10 diff --git a/config/leaps_share.yaml b/config/leaps_share.yaml index f46d0ce..bed256a 100644 --- a/config/leaps_share.yaml +++ b/config/leaps_share.yaml @@ -13,12 +13,16 @@ # (e.g. http://192.168.0.134:8001) # # # # There are three important set up steps: # -# - Install leaps using the ./install.sh script # -# - Copy this configuration into /etc/leaps/config.yaml # +# - Move the leaps folder anywhere (/opt/leaps is good) # +# - Copy this conf file into the root of the folder (/opt/leaps/config.yaml) # +# - OPTIONAL: Add the bin directory to your PATH variable (/opt/leaps/bin) # # # # Then use it like this: # # ( cd /dir/that/i/want/to/share && leaps ) # # # +# Or, if you didn't add it to your PATH: # +# ( cd /dir/that/i/want/to/share && /opt/leaps/bin/leaps ) # +# # ################################################################################ logger: @@ -38,4 +42,4 @@ http_server: static_path: / socket_path: /socket address: :8001 - www_dir: /etc/leaps/www/share_dir + www_dir: ../static/share_dir diff --git a/docs b/docs index 9b4a3ba..51a1d14 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 9b4a3baceb9002c98afcc0064e939ab94fbb6bbc +Subproject commit 51a1d140132b8f635710910cccf9aefd6f0c0832 diff --git a/leaps.go b/leaps.go index cc62348..5de48eb 100644 --- a/leaps.go +++ b/leaps.go @@ -93,11 +93,15 @@ func main() { // A list of default config paths to check for if not explicitly defined defaultPaths := []string{} + /* If we manage to get the path of our executable then we want to try and find config files + * relative to that path, we always check from the parent folder since we assume leaps is + * stored within the bin folder. + */ if executablePath, err := osext.ExecutableFolder(); err == nil { - defaultPaths = append(defaultPaths, filepath.Join(executablePath, "config.yaml")) - defaultPaths = append(defaultPaths, filepath.Join(executablePath, "config", "leaps.yaml")) - defaultPaths = append(defaultPaths, filepath.Join(executablePath, "config.json")) - defaultPaths = append(defaultPaths, filepath.Join(executablePath, "config", "leaps.json")) + defaultPaths = append(defaultPaths, filepath.Join(executablePath, "..", "config.yaml")) + defaultPaths = append(defaultPaths, filepath.Join(executablePath, "..", "config", "leaps.yaml")) + defaultPaths = append(defaultPaths, filepath.Join(executablePath, "..", "config.json")) + defaultPaths = append(defaultPaths, filepath.Join(executablePath, "..", "config", "leaps.json")) } defaultPaths = append(defaultPaths, []string{ diff --git a/scripts/README.md b/scripts/README.md index d5900a9..bd3594c 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -1,4 +1,49 @@ -Scripts -======= +Installing leaps +================ -Contains miscellaneous scripts for various actions, including installation and deployment stress testing. You should run these scripts from the parent directory. +Leaps is just a binary without runtime dependencies, so it can be stored anywhere and run. This is a simple guide demonstrating the quick and easy way to set leaps up on any linux/osx machine, but the reality is that you can put it anywhere that you'd like. + +The first step for installation was extracting the .tar.gz or cloning the repository, well done! + +The next step is to place the repository/package somewhere memorable and out of the way, it's easier for you to keep the static and config files along with the binary, so I tend to copy the entire leaps folder to `/opt`. If you do this then `ls /opt/leaps` should give you: + +``` +bin config docs js scripts static +``` + +Next you will want to write a config file, if you're working from a fresh folder then you can start yourself off by copying an example file: + +```bash +cd /opt/leaps +cp ./config/leaps_share.yaml ./config.yaml +``` + +For more information about leaps configuration check the docs folder. + +When leaps is run it will automatically find and use the `config.yaml` file in the leaps folder, regardless of where that folder is stored, because it searches from the location of the binary itself. + +Now, if you add `/opt/leaps/bin` to your PATH environment variable then you can run it at any time. However, if you wish to run leaps as a background service then we have an example init.d or supervisor config to use. + +## init.d + +Theres an example init.d script to use, this script assumes you copied the leaps directory to `/opt`, so quickly edit the file before moving on. It also assumes that there is a user "leaps" on your machine to run the service as, you can also change this or create the user: + +```bash +useradd -s /bin/bash leaps + +cp ./scripts/init.d/leaps /etc/init.d/leaps +chmod 755 /etc/init.d/leaps +chown root:root /etc/init.d/leaps + +update-rc.d leaps start 30 2 3 4 5 . stop 30 0 1 6 . +``` + +## supervisor + +The example supervisor config for leaps is much simpler, it also assumes you want to run the service as a user "leaps" and that the leaps folder is stored in `/opt`, just edit these values in the config to match reality and then copy it over: + +```bash +useradd -s /bin/bash leaps + +cp ./scripts/supervisor/conf.d/leaps.conf /etc/supervisor/conf.d/leaps.conf +``` diff --git a/scripts/init.d/leaps b/scripts/init.d/leaps index 3d0094f..264bace 100644 --- a/scripts/init.d/leaps +++ b/scripts/init.d/leaps @@ -8,11 +8,11 @@ # Description: Leaps is a service that hosts collaborative and shared documents for important people. ### END INIT INFO -DAEMON=/usr/sbin/leaps +DAEMON=/opt/leaps/bin/leaps NAME=leaps RUNAS=leaps -CONFIG=/etc/leaps/config.yaml +CONFIG=/opt/leaps/config.yaml PID=/var/run/leaps.pid LOG=/var/log/leaps.log diff --git a/scripts/install-linux.sh b/scripts/install-linux.sh deleted file mode 100755 index 38d52f6..0000000 --- a/scripts/install-linux.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -cp ./leaps /usr/sbin/leaps - -if [ ! -d /etc/leaps ]; then - mkdir -p /etc/leaps - cp -R ./static /etc/leaps/www -fi - -if [ ! -f /etc/leaps/config.yaml ]; then - echo "Installing fresh config file at /etc/leaps/config.yaml ..." - ./leaps --print-yaml > /etc/leaps/config.yaml -fi - -if [[ "$1" == "--init-daemon" ]]; then - echo "Setting up init.d script and leaps user ..." - id -u leaps &>/dev/null || (useradd -s /bin/bash leaps && echo leaps:leaps | chpasswd) - - cp ./scripts/init.d/leaps /etc/init.d/leaps - chmod 755 /etc/init.d/leaps - chown root:root /etc/init.d/leaps - - update-rc.d leaps start 30 2 3 4 5 . stop 30 0 1 6 . -elif [[ "$1" == "--supervisor" ]]; then - echo "Setting up supervisor script and leaps user ..." - id -u leaps &>/dev/null || (useradd -s /bin/bash leaps && echo leaps:leaps | chpasswd) - - #TODO -fi diff --git a/scripts/supervisor/conf.d/leaps.conf b/scripts/supervisor/conf.d/leaps.conf new file mode 100644 index 0000000..52dc60c --- /dev/null +++ b/scripts/supervisor/conf.d/leaps.conf @@ -0,0 +1,5 @@ +[program:leaps] +command = /opt/leaps/bin/leaps +autostart = true +stdout_logfile = /var/log/leaps-out.log +stderr_logfile = /var/log/leaps-err.log diff --git a/scripts/uninstall-linux.sh b/scripts/uninstall-linux.sh deleted file mode 100755 index a4a4d83..0000000 --- a/scripts/uninstall-linux.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -if [ -f /etc/init.d/leaps ]; then - /etc/init.d/leaps stop - - rm /etc/init.d/leaps - update-rc.d -f leaps remove -fi - -userdel leaps -rm -f /usr/sbin/leaps - -echo "Do you wish to keep the /etc/leaps directory? Y/n" -read answer - -if [[ "$answer" == "n" || "$answer" == "N" ]]; then - rm -rf /etc/leaps -fi