Created
December 5, 2012 01:53
-
-
Save palexander/4211360 to your computer and use it in GitHub Desktop.
4store-service: a script to start, stop and restart 4store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup for usage in Mac OSX (assuming you are using 4store.app from your /Applications folder) | |
curl -L https://raw.github.com/gist/4211360/81143f15fd6f9a3defcd38b6c24a922f3fc731ac/gistfile1.sh -o 4s-service | |
chmod +x 4s-service | |
mv 4s-service /Applications/4store.app/Contents/MacOS/bin | |
# Add the following to your (zsh|bash)rc path (this makes it so you don't have to run 4store.app): | |
# export PATH=/Applications/4store.app/Contents/MacOS/bin:$PATH | |
# You can also do this for custom installs of 4store, just replace the /Applications path with your own | |
# THE SCRIPT WILL NOT WORK WITHOUT 4s-backend, 4s-httpd, etc IN YOUR PATH | |
# Defaults: | |
PORT=9000 | |
KB=test | |
# Invoke 4s-service as follows: | |
4s-service start | |
4s-service start -p 8080 # custom port | |
4s-service start -k demo # custom knowledgebase | |
4s-service start -p 8080 -k demo | |
4s-service stop | |
4s-service restart # restarts running kbs/httpds with custom options |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Linux startup script for 4store | |
# chkconfig: 2345 99 20 | |
# description: Run an 4store backend and sparql http server | |
# processname: 4store | |
# | |
# To install, configure this file as needed and copy | |
# to /etc/rc.d/init.d as 4store. Then use "# /sbin/chkconfig 4store reset" | |
# Based on Michael Grove's script for 4store-api: | |
# https://github.com/mhgrove/4Store-API | |
# This script is incredibly naive. | |
# 1) Only tested on OSX Mountain Lion | |
# 2) For restarting, it inspects running processes and then | |
# attempts to run the same ones again. | |
# 3) It relies on sorting alphabetically to run 4s-backend before 4s-httpd. | |
# It does this in an attempt to preserve custom settings: | |
# IE 4s-service -p 8080 -k demo | |
# 4) It will also kill every instance of backend and httpd that is running. | |
# For more information, comments, or questions: https://gist.github.com/4211360 | |
# Defaults | |
KB="test" | |
PORT="9000" | |
# Output usage message | |
usage() { | |
echo "Usage: 4s-service (start|stop|restart) [-p <port>] [-k <knowledgebase>] [-h];" | |
exit 0; | |
} | |
# Get the start|stop|restart from the command | |
ACTION=$1 | |
shift | |
# Get non-default options | |
while getopts "k:p:h" opt; do | |
case "$opt" in | |
k) KB="$OPTARG";; # custom knowledgebase | |
p) PORT="$OPTARG";; # custom port | |
h) usage;; # calls function "usage" | |
\?) echo "$OPTARG is an unknown option" | |
exit 1;; # all other options | |
esac | |
done | |
# Process normal start|stop|restart | |
case "$ACTION" in | |
start) | |
echo "Starting 4store backend and httpd" | |
4s-backend $KB | |
4s-httpd -p $PORT $KB | |
;; | |
stop) | |
echo "Stopping all 4store backend and httpd" | |
killall "4s-httpd" | |
pkill -f '^4s-backend' | |
;; | |
restart) | |
running="$(ps -eo args | grep '^4s-[backend|httpd]' | sort | uniq)" | |
$0 stop | |
echo "Starting 4store backend and httpd" | |
while IFS=$'\n' read -ra CMD; do | |
for i in "${CMD[@]}"; do | |
$i | |
done | |
done <<< "$running" | |
;; | |
*) | |
usage | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment