mirror of
https://github.com/frappe/bench.git
synced 2025-01-10 09:02:10 +00:00
Added command to change SSH port
This commit is contained in:
parent
786b997dc3
commit
2e9cfa5d02
@ -47,7 +47,7 @@ def check_uid():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def cmd_requires_root():
|
def cmd_requires_root():
|
||||||
if len(sys.argv) > 2 and sys.argv[2] in ('production', 'sudoers', 'lets-encrypt', 'fonts', 'reload-nginx', 'firewall'):
|
if len(sys.argv) > 2 and sys.argv[2] in ('production', 'sudoers', 'lets-encrypt', 'fonts', 'reload-nginx', 'firewall', 'ssh-port'):
|
||||||
return True
|
return True
|
||||||
if len(sys.argv) >= 2 and sys.argv[1] in ('patch', 'renew-lets-encrypt', 'disable-production'):
|
if len(sys.argv) >= 2 and sys.argv[1] in ('patch', 'renew-lets-encrypt', 'disable-production'):
|
||||||
return True
|
return True
|
||||||
|
@ -84,6 +84,17 @@ def setup_firewall():
|
|||||||
abort=True)
|
abort=True)
|
||||||
run_playbook('production/setup_firewall.yml')
|
run_playbook('production/setup_firewall.yml')
|
||||||
|
|
||||||
|
@click.command('ssh-port')
|
||||||
|
@click.argument('port')
|
||||||
|
def set_ssh_port(port):
|
||||||
|
"Setup firewall"
|
||||||
|
from bench.utils import run_playbook
|
||||||
|
click.confirm('This will change your SSH Port to {}\n'
|
||||||
|
'Do you want to continue?'.format(port),
|
||||||
|
abort=True)
|
||||||
|
run_playbook('production/change_ssh_port.yml', {"ssh_port": port})
|
||||||
|
|
||||||
|
|
||||||
@click.command('lets-encrypt')
|
@click.command('lets-encrypt')
|
||||||
@click.argument('site')
|
@click.argument('site')
|
||||||
@click.option('--custom-domain')
|
@click.option('--custom-domain')
|
||||||
@ -180,3 +191,4 @@ setup.add_command(add_domain)
|
|||||||
setup.add_command(remove_domain)
|
setup.add_command(remove_domain)
|
||||||
setup.add_command(sync_domains)
|
setup.add_command(sync_domains)
|
||||||
setup.add_command(setup_firewall)
|
setup.add_command(setup_firewall)
|
||||||
|
setup.add_command(set_ssh_port)
|
||||||
|
@ -687,9 +687,11 @@ def set_git_remote_url(git_url, bench_path='.'):
|
|||||||
if os.path.exists(os.path.join(app_dir, '.git')):
|
if os.path.exists(os.path.join(app_dir, '.git')):
|
||||||
exec_cmd("git remote set-url upstream {}".format(git_url), cwd=app_dir)
|
exec_cmd("git remote set-url upstream {}".format(git_url), cwd=app_dir)
|
||||||
|
|
||||||
def run_playbook(playbook_name):
|
def run_playbook(playbook_name, extra_vars=None):
|
||||||
if not find_executable('ansible'):
|
if not find_executable('ansible'):
|
||||||
print "Ansible is needed to run this command, please install it using 'pip install ansible'"
|
print "Ansible is needed to run this command, please install it using 'pip install ansible'"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
args = ['ansible-playbook', '-c', 'local', playbook_name]
|
args = ['ansible-playbook', '-c', 'local', playbook_name]
|
||||||
|
if extra_vars:
|
||||||
|
args.extend(['--extra-vars=' + json.dumps(extra_vars)])
|
||||||
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))
|
subprocess.check_call(args, cwd=os.path.join(os.path.dirname(bench.__path__[0]), 'playbooks'))
|
||||||
|
14
playbooks/production/change_ssh_port.yml
Executable file
14
playbooks/production/change_ssh_port.yml
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
- name: Change ssh port
|
||||||
|
gather_facts: false
|
||||||
|
hosts: localhost
|
||||||
|
user: root
|
||||||
|
tasks:
|
||||||
|
- name: change sshd config
|
||||||
|
lineinfile: >
|
||||||
|
dest=/etc/ssh/sshd_config
|
||||||
|
regexp="^Port"
|
||||||
|
line="Port {{ ssh_port }}"
|
||||||
|
state=present
|
||||||
|
|
||||||
|
- name: restart ssh
|
||||||
|
service: name=sshd state=reloaded
|
Loading…
Reference in New Issue
Block a user