change(service.sh, run_websocket) 修改启动脚本, rename run_websocket.py

1. 修改启动脚本,支持放到 init.d
2. rename run_websocket.py -> run_server.py 交互式启动
pull/97/head
ibuler 2016-02-27 01:26:36 +08:00
commit 532fbbd4f1
5 changed files with 70 additions and 61 deletions

View File

@ -2,6 +2,8 @@
url = http://192.168.244.129 url = http://192.168.244.129
websocket_url = ws://192.168.244.129 websocket_url = ws://192.168.244.129
key = 88aaaf7ffe3c6c04 key = 88aaaf7ffe3c6c04
ip = 127.0.0.1
port = 8080
log = debug log = debug
[db] [db]

View File

@ -42,6 +42,8 @@ KEY = config.get('base', 'key')
URL = config.get('base', 'url') URL = config.get('base', 'url')
LOG_LEVEL = config.get('base', 'log') LOG_LEVEL = config.get('base', 'log')
WEB_SOCKET_URL = config.get('base', 'websocket_url') WEB_SOCKET_URL = config.get('base', 'websocket_url')
IP = config.get('base', 'ip')
PORT = config.get('base', 'port')
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

View File

@ -33,8 +33,9 @@ except ImportError:
import json import json
os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings'
define("port", default=3000, help="run on the given port", type=int) from jumpserver.settings import IP, PORT
define("host", default='0.0.0.0', help="run port on given host", type=str) define("port", default=PORT, help="run on the given port", type=int)
define("host", default=IP, help="run port on given host", type=str)
def require_auth(role='user'): def require_auth(role='user'):
@ -317,6 +318,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self.term = WebTty(self.user, asset, login_role, login_type='web') self.term = WebTty(self.user, asset, login_role, login_type='web')
# self.term.remote_ip = self.request.remote_ip # self.term.remote_ip = self.request.remote_ip
self.term.remote_ip = self.request.headers.get("X-Real-IP") self.term.remote_ip = self.request.headers.get("X-Real-IP")
if not self.term.remote_ip:
self.term.remote_ip = self.request.remote_ip
self.ssh = self.term.get_connection() self.ssh = self.term.get_connection()
self.channel = self.ssh.invoke_shell(term='xterm') self.channel = self.ssh.invoke_shell(term='xterm')
WebTerminalHandler.tasks.append(MyThread(target=self.forward_outbound)) WebTerminalHandler.tasks.append(MyThread(target=self.forward_outbound))
@ -461,6 +464,6 @@ if __name__ == '__main__':
# server.bind(options.port, options.host) # server.bind(options.port, options.host)
# #server.listen(options.port) # #server.listen(options.port)
# server.start(num_processes=5) # server.start(num_processes=5)
# print "Run server on %s:%s" % (options.host, options.port)
# tornado.ioloop.IOLoop.instance().start() # tornado.ioloop.IOLoop.instance().start()
print "Run server on %s:%s" % (options.host, options.port)
main() main()

View File

@ -4,85 +4,84 @@
# chkconfig: - 85 12 # chkconfig: - 85 12
# description: Open source detecting system # description: Open source detecting system
# processname: jumpserver # processname: jumpserver
# Date: 2015-04-12 # Date: 2016-02-27
# Version: 2.0.0 # Version: 3.0.1
# Site: http://www.jumpserver.org # Site: http://www.jumpserver.org
# Author: Jumpserver Team # Author: Jumpserver Team
jumpserver_dir=
base_dir=$(dirname $0) base_dir=$(dirname $0)
jumpserver_dir=${jumpserver_dir:-$base_dir}
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
. ${base_dir}/functions if [ -f ${jumpserver_dir}/install/functions ];then
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin . ${jumpserver_dir}/install/functions
elif [ -f /etc/init.d/functions ];then
. /etc/init.d/functions
else
echo "No functions script found in [./functions, ./install/functions, /etc/init.d/functions]"
exit 1
fi
PROC_NAME="jumpserver"
PROC_NAME="jumpsever"
lockfile=/var/lock/subsys/${PROC_NAME} lockfile=/var/lock/subsys/${PROC_NAME}
start() { start() {
jump_start=$"Starting ${PROC_NAME} service:" jump_start=$"Starting ${PROC_NAME} service:"
if [ -f $lockfile ];then if [ -f $lockfile ];then
echo "jumpserver is running..." echo -n "jumpserver is running..."
success "$jump_start" success "$jump_start"
echo
else else
daemon python $base_dir/manage.py runserver 0.0.0.0:80 &>> /tmp/jumpserver.log 2>&1 & daemon python $jumpserver_dir/manage.py crontab add &>> /var/log/jumpserver.log 2>&1
daemon python $base_dir/manage.py crontab add &>> /tmp/jumpserver.log 2>&1 daemon python $jumpserver_dir/run_server.py &> /dev/null 2>&1 &
daemon python $base_dir/run_websocket.py &> /dev/null 2>&1 & sleep 1
sleep 4 echo -n "$jump_start"
ps axu | grep 'run_server' | grep -v 'grep' &> /dev/null
echo -n "$jump_start" if [ $? == '0' ];then
nums=0 success "$jump_start"
for i in manage.py run_websocket.py;do touch "$lockfile"
if ps aux | grep "$i" | grep -v 'grep' &> /dev/null; then echo
nums=$[nums+1] else
else failure "$jump_start"
echo "$i not running" echo
fi
done
if [ "x$nums" == "x2" ];then
success "$jump_start"
if [ ! -e $lockfile ]; then
lockfile_dir=`dirname $lockfile`
mkdir -pv $lockfile_dir
fi fi
touch "$lockfile" fi
echo
else
failure "$jump_start"
echo
fi
fi
} }
stop() { stop() {
echo -n $"Stopping ${PROC_NAME} service:"
echo -n $"Stopping ${PROC_NAME} service:" daemon python $jumpserver_dir/manage.py crontab remove &>> /var/log/jumpserver.log 2>&1
ps aux | grep -E 'run_server.py' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null
daemon python $base_dir/manage.py crontab remove &>> /tmp/jumpserver.log 2>&1 ret=$?
ps aux | grep -E 'manage.py|run_websocket.py' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null if [ $ret -eq 0 ]; then
ret=$? echo_success
echo
if [ $ret -eq 0 ]; then
echo_success
echo
rm -f "$lockfile" rm -f "$lockfile"
else else
echo_failure echo_failure
echo echo
rm -f "$lockfile" rm -f "$lockfile"
fi fi
} }
status(){
ps axu | grep 'run_server' | grep -v 'grep' &> /dev/null
if [ $? == '0' ];then
echo -n "jumpserver is running..."
success
touch "$lockfile"
echo
else
echo -n "jumpserver is not running."
failure
echo
fi
}
restart(){ restart(){
@ -103,7 +102,10 @@ case "$1" in
restart restart
;; ;;
status)
status
;;
*) *)
echo $"Usage: $0 {start|stop|restart}" echo $"Usage: $0 {start|stop|restart|status}"
exit 2 exit 2
esac esac