Skip to content

Commit

Permalink
Add new supervisor example config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Apr 17, 2015
1 parent e87bfbb commit a2e4c91
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 84 deletions.
28 changes: 17 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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
Expand All @@ -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), \
Expand All @@ -95,11 +99,13 @@ 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)"; \
cd ../..; \
)

package: multiplat
@echo ""; echo " -- Packaging multiplatform archives -- ";
@$(package_builds)
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/leaps_ace_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions config/leaps_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions config/leaps_files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions config/leaps_mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions config/leaps_postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 7 additions & 3 deletions config/leaps_share.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs
Submodule docs updated from 9b4a3b to 51a1d1
12 changes: 8 additions & 4 deletions leaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
51 changes: 48 additions & 3 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -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
```
4 changes: 2 additions & 2 deletions scripts/init.d/leaps
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions scripts/install-linux.sh

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/supervisor/conf.d/leaps.conf
Original file line number Diff line number Diff line change
@@ -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
18 changes: 0 additions & 18 deletions scripts/uninstall-linux.sh

This file was deleted.

0 comments on commit a2e4c91

Please sign in to comment.