From 37e0f80fb8cddd64316d23ec8d986d57820fbfe9 Mon Sep 17 00:00:00 2001 From: yumaojun <719118794@qq.com> Date: Sat, 27 Feb 2016 12:01:44 +0800 Subject: [PATCH] fix (install.py): fix install.py add user failed and service failed 1. use shlex.os.system replace subprocess.call 2. next.py use bash service start --- install/install.py | 12 +++++++++--- install/next.py | 9 +++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/install/install.py b/install/install.py index bb3b2027e..77c85b9d5 100755 --- a/install/install.py +++ b/install/install.py @@ -13,6 +13,7 @@ import string import re import platform +import shlex jms_dir = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) sys.path.append(jms_dir) @@ -23,7 +24,7 @@ def bash(cmd): run a bash shell command 执行bash命令 """ - return subprocess.call(cmd, shell=True) + return shlex.os.system(cmd) def valid_ip(ip): @@ -84,14 +85,18 @@ class PreSetup(object): @property def _is_redhat(self): - if self.dist == "centos" or self.dist == "redhat": + if self.dist == "centos" or self.dist == "redhat" or self.dist == "federa": return True @property def _is_ubuntu(self): - if self.dist == "ubuntu": + if self.dist == "ubuntu" or self.dist == "debain": return True + def check_platform(self): + if self._is_redhat or self._is_ubuntu: + raise ValueError(u"支持的平台: CentOS, RedHat, Fedare, Debain, Ubuntu, 暂不支持其他平台安装.") + def write_conf(self, conf_file=os.path.join(jms_dir, 'jumpserver.conf')): color_print('开始写入配置文件', 'green') conf = ConfigParser.ConfigParser() @@ -128,6 +133,7 @@ class PreSetup(object): bash('echo mysql-server mysql-server/root_password select '' | debconf-set-selections') bash('echo mysql-server mysql-server/root_password_again select '' | debconf-set-selections') bash('apt-get -y install mysql-server') + bash('service mysql start') bash('mysql -e "create database %s default charset=utf8"' % self.db) bash('mysql -e "grant all on %s.* to \'%s\'@\'%s\' identified by \'%s\'"' % (self.db, self.db_user, diff --git a/install/next.py b/install/next.py index 49d62db25..9c3250714 100755 --- a/install/next.py +++ b/install/next.py @@ -5,7 +5,7 @@ import sys import os import django from django.core.management import execute_from_command_line -import shutil +import shlex import urllib import socket import subprocess @@ -77,8 +77,8 @@ class Setup(object): user.delete() db_add_user(username=self.admin_user, password=self.admin_pass, role='SU', name='admin', groups='', admin_groups='', email='admin@jumpserver.org', uuid='MayBeYouAreTheFirstUser', is_active=True) - cmd = 'useradd %s' % self.admin_user - subprocess.call(cmd, shell=True) + cmd = 'id %s 2> /dev/null 1> /dev/null || useradd %s' % (self.admin_user, self.admin_user) + shlex.os.system(cmd) @staticmethod def _chmod_file(): @@ -93,7 +93,8 @@ class Setup(object): @staticmethod def _run_service(): - os.system('sh %s start' % os.path.join(jms_dir, 'service.sh')) + cmd = 'bash %s start' % os.path.join(jms_dir, 'service.sh') + shlex.os.system(cmd) print color_print('安装成功,请访问web, 祝你使用愉快。\n请访问 https://github.com/jumpserver/jumpserver 查看文档', 'green')