Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import parseopt
- import shell
- import std/rdstdin
- import strformat
- import strutils, typetraits
- from os import fileExists
- proc writeHelp() =
- echo """
- Usage of builder:
- --help : show this help message
- -- single : Single Process
- -- seperate : Seperate service
- -- config : Config only
- """
- proc singleinstance() =
- if bool fileExists("/etc/redhat-release"):
- echo "Supported OS!"
- shell:
- sudo r"yum install -y yum-utils sudo -y"
- sudo r"yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo"
- sudo r"yum install -y clickhouse-server clickhouse-client -y"
- sudo r"mkdir -p /etc/clickhouse-keeper/"
- proc configonly() =
- echo "Creating /etc/clickhouse-server/config.d/custom.xml"
- echo "Creating ddlworker.xml"
- echo "Creating macros.xml"
- echo "Creating remote_servers.xml"
- echo "Creating keeper.xml"
- stdout.write "enter cluster id: "
- let clusterid = stdin.readline.parseBiggestUInt
- var ffqdn: string = readLineFromStdin("Enter first dns server:")
- var sfqdn: string = readLineFromStdin("Enter second dns server:")
- echo "Your cluster id is ", clusterid
- if clusterid == 1:
- "/etc/clickhouse-server/config.d/macros.xml".writefile(fmt"""<clickhouse>
- <distributed_ddl>
- <path>/clickhouse/task_queue/ddl</path>
- </distributed_ddl>
- <macros>
- <cluster>hepic</cluster>
- <shard>1</shard>
- <replica>{ffqdn}</replica>
- </macros>
- </clickhouse>
- """)
- "/etc/clickhouse-server/config.d/keeper.xml".writefile(fmt"""<?xml version="1.0"?>
- <clickhouse>
- <zookeeper>
- <node index="1">
- <host>{ffqdn}</host>
- <port>9181</port>
- </node>
- <node index="2">
- <host>{sfqdn}</host>
- <port>9181</port>
- </node>
- <session_timeout_ms>3000</session_timeout_ms>
- </zookeeper>
- </clickhouse>
- """)
- elif clusterid == 2:
- "/etc/clickhouse-server/config.d/macros.xml".writefile(fmt"""<clickhouse>
- <distributed_ddl>
- <path>/clickhouse/task_queue/ddl</path>
- </distributed_ddl>
- <macros>
- <cluster>hepic</cluster>
- <shard>1</shard>
- <replica>{sfqdn}</replica>
- </macros>
- </clickhouse>
- """)
- "/etc/clickhouse-server/config.d/keeper.xml".writefile(fmt"""<?xml version="1.0"?>
- <clickhouse>
- <zookeeper>
- <node index="1">
- <host>{ffqdn}</host>
- <port>9181</port>
- </node>
- <node index="2">
- <host>{sfqdn}</host>
- <port>9181</port>
- </node>
- <session_timeout_ms>3000</session_timeout_ms>
- </zookeeper>
- </clickhouse>
- """)
- "/etc/clickhouse-server/config.d/ddlworker.xml".writefile("""<?xml version="1.0"?>
- <clickhouse>
- <distributed_ddl>
- <path>/clickhouse/task_queue/ddl</path>
- </distributed_ddl>
- </clickhouse>
- """)
- "/etc/clickhouse-server/config.d/custom.xml".writefile("""<yandex>
- <listen_host>0.0.0.0</listen_host>
- <logger>
- <level>warning</level>
- <console>true</console>
- </logger>
- <query_thread_log remove="remove"/>
- <query_log remove="remove"/>
- <text_log remove="remove"/>
- <trace_log remove="remove"/>
- <metric_log remove="remove"/>
- <asynchronous_metric_log remove="remove"/>
- <!-- Update: Required for newer versions of Clickhouse -->
- <session_log remove="remove"/>
- <part_log remove="remove"/>
- <path>/var/lib/clickhouse/</path>
- <metadata_path>/var/lib/clickhouse/disks/blob_storage_disk/</metadata_path>
- <cache_path>/var/lib/clickhouse/disks/blob_storage_disk/cache/</cache_path>
- <tmp_path>/var/lib/clickhouse/tmp/</tmp_path>
- <user_files_path>/var/lib/clickhouse/user_files/</user_files_path>
- <path>/var/lib/clickhouse/access/</path>
- <format_schema_path>/var/lib/clickhouse/format_schemas/</format_schema_path>
- <max_table_size_to_drop>0</max_table_size_to_drop>
- <max_partition_size_to_drop>0</max_partition_size_to_drop>
- </yandex>""")
- proc cli*() =
- for kind, key, val in getopt():
- case kind
- of cmdLongOption, cmdShortOption:
- case key
- of "help", "h":
- writeHelp()
- quit()
- of "single", "s":
- singleinstance()
- quit()
- of "seperate", "se":
- quit()
- of "config", "co":
- configonly()
- quit()
- else:
- discard
- else:
- discard
- cli()
Add Comment
Please, Sign In to add comment