-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uptime HTTP server, displays uptime information as response to HTTP r…
…equest
- Loading branch information
René Feiner
committed
Aug 24, 2015
0 parents
commit 1437ec8
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
BINARY = bin/uptime-httpd | ||
GO = env GOPATH="$(PWD)/vendor:$(PWD)" go | ||
|
||
all: | ||
@echo "make release # Build a release version" | ||
@echo "make run # Run a development version" | ||
|
||
release: clean | ||
@env GOOS=linux GOARCH=amd64 $(GO) build -o $(BINARY) uptime-httpd.go | ||
|
||
run: clean | ||
@$(GO) build -o $(BINARY) uptime-httpd.go | ||
@./$(BINARY) | ||
|
||
clean: | ||
rm -fr bin pkg vendor/pkg |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#! /bin/sh | ||
|
||
### BEGIN INIT INFO | ||
# Provides: uptime-httpd | ||
# Required-Start: $remote_fs $syslog | ||
# Required-Stop: $remote_fs $syslog | ||
# Should-Start: $network | ||
# Should-Stop: $network | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: Uptime HTTPd | ||
# Description: Starts the Uptime HTTPd service in the background | ||
### END INIT INFO | ||
|
||
PATH=/sbin:/usr/sbin:/bin:/usr/bin | ||
|
||
GOPATH="/path/to/this/project" | ||
|
||
UHTTPD="$GOPATH/bin/uptime-httpd" | ||
UHTTPD_NAME="uptime-httpd" | ||
UHTTPD_PID="/var/run/$UHTTPD_NAME.pid" | ||
UHTTPD_LOG_DIR="$/var/log/$UHTTPD_NAME" ; mkdir -p $UHTTPD_LOG_DIR | ||
UHTTPD_LOG_FILE="$UHTTPD_LOG_DIR/$UHTTPD_NAME.log" | ||
|
||
SSD_PARAMS="--quiet --oknodo --pidfile $UHTTPD_PID" | ||
|
||
set -e | ||
test -x $UHTTPD || exit 0 | ||
|
||
. /lib/lsb/init-functions | ||
|
||
case "$1" in | ||
start) | ||
log_daemon_msg "Starting Uptime HTTPd service" "$UHTTPD_NAME" || true | ||
if start-stop-daemon --start $SSD_PARAMS --make-pidfile --background --no-close --exec $UHTTPD >> $UHTTPD_LOG_FILE 2>&1; then | ||
log_end_msg 0 || true | ||
else | ||
log_end_msg 1 || true | ||
fi | ||
;; | ||
|
||
stop) | ||
log_daemon_msg "Stopping Uptime HTTPd service" "$UHTTPD_NAME" || true | ||
if start-stop-daemon --stop --retry 10 $SSD_PARAMS; then | ||
log_end_msg 0 || true | ||
else | ||
log_end_msg 1 || true | ||
fi | ||
;; | ||
|
||
restart) | ||
$0 stop | ||
$0 start | ||
;; | ||
|
||
status) | ||
status_of_proc -p $UHTTPD_PID $UHTTPD $UHTTPD_NAME && exit 0 || exit $? | ||
;; | ||
|
||
*) | ||
log_action_msg "Usage: /etc/init.d/$UHTTPD_NAME {start|stop|restart|status}" || true | ||
exit 1 | ||
esac | ||
|
||
exit 0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# _uptime_ HTTP server | ||
|
||
## Features | ||
* Returns _uptime_ of server running the uptime-http-server | ||
* Define listening socket using _-socket_ | ||
|
||
## Usage | ||
``` | ||
./uptime-httpd [-socket=":80"] | ||
``` | ||
|
||
## Todo (someday) | ||
* Request logging | ||
|
||
## Author | ||
* [René Feiner](http://feiner.nu) for internal usage at [MessageBird](https://www.messagebird.com) | ||
|
||
## Thanks to | ||
* [Maurice Nonnekes](https://github.com/prep) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"log" | ||
"flag" | ||
"os/exec" | ||
) | ||
|
||
var bindSocket = flag.String("socket", ":80", "Define socket where to listen for the HTTP requests") | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
out, err := exec.Command("/usr/bin/uptime").Output() | ||
if err != nil { | ||
fmt.Fprintf(w, "Error, unable to retrieve uptime: %s", err) | ||
log.Fatal(err) | ||
} | ||
fmt.Fprintf(w, "%s", out) | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
fmt.Printf("Starting server at %s\n", *bindSocket) | ||
|
||
http.HandleFunc("/", handler) | ||
http.ListenAndServe(*bindSocket, nil) | ||
} |