diff --git a/functions b/install/functions similarity index 100% rename from functions rename to install/functions diff --git a/jumpserver.conf b/jumpserver.conf index 2e1668a6d..f1a166c09 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -2,6 +2,8 @@ url = http://192.168.244.129 websocket_url = ws://192.168.244.129 key = 88aaaf7ffe3c6c04 +ip = 127.0.0.1 +port = 8080 log = debug [db] diff --git a/jumpserver/settings.py b/jumpserver/settings.py index a8c0d4dc3..24c0ea27a 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -42,6 +42,8 @@ KEY = config.get('base', 'key') URL = config.get('base', 'url') LOG_LEVEL = config.get('base', 'log') 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 # See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ diff --git a/run_websocket.py b/run_server.py similarity index 98% rename from run_websocket.py rename to run_server.py index ddd724697..c8240ea9f 100755 --- a/run_websocket.py +++ b/run_server.py @@ -33,8 +33,9 @@ except ImportError: import json os.environ['DJANGO_SETTINGS_MODULE'] = 'jumpserver.settings' -define("port", default=3000, help="run on the given port", type=int) -define("host", default='0.0.0.0', help="run port on given host", type=str) +from jumpserver.settings import IP, PORT +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'): @@ -317,6 +318,8 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): 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.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.channel = self.ssh.invoke_shell(term='xterm') WebTerminalHandler.tasks.append(MyThread(target=self.forward_outbound)) @@ -461,6 +464,6 @@ if __name__ == '__main__': # server.bind(options.port, options.host) # #server.listen(options.port) # server.start(num_processes=5) - # print "Run server on %s:%s" % (options.host, options.port) # tornado.ioloop.IOLoop.instance().start() + print "Run server on %s:%s" % (options.host, options.port) main() diff --git a/service.sh b/service.sh index d2a9d06c0..f338938ee 100755 --- a/service.sh +++ b/service.sh @@ -4,85 +4,84 @@ # chkconfig: - 85 12 # description: Open source detecting system # processname: jumpserver -# Date: 2015-04-12 -# Version: 2.0.0 +# Date: 2016-02-27 +# Version: 3.0.1 # Site: http://www.jumpserver.org # Author: Jumpserver Team +jumpserver_dir= + 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 -export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin +if [ -f ${jumpserver_dir}/install/functions ];then + . ${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="jumpsever" +PROC_NAME="jumpserver" lockfile=/var/lock/subsys/${PROC_NAME} - start() { jump_start=$"Starting ${PROC_NAME} service:" - if [ -f $lockfile ];then - echo "jumpserver is running..." - success "$jump_start" + echo -n "jumpserver is running..." + success "$jump_start" + echo else - daemon python $base_dir/manage.py runserver 0.0.0.0:80 &>> /tmp/jumpserver.log 2>&1 & - daemon python $base_dir/manage.py crontab add &>> /tmp/jumpserver.log 2>&1 - daemon python $base_dir/run_websocket.py &> /dev/null 2>&1 & - sleep 4 - - echo -n "$jump_start" - nums=0 - for i in manage.py run_websocket.py;do - if ps aux | grep "$i" | grep -v 'grep' &> /dev/null; then - nums=$[nums+1] - else - echo "$i not running" - fi - done - - if [ "x$nums" == "x2" ];then - success "$jump_start" - if [ ! -e $lockfile ]; then - lockfile_dir=`dirname $lockfile` - mkdir -pv $lockfile_dir + daemon python $jumpserver_dir/manage.py crontab add &>> /var/log/jumpserver.log 2>&1 + daemon python $jumpserver_dir/run_server.py &> /dev/null 2>&1 & + sleep 1 + echo -n "$jump_start" + ps axu | grep 'run_server' | grep -v 'grep' &> /dev/null + if [ $? == '0' ];then + success "$jump_start" + touch "$lockfile" + echo + else + failure "$jump_start" + echo fi - touch "$lockfile" - echo - else - failure "$jump_start" - echo - fi - fi - - + fi } stop() { - - echo -n $"Stopping ${PROC_NAME} service:" - - daemon python $base_dir/manage.py crontab remove &>> /tmp/jumpserver.log 2>&1 - ps aux | grep -E 'manage.py|run_websocket.py' | grep -v grep | awk '{print $2}' | xargs kill -9 &> /dev/null - ret=$? - - if [ $ret -eq 0 ]; then - echo_success - echo + 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 + ret=$? + if [ $ret -eq 0 ]; then + echo_success + echo rm -f "$lockfile" - else - echo_failure - echo + else + echo_failure + echo 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(){ @@ -103,7 +102,10 @@ case "$1" in restart ;; + status) + status + ;; *) - echo $"Usage: $0 {start|stop|restart}" + echo $"Usage: $0 {start|stop|restart|status}" exit 2 esac