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
pull/98/head
yumaojun 2016-02-27 12:01:44 +08:00
parent 8aec0c1ac7
commit 37e0f80fb8
2 changed files with 14 additions and 7 deletions

View File

@ -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,

View File

@ -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')