Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. # Fabfile to:
  2. # - update the remote system(s)
  3. # - download and install an application
  4.  
  5.  
  6. from fabric.api import *
  7.  
  8. env.hosts = [
  9. 'IP ADDRESS HERE!',
  10. # 'ip.add.rr.ess
  11. # 'server2.domain.tld',
  12. ]
  13.  
  14. # Set the username
  15. env.user = "root"
  16.  
  17. # Set the password [NOT RECOMMENDED]
  18. env.password = "passwd"
  19.  
  20. def install_ubuntu_packages():
  21. """
  22. Install mosquitto, redis, and postgres
  23. """
  24.  
  25. run("apt-get update")
  26. run("apt-get upgrade")
  27.  
  28. run("apt-get install mosquitto")
  29. run("apt-get install redis-server")
  30. run("apt-get install postgresql")
  31.  
  32.  
  33. def add_system_users():
  34. """
  35. Add system users for all the server functions
  36. """
  37.  
  38. run("useradd -M -r -s /bin/false gatewaybridge")
  39. run("useradd -M -r -s /bin/false loraserver")
  40. run("useradd -M -r -s /bin/false appserver")
  41.  
  42.  
  43.  
  44. def create_database_with_user():
  45. """
  46. Add database user as owner to a newly created database
  47. """
  48. ### Add Postgres Database
  49.  
  50. # create postgress user with password
  51. # create postgres database with owner
  52. pass
  53.  
  54.  
  55. def download_and_unpack():
  56.  
  57. # LoRa Gateway Bridge
  58. run("wget https://github.com/brocaar/lora-gateway-bridge/releases/download/VERSION/lora_gateway_bridge_VERSION_linux_amd64.tar.gz")
  59. run("tar zxf lora_gateway_bridge_VERSION_linux_amd64.tar.gz")
  60. run("mkdir -p /opt/lora-gateway-bridge/bin")
  61. run("mv loraserver /opt/lora-gateway-bridge/bin")
  62.  
  63. # LoRa Network Server
  64. run("wget https://github.com/brocaar/loraserver/releases/download/VERSION/loraserver_VERSION_linux_amd64.tar.gz")
  65. run("tar zxf loraserver_VERSION_linux_amd64.tar.gz")
  66. run("mkdir -p /opt/loraserver/bin")
  67. run("mv loraserver /opt/loraserver/bin")
  68.  
  69. # LoRa App Server
  70. run("wget https://github.com/brocaar/lora-app-server/releases/download/VERSION/lora_app_server_VERSION_linux_amd64.tar.gz")
  71. run("tar zxf lora_app_server_VERSION_linux_amd64.tar.gz")
  72. run("mkdir -p /opt/lora-app-server/bin")
  73. run("mv lora-app-server /opt/lora-app-server/bin")
  74.  
  75.  
  76.  
  77. def create_self_signed_certificate():
  78. ### TLS self signed certificate
  79. pass
  80.  
  81.  
  82. def system_daemon_setup():
  83.  
  84. """
  85. [Unit]
  86. Description=lora-gateway-bridge
  87. After=mosquitto.service
  88.  
  89. [Service]
  90. User=gatewaybridge
  91. Group=gatewaybridge
  92. ExecStart=/opt/lora-gateway-bridge/bin/lora-gateway-bridge
  93. Restart=on-failure
  94.  
  95. [Install]
  96. WantedBy=multi-user.target
  97. """
  98.  
  99. ("/etc/systemd/system/lora-gateway-bridge.service")
  100.  
  101. """
  102. [Unit]
  103. Description=loraserver
  104. After=mosquitto.service
  105.  
  106. [Service]
  107. User=loraserver
  108. Group=loraserver
  109. ExecStart=/opt/loraserver/bin/loraserver
  110. Restart=on-failure
  111.  
  112. [Install]
  113. WantedBy=multi-user.target
  114. """
  115. ("/etc/systemd/system/loraserver.service")
  116.  
  117. """
  118. [Unit]
  119. Description=lora-app-server
  120. After=mosquitto.service postgresql.service
  121.  
  122. [Service]
  123. User=appserver
  124. Group=appserver
  125. ExecStart=/opt/lora-app-server/bin/lora-app-server
  126. Restart=on-failure
  127.  
  128. [Install]
  129. WantedBy=multi-user.target
  130. """
  131. ("/etc/systemd/system/lora-app-server.service")
  132.  
  133. def service_config_file():
  134.  
  135. run("mkdir /etc/systemd/system/lora-gateway-bridge.service.d")
  136.  
  137. """
  138. [Service]
  139. Environment="SETTING_A=value_a"
  140. Environment="SETTING_B=value_b"
  141. """
  142.  
  143. run("mkdir /etc/systemd/system/loraserver.service.d")
  144.  
  145. """
  146. [Service]
  147. Environment="NET_ID=010203"
  148. Environment="BAND=EU_863_870"
  149. Environment="BIND=127.0.0.1:8000"
  150. Environment="REDIS_URL=redis://localhost:6379"
  151. Environment="GW_MQTT_SERVER=tcp://localhost:1883"
  152. Environment="AS_SERVER=127.0.0.1:8001"
  153. """
  154.  
  155. run("mkdir /etc/systemd/system/lora-app-server.service.d")
  156.  
  157. """
  158. [Service]
  159. Environment="BIND=127.0.0.1:8001"
  160. Environment="HTTP_BIND=0.0.0.0:8080"
  161. Environment="NS_SERVER=127.0.0.1:8000"
  162. Environment="HTTP_TLS_CERT=/opt/lora-app-server/certs/http.pem"
  163. Environment="HTTP_TLS_KEY=/opt/lora-app-server/certs/http-key.pem"
  164. Environment="DB_AUTOMIGRATE=True"
  165. Environment="MIGRATE_NODE_SESSIONS=True"
  166. Environment="REDIS_URL=redis://localhost:6379"
  167. Environment="POSTGRES_DSN=postgres://loraserver:dbpassword@localhost/loraserver?sslmode=disable"
  168. """
  169.  
  170.  
  171. def restart_all_service():
  172.  
  173. run("systemctl daemon-reload")
  174.  
  175. run("systemctl restart lora-gateway-bridge")
  176. run("systemctl restart loraserver")
  177. run("systemctl restart lora-app-server")
  178.  
  179.  
  180.  
  181. ### Service log check
  182.  
  183. # For Gateway
  184. # For Lora Server
  185. # For Lora App Serv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement