-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbox_init
74 lines (67 loc) · 1.59 KB
/
box_init
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
#! /bin/sh
### BEGIN INIT INFO
# Provides: live_platform
# Required-Start:
# Required-Stop:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start box default process
# Description: Start redis and nginx server, and start
# box default process of live_platform
#
### END INIT INFO
# RAMDISK SETTINGS
RAMDISK_SIZE=400
RAMDISK_PATH=/tmp
# Nginx SETTINGS
NGINX_PATH=/usr/local/nginx/sbin/nginx
NGINX_HTTP_PORT=8000
# REDIS SETTINGS
REDIS_PIDFILE=/var/run/redis_6379.pid
# PACKAGE SETTINGS
PACKAGE_PATH=/root/Dandelion
BOX_FILE=run_box.py
PROCESS_NUMBER=4 #Number of Multiprocess for box
# BASH SETTINGS
PROCESS_NAME=run_box
LOGFILE=${PACKAGE_PATH}/run_box.log
start() {
# Create ramdisk
mkdir -p $RAMDISK_PATH
mount -t tmpfs -o size=${RAMDISK_SIZE}M tmpfs ${RAMDISK_PATH}
# Start Nginx server
/usr/local/nginx/sbin/nginx
# Start Redis
redis-server --daemonize yes
# Start box process in background
if [ -e $PACKAGE_PATH ];then
nohup python3.6 ${PACKAGE_PATH}/${BOX_FILE} & 2>&1&
else
echo -e "PACKAGE MISSING, CAN'T START PROCESS"
fi
}
stop() {
/usr/local/nginx/sbin/nginx -s stop
redis-cli shutdown
pkill -9 python
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0