forked from windock/erlyvideo
/
erlyctl
executable file
·114 lines (97 loc) · 2 KB
/
erlyctl
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
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: erlyvideo
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start erlyvideo at boot time and control it in runtime
# Description: Enable service provided by erlyvideo.
### END INIT INFO
NODE=ems
HOST=`hostname`
DOTTED=`hostname | grep '\.'`
if [ "" = "$DOTTED" ] ;then
TYPE="sname"
else
TYPE="name"
fi
ERL="erl +A 4 +K true"
start()
{
export ERL_LIBS=deps:lib:plugins:..
EBIN=`erl -eval 'io:format("~s", [code:lib_dir(erlyvideo,ebin)])' -s init stop -noshell`
if [ -f "/etc/erlyvideo/production.config" ] ; then
CONFIG="-config /etc/erlyvideo/production.config"
else if [ -f "priv/production.config" ] ; then
CONFIG="-config priv/production.config"
else
CONFIG=""
fi
fi
$ERL -noinput -detached -pa ebin -pa "$EBIN" -pa /var/lib/erlyvideo/plugins $CONFIG \
-kernel error_logger false \
-boot start_sasl \
-s erlyvideo \
-$TYPE $NODE@$HOST
}
run()
{
if [ -f "priv/dev.config" ] ; then
CONFIG="-config priv/dev.config"
else if [ -f "/etc/erlyvideo/dev.config" ] ; then
CONFIG="-config /etc/erlyvideo/dev.config"
else
CONFIG=""
fi
fi
ERL_LIBS=apps:.. $ERL -pa apps/erlyvideo/ebin -pa /var/lib/erlyvideo/plugins $CONFIG \
-boot start_sasl \
-s erlyvideo \
-$TYPE $NODE@$HOST
exit
}
shell()
{
$ERL \
-$TYPE debug$NODE@$HOST \
-pa ebin \
-hidden \
-remsh $NODE@$HOST
}
ctl()
{
$ERL \
-$TYPE ctl$NODE@$HOST \
-pa ebin \
-noinput \
-hidden \
-s erlyvideo_ctl -extra $NODE@$HOST $@
}
usage()
{
cat <<-EOF
erlyctl run (in foreground)
erlyctl start (in background)
erlyctl shell (remote shell)
erlyctl stop (shutdown server)
erlyctl reload (validate and reload config file)
erlyctl restart (reload config file and restart whole server)
EOF
exit
}
stop()
{
ctl stop
}
reload()
{
ctl restart
}
restart()
{
ctl restart
}
[ $# -lt 1 ] && usage
$@