fix init.d script and add some docs
This commit is contained in:
parent
ae5f2a66ed
commit
1f573df67e
11
README.md
11
README.md
|
@ -25,9 +25,13 @@ $ ./metrics.sh --help
|
|||
## Installation
|
||||
|
||||
```sh
|
||||
$ git clone git@github.com:pstadler/metrics.sh.git
|
||||
$ git clone https://github.com/pstadler/metrics.sh.git
|
||||
```
|
||||
|
||||
## Running as a service on Linux
|
||||
|
||||
[Docs](init.d/README.md)
|
||||
|
||||
### Requirements
|
||||
|
||||
metrics.sh has been tested on Ubuntu 14.04 and Mac OS X but is supposed to run on most Unix-like operating systems. Some of the provided metrics require [procfs](http://en.wikipedia.org/wiki/Procfs) to be available when running on *nix. POSIX compliancy means that metrics.sh works with minimalistic command interpreters such as [dash](http://manpages.ubuntu.com/manpages/en/man1/dash.1.html). Built-in metrics do __not__ require root privileges.
|
||||
|
@ -248,8 +252,3 @@ docs () {
|
|||
echo "JSON_API_METHOD=$JSON_API_METHOD"
|
||||
}
|
||||
```
|
||||
|
||||
## Roadmap
|
||||
|
||||
- Test and improve init.d script and write docs for it
|
||||
- Tests
|
|
@ -0,0 +1,33 @@
|
|||
# Running metrics.sh as a service on Linux
|
||||
|
||||
Run the following commands as root:
|
||||
|
||||
```sh
|
||||
# Install at /opt/metrics.sh
|
||||
$ mkdir /opt && cd /opt
|
||||
$ git clone https://github.com/pstadler/metrics.sh.git
|
||||
$ cd metrics.sh
|
||||
# Install service
|
||||
$ ln -s $PWD/init.d/metrics.sh /etc/init.d/metrics.sh
|
||||
# Create config file
|
||||
$ mkdir /etc/metrics.sh && chmod 600 /etc/metrics.sh
|
||||
$ ./metrics.sh -C > /etc/metrics.sh/metrics.ini
|
||||
# At this point you should edit your config file
|
||||
# at /etc/metrics.sh/metrics.ini
|
||||
|
||||
# Start service
|
||||
$ service metrics.sh start
|
||||
# Stop service
|
||||
$ service metrics.sh stop
|
||||
# Check servie status
|
||||
$ service metrics.sh status
|
||||
|
||||
# Check log file
|
||||
$ tail /var/log/metrics.sh.log
|
||||
|
||||
# Automatically start/stop service when (re-)booting
|
||||
$ update-rc.d metrics.sh defaults
|
||||
|
||||
# Uninstall automatic start/stop
|
||||
$ update-rc.d -f metrics.sh remove
|
||||
```
|
|
@ -9,9 +9,10 @@
|
|||
# Description: Controls the metrics daemon "metrics.sh"
|
||||
### END INIT INFO
|
||||
|
||||
SCRIPT=<SCRIPT>
|
||||
RUNAS=<USER>
|
||||
CONFIG_FILE=<CONFIG_FILE>
|
||||
SCRIPT_DIR=/opt/metrics.sh
|
||||
CONFIG_FILE=/etc/metrics.sh/metrics.ini
|
||||
RUNAS=root
|
||||
SCRIPT=$SCRIPT_DIR/metrics.sh
|
||||
ARGS="-c $CONFIG_FILE"
|
||||
NAME=metrics.sh
|
||||
|
||||
|
@ -19,16 +20,19 @@ PIDFILE=/var/run/$NAME.pid
|
|||
LOGFILE=/var/log/$NAME.log
|
||||
|
||||
# Exit if the package is not installed
|
||||
[ -x "$DAEMON" ] || exit 0
|
||||
[ -x "$SCRIPT" ] || exit 0
|
||||
|
||||
cd $SCRIPT_DIR
|
||||
|
||||
start() {
|
||||
if [ -f $PIDFILE ] && kill -0 $(cat $PIDFILE); then
|
||||
PID=$([ -f $PIDFILE ] && cat $PIDFILE)
|
||||
if [ -n "$PID" ] && kill -0 $PID; then
|
||||
echo 'Service already running' >&2
|
||||
return 1
|
||||
fi
|
||||
echo 'Starting service...' >&2
|
||||
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
|
||||
su -c "$CMD $ARGS" $RUNAS > "$PIDFILE"
|
||||
local CMD="$SCRIPT $ARGS &> \"$LOGFILE\" & echo \$!"
|
||||
su -c "$CMD" $RUNAS > "$PIDFILE"
|
||||
echo 'Service started' >&2
|
||||
}
|
||||
|
||||
|
@ -43,29 +47,15 @@ stop() {
|
|||
}
|
||||
|
||||
status() {
|
||||
printf "%-50s" "Checking $NAME..."
|
||||
if [ -f $PIDFILE ]; then
|
||||
PID=$(cat $PIDFILE)
|
||||
if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
|
||||
printf "%s\n" "The process appears to be dead but pidfile still exists"
|
||||
if [ -z "$(ps axf | grep $PID | grep -v grep)" ]; then
|
||||
echo "The process appears to be dead but pidfile still exists"
|
||||
else
|
||||
echo "Running, the PID is $PID"
|
||||
echo "Service is running"
|
||||
fi
|
||||
else
|
||||
printf "%s\n" "Service not running"
|
||||
fi
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
echo -n 'Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] '
|
||||
local SURE
|
||||
read SURE
|
||||
if [ "$SURE" = "yes" ]; then
|
||||
stop
|
||||
rm -f "$PIDFILE"
|
||||
echo "Notice: log file was not removed: '$LOGFILE'" >&2
|
||||
update-rc.d -f <NAME> remove
|
||||
rm -fv "$0"
|
||||
echo "Service not running"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -79,13 +69,6 @@ case "$1" in
|
|||
status)
|
||||
status
|
||||
;;
|
||||
uninstall)
|
||||
uninstall
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|status|restart|uninstall}"
|
||||
echo "Usage: $0 {start|stop|status}"
|
||||
esac
|
||||
|
|
|
@ -69,7 +69,7 @@ main_collect () {
|
|||
trap "" 13
|
||||
trap - INT TERM EXIT
|
||||
echo Exit signal received, stopping...
|
||||
kill -13 -$$
|
||||
kill -13 0
|
||||
' 13 INT TERM EXIT
|
||||
|
||||
# init reporter
|
||||
|
|
Loading…
Reference in New Issue