-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgrove.sh
executable file
·124 lines (112 loc) · 2 KB
/
grove.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
### BEGIN INIT INFO
# Provides: grove
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: none
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: Service script for the Grove daemon.
# Description: Start, stop, or restart the Grove webserver/daemon.
### END INIT INFO
#
# To use:
# sudo service grove {start|stop|restart|status|check}
#
# Determine the full path of the grove binary, if not set
if [ -z $GROVE ]; then
GROVE=$(which grove)
fi
# Attempt to locate the directory from which to serve files if not set
if [ -z "$SRC" ]; then
if [ -e ~/dev ]; then
SRC=~/dev
elif [ -e ~/src ]; then
SRC=~/src
elif [ $(git status >> /dev/null; echo $?) == 0 ]; then
# If the working directory is a git repository, use that.
SRC=$(pwd)
fi
fi
# Set default options if not set
if [ -z "$OPTIONS" ]; then
OPTIONS=""
fi
# Set the location to log to, if not set
if [ -z $LOG ]; then
LOG=/dev/null
fi
# Find the PID of any running instance owned by the current user
PID=$(pgrep -u "$(whoami)" -f -d " " $GROVE)
start()
{
if [ -z "$SRC" ]; then
echo "Could not determine the directory to serve"
return 1
fi
if [ ! -z "$PID" ]; then
echo "Grove is already running."
return 1
fi
if [ -z "$GROVE" ]; then
echo "Grove not found."
return 1
fi
$GROVE $OPTIONS $SRC >> $LOG &
echo "Started $GROVE serving $SRC"
return 0
}
stop()
{
if [ ! -z "$PID" ]; then
echo "Killing '$GROVE', PID $PID"
kill $PID
fi
}
restart()
{
stop
PID="" start
}
status()
{
echo -n "* Grove is "
if [ -z "$PID" ]; then
echo "not running."
return 1
else
echo "running."
return 0
fi
}
check()
{
status > /dev/null
if [ $? == 1 ]; then
echo "Grove was not running."
start
return 0
fi
echo "Grove is running."
}
case "$1" in
"start" )
start
;;
"stop" )
stop
;;
"restart" )
restart
;;
"force-reload" )
restart
;;
"status" )
status
;;
"check" )
check
;;
* )
echo "usage: $0 {start|stop|restart|status|check}"
esac