1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Added rudimentary install script

This commit is contained in:
Zack Scholl 2016-02-06 09:11:02 -05:00
parent dbcb7a42c9
commit 107e20c283
5 changed files with 109 additions and 5 deletions

90
install/cowyo.init Executable file
View File

@ -0,0 +1,90 @@
# This should be placed in /etc/init.d directory
# start with
# sudo /etc/init.d/shrib start
# stop with
# sudo /etc/init.d/shrib start
dir="/home/phi/Documents/cowyo"
user="phi"
cmd="./cowyo cowyo.duckdns.org"
name="cowyo2"
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
get_pid() {
cat "$pid_file"
}
is_running() {
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
start)
if is_running; then
echo "Already started"
else
echo "Starting $name"
cd "$dir"
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
echo $! > "$pid_file"
if ! is_running; then
echo "Unable to start, see $stdout_log and $stderr_log"
exit 1
fi
fi
;;
stop)
if is_running; then
echo -n "Stopping $name.."
kill `get_pid`
for i in {1..10}
do
if ! is_running; then
break
fi
echo -n "."
sleep 1
done
echo
if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed"
exit 1
else
echo "Stopped"
if [ -f "$pid_file" ]; then
rm "$pid_file"
fi
fi
else
echo "Not running"
fi
;;
restart)
$0 stop
if is_running; then
echo "Unable to stop, will not attempt to start"
exit 1
fi
$0 start
;;
status)
if is_running; then
echo "Running"
else
echo "Stopped"
exit 1
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0

10
install/install.sh Executable file
View File

@ -0,0 +1,10 @@
apt-get update
apt-get install nginx
cp cowyo.nginx /etc/nginx/sites-available/
cp cowyo.init /etc/init.d/
ln -s /etc/nginx/sites-available/cowyo.nginx /etc/nginx/sites-enabled/cowyo.nginx
service nginx reload && service nginx restart
cd ../
go build
service cowyo.init start

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
"os"
"path" "path"
"runtime" "runtime"
"time" "time"
@ -16,6 +17,7 @@ import (
var db *bolt.DB var db *bolt.DB
var open bool var open bool
var ExternalIP string
func Open() error { func Open() error {
var err error var err error
@ -107,6 +109,10 @@ func (p *CowyoData) decode(data []byte) error {
} }
func main() { func main() {
if len(os.Args) == 1 {
log.Fatal("You need to specify the external IP address")
}
ExternalIP = os.Args[1]
Open() Open()
defer Close() defer Close()
r := gin.Default() r := gin.Default()
@ -123,7 +129,8 @@ func main() {
wshandler(c.Writer, c.Request) wshandler(c.Writer, c.Request)
} else { } else {
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Title": title, "Title": title,
"ExternalIP": ExternalIP,
}) })
} }

View File

@ -92,7 +92,7 @@
} }
// websockets // websockets
url = 'ws://cowyo.duckdns.org/ws'; url = 'ws://{{ .ExternalIP }}/ws';
c = new WebSocket(url); c = new WebSocket(url);
send = function(data){ send = function(data){

File diff suppressed because one or more lines are too long