-
Notifications
You must be signed in to change notification settings - Fork 1
/
pijs-boot.sh
executable file
·69 lines (57 loc) · 1.58 KB
/
pijs-boot.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
#! /bin/sh
### BEGIN INIT INFO
# Provides: pijs
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Connects to the pijs.io cloud platform
# Description: This daemon will connect to pijs.io, download and execute
# code. Go to www.pijs.io to program your device.
### END INIT INFO
# Author: Thomas Sarlandie <[email protected]>
# Heavily relies on npm module forever to daemonize/kill node scripts
PATH=/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
NAME=pijs
SCRIPTNAME=/etc/init.d/$NAME
DESC="Client for pijs.io cloud platform"
DAEMON=/usr/local/bin/pi-nook
DAEMON_ARGS=""
USER=pi
LOGS=/var/log/pijs
FOREVER=/usr/local/bin/forever
FOREVER_ARGS="-a -p $LOGS -l $LOGS/pijs.log"
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if forever is not installed
[ -x $FOREVER ] || exit 0
# Create logs directory and setup owner.
if [ ! -d $LOGS ]
then
mkdir -p $LOGS
chown $USER $LOGS
fi
case "$1" in
start)
echo "pijs.io: Launching client ..."
su - $USER -c "$FOREVER start $FOREVER_ARGS $DAEMON $DAEMON_ARGS"
;;
stop)
echo "pijs.io: Stopping client ..."
su - $USER -c "$FOREVER stop $FOREVER_ARGS $DAEMON"
;;
restart)
echo "pijs.io: Restarting client ..."
su - $USER -c "$FOREVER restart $FOREVER_ARGS $DAEMON"
;;
status)
su - $USER -c "$FOREVER list $FOREVER_ARGS"
;;
logs)
tail $LOGS/pijs.log
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|update|updategit|logs}" >&2
exit 3
;;
esac