Last active
December 28, 2015 04:29
-
-
Save codemoran/7442551 to your computer and use it in GitHub Desktop.
Graphdat Relay Redhat / CentOS init script
This file contains 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 | |
## | |
## The graphdat-relay hosts and manages the graphdat plugins. | |
## Batching and sending data to graphdat.com | |
## | |
# chkconfig: 345 85 15 | |
# description: Graphdat Relay Daemon | |
# processname: graphdat-relay | |
# Source init functions | |
. /etc/rc.d/init.d/functions | |
#### CHANGE ME ### | |
# Where did you install the graphdat-relay's config files | |
CONFIG=/etc/graphdat-relay | |
################### | |
#### CHANGE ME ### | |
# Where is node installed? | |
# If you have done something custom like use nvm, please update | |
# the $NODEPATH instead of using this default | |
NODEBIN=$(which node) | |
NODEPATH=${NODEBIN%/*} | |
################### | |
#### CHANGE ME ### | |
# Where is the graphdat-relay installed? | |
# If you have done something custom like use nvm, please update | |
# the $DAEMON instead of using this default | |
DAEMON=$(which graphdat-relay-daemon) | |
################### | |
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:$NODEPATH | |
# Add $HOME to the ENV so node-gyp plays nicely | |
test -z $HOME && export HOME=/root | |
DESC="The graphdat-relay hosts plugins that send data to graphdat.com" | |
SCRIPTNAME=/etc/init.d/graphdat-relay | |
# Exit if node is not installed | |
if [ ! -x "$NODEBIN" ] && [ ! -L "$NODEBIN" ]; then | |
echo "** Node.js is either not installed or not in your current path" | |
echo "\"\$ which node\" gives back the value: \"$NODEBIN\"" | |
echo "-- To install nodejs, please go to http://nodejs.org/" | |
echo "-- If node is installed, please update the \$NODEBIN value in this init script" | |
exit 0 | |
fi | |
# Exit if the graphdat-relay is not installed | |
if [ ! -x "$DAEMON" ] && [ ! -L "$DAEMON" ]; then | |
echo "** The Graphdat relay was not found in your path" | |
echo "\"\$ which graphdat-relay-daemon\" gives back the value: \"$DAEMON\"" | |
echo "-- To install the graphdat relay run \$ sudo npm install graphdat-relay --global" | |
echo "-- If the graphdat-relay is installed, please update the \$DAEMON value in this init script" | |
exit 0 | |
fi | |
# Exit if the relay directory is not found | |
if [ ! -d "$CONFIG" ] && [ ! -L "$CONFIG" ]; then | |
echo "** The Graphdat relay directory was not found" | |
echo "The current CONFIG path is: \"$CONFIG\"" | |
echo "-- Please update the \$CONFIG value in this init script" | |
exit 0 | |
fi | |
# Exit if the relay directory does not contain a configuration file | |
if [ ! -f "$CONFIG/config.json" ]; then | |
echo "** The Graphdat relay directory does not contain a configuration file" | |
echo "The config.json file should be located in \"$CONFIG/config.json\"" | |
echo "-- To create the config file, please run the following in the $CONFIG directory:" | |
echo "-- \"\$ graphdat-relay -e your-email -t your-api-token\"" | |
exit 0 | |
fi | |
do_start() | |
{ | |
cd $CONFIG && $DAEMON start | |
} | |
do_stop() | |
{ | |
cd $CONFIG && $DAEMON stop | |
} | |
do_restart() | |
{ | |
cd $CONFIG && $DAEMON restart | |
} | |
do_status() | |
{ | |
cd $CONFIG && $DAEMON status | |
} | |
case "$1" in | |
start) | |
do_start | |
;; | |
stop) | |
do_stop | |
;; | |
restart) | |
do_restart | |
;; | |
status) | |
do_status | |
;; | |
*) | |
echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment