2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-23 15:08:24 +00:00

auto update and sudoers

This commit is contained in:
Pratik Vyas 2014-07-11 09:59:57 +05:30
parent a395b15537
commit e04f548389
2 changed files with 37 additions and 10 deletions

View File

@ -1,8 +1,11 @@
import click import click
from .utils import init as _init from .utils import init as _init
from .utils import setup_env as _setup_env from .utils import setup_env as _setup_env
from .utils import new_site as _new_site from .utils import new_site as _new_site
from .utils import build_assets, patch_sites, get_sites_dir, get_bench_dir, get_frappe, exec_cmd from .utils import setup_backups as _setup_backups
from .utils import setup_auto_update as _setup_auto_update
from .utils import setup_sudoers as _setup_sudoers
from .utils import build_assets, patch_sites, exec_cmd, update_bench
from .app import get_app as _get_app from .app import get_app as _get_app
from .app import new_app as _new_app from .app import new_app as _new_app
from .app import pull_all_apps from .app import pull_all_apps
@ -39,15 +42,22 @@ def new_site(site):
@click.option('--pull', flag_value=True, type=bool) @click.option('--pull', flag_value=True, type=bool)
@click.option('--patch',flag_value=True, type=bool) @click.option('--patch',flag_value=True, type=bool)
@click.option('--build',flag_value=True, type=bool) @click.option('--build',flag_value=True, type=bool)
@click.option('--bench',flag_value=True, type=bool)
def update(pull=False, patch=False, build=False): def update(pull=False, patch=False, build=False):
if not (pull or patch or build): if not (pull or patch or build or bench):
pull, patch, build = True, True, True pull, patch, build, bench = True, True, True, True
if pull: if pull:
pull_all_apps() pull_all_apps()
if patch: if patch:
patch_sites() patch_sites()
if build: if build:
build_assets() build_assets()
if bench:
update_bench()
@click.command('restart')
def restart():
exec_cmd("sudo supervisorctl restart frappe:")
## Setup ## Setup
@click.group() @click.group()
@ -56,7 +66,7 @@ def setup():
@click.command('sudoers') @click.command('sudoers')
def setup_sudoers(): def setup_sudoers():
pass _setup_sudoers()
@click.command('nginx') @click.command('nginx')
def setup_nginx(): def setup_nginx():
@ -68,13 +78,11 @@ def setup_supervisor():
@click.command('auto-update') @click.command('auto-update')
def setup_auto_update(): def setup_auto_update():
exec_cmd('echo \"`crontab -l`\" | uniq | sed -e \"a0 10 * * * cd {bench_dir} && {bench} update\" | grep -v "^$" | uniq | crontab'.format(bench_dir=get_bench_dir(), _setup_auto_update()
bench=os.path.join(get_bench_dir(), 'env', 'bin', 'bench')))
@click.command('backups') @click.command('backups')
def setup_backups(): def setup_backups():
exec_cmd('echo \"`crontab -l`\" | uniq | sed -e \"a0 */6 * * * cd {sites_dir} && {frappe} --backup all\" | grep -v "^$" | uniq | crontab'.format(sites_dir=get_sites_dir(), _setup_backups()
frappe=get_frappe()))
@click.command('dnsmasq') @click.command('dnsmasq')
def setup_dnsmasq(): def setup_dnsmasq():
@ -83,7 +91,6 @@ def setup_dnsmasq():
@click.command('env') @click.command('env')
def setup_env(): def setup_env():
_setup_env() _setup_env()
pass
setup.add_command(setup_nginx) setup.add_command(setup_nginx)
setup.add_command(setup_sudoers) setup.add_command(setup_sudoers)
@ -101,3 +108,4 @@ bench.add_command(new_app)
bench.add_command(new_site) bench.add_command(new_site)
bench.add_command(setup) bench.add_command(setup)
bench.add_command(update) bench.add_command(update)
bench.add_command(restart)

View File

@ -1,6 +1,7 @@
import os import os
import sys import sys
import subprocess import subprocess
import getpass
def get_frappe(bench='.'): def get_frappe(bench='.'):
frappe = os.path.abspath(os.path.join(bench, 'env', 'bin', 'frappe')) frappe = os.path.abspath(os.path.join(bench, 'env', 'bin', 'frappe'))
@ -51,3 +52,21 @@ def get_sites_dir(bench='.'):
def get_bench_dir(bench='.'): def get_bench_dir(bench='.'):
return os.path.abspath(bench) return os.path.abspath(bench)
def setup_auto_update():
exec_cmd('echo \"`crontab -l`\" | uniq | sed -e \"a0 10 * * * cd {bench_dir} && {bench} update\" | grep -v "^$" | uniq | crontab'.format(bench_dir=get_bench_dir(),
bench=os.path.join(get_bench_dir(), 'env', 'bin', 'bench')))
def setup_backups():
exec_cmd('echo \"`crontab -l`\" | uniq | sed -e \"a0 */6 * * * cd {sites_dir} && {frappe} --backup all\" | grep -v "^$" | uniq | crontab'.format(sites_dir=get_sites_dir(),
frappe=get_frappe()))
def update_bench():
cwd = os.path.dirname(os.path.abspath(__file__))
exec_cmd("git pull", cwd=cwd)
def setup_sudoers():
with open('/etc/sudoers.d/frappe', 'w') as f:
f.write("{user} ALL=(ALL) NOPASSWD: {supervisorctl} restart frappe\:\n".format(
user=getpass.getuser()),
supervisorctl=subprocess.check_output('which supervisorctl', shell=True).strip())