a
This commit is contained in:
		
					parent
					
						
							
								d3d77fdccf
							
						
					
				
			
			
				commit
				
					
						1259216e86
					
				
			
		
					 2 changed files with 47 additions and 26 deletions
				
			
		
							
								
								
									
										39
									
								
								_not_working_etcd.sh
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								_not_working_etcd.sh
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,39 @@
 | 
				
			||||||
 | 
					#/bin/sh
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ $# -lt 2 ]; then
 | 
				
			||||||
 | 
					    echo "Insufficient Args"
 | 
				
			||||||
 | 
					    echo "Please pass IPv6 address like [2a0a:e5c0:0:2:0:b3ff:fe39:7994] and password of root"
 | 
				
			||||||
 | 
					    exit 1
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Enable Alpine (3.10 + Edge) Repos
 | 
				
			||||||
 | 
					cat > /etc/apk/repositories << EOF
 | 
				
			||||||
 | 
					http://dl-cdn.alpinelinux.org/alpine/v3.10/main
 | 
				
			||||||
 | 
					http://dl-cdn.alpinelinux.org/alpine/v3.10/community
 | 
				
			||||||
 | 
					http://dl-cdn.alpinelinux.org/alpine/edge/main
 | 
				
			||||||
 | 
					http://dl-cdn.alpinelinux.org/alpine/edge/community
 | 
				
			||||||
 | 
					http://dl-cdn.alpinelinux.org/alpine/edge/testing
 | 
				
			||||||
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Update Package List and Upgrade System
 | 
				
			||||||
 | 
					apk update
 | 
				
			||||||
 | 
					apk upgrade
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					apk add etcd etcd-ctl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sed -i -e "s/localhost/$1/g" /etc/etcd/conf.yml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Should be made better
 | 
				
			||||||
 | 
					sed -i -e "s/initial-cluster:/initial-cluster: http:\/\/$1:2380/g" /etc/etcd/conf.yml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					echo 'alias etcdctl="ETCDCTL_API=3 etcdctl"' >> ~/.bashrc
 | 
				
			||||||
 | 
					source ~/.bashrc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					service etcd start
 | 
				
			||||||
 | 
					rc-update add etcd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					etcdctl --endpoints http://$1:2379 user add root:$2
 | 
				
			||||||
 | 
					etcdctl --endpoints http://$1:2379 user grant root --roles root
 | 
				
			||||||
 | 
					etcdctl --endpoints http://$1:2379 auth enable
 | 
				
			||||||
							
								
								
									
										34
									
								
								app/api.py
									
										
									
									
									
								
							
							
						
						
									
										34
									
								
								app/api.py
									
										
									
									
									
								
							| 
						 | 
					@ -24,40 +24,20 @@ def api():
 | 
				
			||||||
@click.option("--auth_seed", required=True)
 | 
					@click.option("--auth_seed", required=True)
 | 
				
			||||||
@click.option("--auth_realm", required=True)
 | 
					@click.option("--auth_realm", required=True)
 | 
				
			||||||
@click.option("--realm_allowed", multiple=True, required=True)
 | 
					@click.option("--realm_allowed", multiple=True, required=True)
 | 
				
			||||||
 | 
					@click.option("--etcd_url", required=True)
 | 
				
			||||||
 | 
					@click.option("--etcd_password", required=True)
 | 
				
			||||||
@click.option(
 | 
					@click.option(
 | 
				
			||||||
    "--otp_server",
 | 
					    "--otp_server",
 | 
				
			||||||
    default="https://otp.ungleich.ch/ungleichotp/",
 | 
					    default="https://otp.ungleich.ch/ungleichotp/",
 | 
				
			||||||
    help="URL of ungleich OTP server",
 | 
					    help="URL of ungleich OTP server",
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
def setup(path, auth_name, auth_seed, auth_realm, realm_allowed, otp_server):
 | 
					def setup(path, auth_name, auth_seed, auth_realm,
 | 
				
			||||||
 | 
					          realm_allowed, otp_server, etcd_url,
 | 
				
			||||||
 | 
					          etcd_password):
 | 
				
			||||||
    os.chdir(path)
 | 
					    os.chdir(path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Install etcd
 | 
					 | 
				
			||||||
    op = PackageManagementOperation.install("etcd")
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    # Add --pidfile argument to supervise daemon
 | 
					 | 
				
			||||||
    op.add(
 | 
					 | 
				
			||||||
        subprocess.check_output,
 | 
					 | 
				
			||||||
        args=["sed", "-i", "-e",
 | 
					 | 
				
			||||||
              r"""'s/supervise_daemon_args="--chdir"""
 | 
					 | 
				
			||||||
              r""" $ETCD_DATA_DIR"/supervise_daemon_args="--chdir $ETCD_DATA_DIR"""
 | 
					 | 
				
			||||||
              r""" --pidfile /run/etcd.pid"/g' /etc/init.d/etcd"""])
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    # Change address of etcd
 | 
					 | 
				
			||||||
    op.add(
 | 
					 | 
				
			||||||
        subprocess.check_output,
 | 
					 | 
				
			||||||
        args=["sed", "-i", "-e",
 | 
					 | 
				
			||||||
              r""""s/localhost/[2a0a:e5c0:0:2:0:b3ff:fe39:7994]/g" /etc/etcd/conf.yml'"""])
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    # Start and Enable etcd service
 | 
					 | 
				
			||||||
    op.add(subprocess.check_output,
 | 
					 | 
				
			||||||
           args="service etcd start; rc-update add etcd".split())
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Git Operation Depends on success of previous operation i.e PackageManagementOperation
 | 
					    # Git Operation Depends on success of previous operation i.e PackageManagementOperation
 | 
				
			||||||
    op.add(
 | 
					    op = GitOperation.clone(url="https://code.ungleich.ch/ungleich-public/ucloud-api.git")
 | 
				
			||||||
        GitOperation.clone,
 | 
					 | 
				
			||||||
        url="https://code.ungleich.ch/ungleich-public/ucloud-api.git",
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    content = (
 | 
					    content = (
 | 
				
			||||||
        f"AUTH_NAME={auth_name}\n"
 | 
					        f"AUTH_NAME={auth_name}\n"
 | 
				
			||||||
| 
						 | 
					@ -65,6 +45,8 @@ def setup(path, auth_name, auth_seed, auth_realm, realm_allowed, otp_server):
 | 
				
			||||||
        f"AUTH_REALM={auth_seed}\n"
 | 
					        f"AUTH_REALM={auth_seed}\n"
 | 
				
			||||||
        f"REALM_ALLOWED={list(realm_allowed)}\n"
 | 
					        f"REALM_ALLOWED={list(realm_allowed)}\n"
 | 
				
			||||||
        f"OTP_SERVER={otp_server}\n"
 | 
					        f"OTP_SERVER={otp_server}\n"
 | 
				
			||||||
 | 
					        f"ETCD_URL={etcd_url}\n"
 | 
				
			||||||
 | 
					        f"ETCD_PASSWORD={etcd_password}\n"
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # FileOperation depends on success of previos operation i.e GitOperation.clone
 | 
					    # FileOperation depends on success of previos operation i.e GitOperation.clone
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue