Last active
October 25, 2019 23:57
-
-
Save uneasyguy/fc3c2d0ef1cf52540a68da000f86d751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from subprocess import check_output | |
from crontab import CronTab | |
import os | |
def replace_text(filename,find,replace): | |
with open(filename, 'r') as file : | |
filedata = file.read() | |
filedata = filedata.replace(find, replace) | |
with open(filename, 'w') as file: | |
file.write(filedata) | |
def sudo_move_file(original,new_location): | |
move_command = f'sudo mv {original} {new_location}' | |
os.system(move_command) | |
return | |
def open_app_port(): | |
hostname = check_output(['hostname']).decode().strip() | |
command = f'gcloud compute firewall-rules create "merge-app-port" --allow tcp:4000 --source-tags="{hostname}" --source-ranges="0.0.0.0/0" --description="Open port for merge app"' | |
os.system(command) | |
return | |
def main(): | |
username = check_output(['whoami']).decode().strip() | |
find_text = '****USERNAME GOES HERE****' | |
replace_text('rc.local',find_text,username) | |
replace_text('merge_app.py',find_text,username) | |
cron = CronTab(user=True) | |
new_cron_job = cron.new(command='00 12 * * * ~/forever_all.sh >/dev/null 2>&1', comment='Restart all forever processes daily at 12:00pm UTC') | |
sudo_move_file('rc.local','/etc/') | |
sudo_move_file('rc-local.service','/etc/systemd/system/') | |
ownership_command = f'chmod 777 /home/{username}/*' | |
change_file_ownership = os.system(ownership_command) | |
open_app_port() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment