-
Notifications
You must be signed in to change notification settings - Fork 3
/
cherrymusic
176 lines (154 loc) · 4.87 KB
/
cherrymusic
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#! /bin/sh
### BEGIN INIT INFO
# Provides: cherrymusic
# Required-Start: $network $local_fs
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: CherryMusic Server Daemon
# Description: CherryMusic is a music streaming server based on CherryPy and jPlayer.
# It plays the music inside your PC, smartphone, tablet, toaster or
# whatever device has a HTML5 compliant browser installed.
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="CherryMusic"
NAME=cherrymusic
DIR= # add path to the cherrymusic folder; must not end with /
DAEMON=$DIR/cherrymusic
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
PYTHON= #add python executable path
# Git
GIT=`which git`
GIT_URL=https://github.com/devsnd/cherrymusic.git
GIT_BRANCH=devel
# Extra
WGET=`which wget`
CURL=`which curl`
DAEMON_ARGS=""
# Permissions
USER=
GROUP=
[ -x "$DAEMON" ] || exit 0
. /lib/init/vars.sh
. /lib/lsb/init-functions
do_start() {
if [ -e $PIDFILE ]; then
PID=`cat $PIDFILE`
if ( ps -p $PID > /dev/null ); then
log_failure_msg "$DESC '$NAME' is already running."
return 1
else
rm -f $PIDFILE
start-stop-daemon --start --background --chdir $DIR --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --quiet --exec $PYTHON $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --background --chdir $DIR --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --quiet --exec $PYTHON $DAEMON -- $DAEMON_ARGS || return 2
fi
else
start-stop-daemon --start --background --chdir $DIR --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --quiet --exec $PYTHON $DAEMON --test > /dev/null || return 1
start-stop-daemon --start --background --chdir $DIR --chuid $USER:$GROUP --make-pidfile --pidfile $PIDFILE --quiet --exec $PYTHON $DAEMON -- $DAEMON_ARGS || return 2
fi
}
do_stop() {
if [ -e $PIDFILE ]; then
PID=`cat $PIDFILE`
if ( ps -p $PID > /dev/null ); then
start-stop-daemon --stop --retry 1 --signal 2 --quiet --pidfile $PIDFILE
[ "$?" = 2 ] && return 2
else
log_failure_msg "$DESC '$NAME' is not running."
rm -f $PIDFILE
return 1
fi
else
log_failure_msg "$DESC '$NAME' is not running."
return 1
fi
}
do_update() {
if [ $? -le 1 ]; then
#if [ -n $GIT -a -d "$DIR/.git" ]; then
#$GIT --git-dir=$DIR/.git pull $GIT_URL $GIT_BRANCH && $GIT --git-dir=$DIR/.git reset --hard origin/$GIT_BRANCH || return 1
if [ -n $WGET -o -n $CURL ]; then
if [ -n $WGET ]; then
$WGET --no-check-certificate ${GIT_URL%.git}/tarball/$GIT_BRANCH -O - | tar xz --strip-components=1 -C $DIR || return 1
elif [ -n $CURL ]; then
$CURL ${GIT_URL%.git}/tarball/$GIT_BRANCH -L -o - | tar xz --strip-components=1 -C $DIR || return 1
fi
else
log_failure_msg "Update aborted. Please install either git, wget or curl."
return 1
fi
else
log_failure_msg "Update aborted, could not stop '$NAME'"
return 1
fi
}
case "$1" in
start)
log_daemon_msg "Starting $DESC..." "$NAME"
do_start
case "$?" in
0|1) log_end_msg 0 ;;
1) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC..." "$NAME"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
restart)
log_daemon_msg "Restarting $DESC..." "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
*) log_end_msg 1 ;;
esac
;;
*)
log_end_msg 1
;;
esac
;;
status)
if [ -e $PIDFILE ]; then
PID=`cat $PIDFILE`
if ( ps -p $PID > /dev/null ); then
log_success_msg "$DESC '$NAME' is running (pid $PID)."
exit 0
else
log_failure_msg "$DESC '$NAME' is not running."
rm -f $PIDFILE
exit 1
fi
else
log_failure_msg "$DESC '$NAME' is not running."
exit 1
fi
;;
update)
do_stop
case "$?" in
0|1)
do_update
case "$?" in
0) log_end_msg 0 ;;
*) log_end_msg 1 ;;
esac
;;
*)
log_end_msg 1
;;
esac
;;
*)
log_action_msg "Usage: $SCRIPTNAME {start|stop|restart|status|update}"
exit 0
;;
esac