mirror of
https://github.com/frappe/bench.git
synced 2025-02-03 19:38:24 +00:00
check for roor, change dir and change user on init
This commit is contained in:
parent
6476c7eb72
commit
585d041b19
31
bench/cli.py
31
bench/cli.py
@ -21,14 +21,39 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
import copy
|
import copy
|
||||||
|
import pwd
|
||||||
|
|
||||||
logger = logging.getLogger('bench')
|
logger = logging.getLogger('bench')
|
||||||
|
|
||||||
def cli():
|
def cli():
|
||||||
|
check_uid()
|
||||||
|
change_dir()
|
||||||
|
change_uid()
|
||||||
if len(sys.argv) > 2 and sys.argv[1] == "frappe":
|
if len(sys.argv) > 2 and sys.argv[1] == "frappe":
|
||||||
return frappe()
|
return frappe()
|
||||||
return bench()
|
return bench()
|
||||||
|
|
||||||
|
def check_uid():
|
||||||
|
if len(sys.argv) > 3 and sys.argv[2] in ('production', 'sudoers') and not is_root():
|
||||||
|
print 'superuser privileges required for this command'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def change_uid():
|
||||||
|
if is_root():
|
||||||
|
frappe_user = get_config().get('frappe_user')
|
||||||
|
if frappe_user:
|
||||||
|
os.setuid(pwd.getpwnam(frappe_user).pw_uid)
|
||||||
|
else:
|
||||||
|
print 'You should not run this command as root'
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
def change_dir():
|
||||||
|
dir_path_file = '/etc/frappe_bench_dir'
|
||||||
|
if os.path.exists(dir_path_file):
|
||||||
|
with open(dir_path_file) as f:
|
||||||
|
dir_path = f.read().strip()
|
||||||
|
os.chdir(dir_path)
|
||||||
|
|
||||||
def frappe(bench='.'):
|
def frappe(bench='.'):
|
||||||
f = get_frappe(bench=bench)
|
f = get_frappe(bench=bench)
|
||||||
os.chdir(os.path.join(bench, 'sites'))
|
os.chdir(os.path.join(bench, 'sites'))
|
||||||
@ -215,9 +240,6 @@ def setup():
|
|||||||
@click.argument('user')
|
@click.argument('user')
|
||||||
def setup_sudoers(user):
|
def setup_sudoers(user):
|
||||||
"Add commands to sudoers list for execution without password"
|
"Add commands to sudoers list for execution without password"
|
||||||
if not is_root():
|
|
||||||
print 'superuser privileges required for this command'
|
|
||||||
sys.exit(1)
|
|
||||||
_setup_sudoers(user)
|
_setup_sudoers(user)
|
||||||
|
|
||||||
@click.command('nginx')
|
@click.command('nginx')
|
||||||
@ -233,9 +255,6 @@ def setup_supervisor():
|
|||||||
@click.command('production')
|
@click.command('production')
|
||||||
def setup_production():
|
def setup_production():
|
||||||
"setup bench for production"
|
"setup bench for production"
|
||||||
if not is_root():
|
|
||||||
print 'superuser privileges required for this command'
|
|
||||||
sys.exit(1)
|
|
||||||
_setup_production()
|
_setup_production()
|
||||||
|
|
||||||
@click.command('auto-update')
|
@click.command('auto-update')
|
||||||
|
@ -14,6 +14,7 @@ default_config = {
|
|||||||
'serve_default_site': True,
|
'serve_default_site': True,
|
||||||
'rebase_on_pull': False,
|
'rebase_on_pull': False,
|
||||||
'update_bench_on_update': True,
|
'update_bench_on_update': True,
|
||||||
|
'frappe_user': getpass.getuser(),
|
||||||
'shallow_clone': True
|
'shallow_clone': True
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user