Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Fabfile to:
- # - update the remote system(s)
- # - download and install an application
- from fabric.api import *
- env.hosts = [
- 'IP ADDRESS HERE!',
- # 'ip.add.rr.ess
- # 'server2.domain.tld',
- ]
- # Set the username
- env.user = "root"
- # Set the password [NOT RECOMMENDED]
- env.password = "passwd"
- def install_ubuntu_packages():
- """
- Install mosquitto, redis, and postgres
- """
- run("apt-get update")
- run("apt-get upgrade")
- run("apt-get install mosquitto")
- run("apt-get install redis-server")
- run("apt-get install postgresql")
- def add_system_users():
- """
- Add system users for all the server functions
- """
- run("useradd -M -r -s /bin/false gatewaybridge")
- run("useradd -M -r -s /bin/false loraserver")
- run("useradd -M -r -s /bin/false appserver")
- def create_database_with_user():
- """
- Add database user as owner to a newly created database
- """
- ### Add Postgres Database
- # create postgress user with password
- # create postgres database with owner
- pass
- def download_and_unpack():
- # LoRa Gateway Bridge
- run("wget https://github.com/brocaar/lora-gateway-bridge/releases/download/VERSION/lora_gateway_bridge_VERSION_linux_amd64.tar.gz")
- run("tar zxf lora_gateway_bridge_VERSION_linux_amd64.tar.gz")
- run("mkdir -p /opt/lora-gateway-bridge/bin")
- run("mv loraserver /opt/lora-gateway-bridge/bin")
- # LoRa Network Server
- run("wget https://github.com/brocaar/loraserver/releases/download/VERSION/loraserver_VERSION_linux_amd64.tar.gz")
- run("tar zxf loraserver_VERSION_linux_amd64.tar.gz")
- run("mkdir -p /opt/loraserver/bin")
- run("mv loraserver /opt/loraserver/bin")
- # LoRa App Server
- run("wget https://github.com/brocaar/lora-app-server/releases/download/VERSION/lora_app_server_VERSION_linux_amd64.tar.gz")
- run("tar zxf lora_app_server_VERSION_linux_amd64.tar.gz")
- run("mkdir -p /opt/lora-app-server/bin")
- run("mv lora-app-server /opt/lora-app-server/bin")
- def create_self_signed_certificate():
- ### TLS self signed certificate
- pass
- def system_daemon_setup():
- """
- [Unit]
- Description=lora-gateway-bridge
- After=mosquitto.service
- [Service]
- User=gatewaybridge
- Group=gatewaybridge
- ExecStart=/opt/lora-gateway-bridge/bin/lora-gateway-bridge
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
- """
- ("/etc/systemd/system/lora-gateway-bridge.service")
- """
- [Unit]
- Description=loraserver
- After=mosquitto.service
- [Service]
- User=loraserver
- Group=loraserver
- ExecStart=/opt/loraserver/bin/loraserver
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
- """
- ("/etc/systemd/system/loraserver.service")
- """
- [Unit]
- Description=lora-app-server
- After=mosquitto.service postgresql.service
- [Service]
- User=appserver
- Group=appserver
- ExecStart=/opt/lora-app-server/bin/lora-app-server
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
- """
- ("/etc/systemd/system/lora-app-server.service")
- def service_config_file():
- run("mkdir /etc/systemd/system/lora-gateway-bridge.service.d")
- """
- [Service]
- Environment="SETTING_A=value_a"
- Environment="SETTING_B=value_b"
- """
- run("mkdir /etc/systemd/system/loraserver.service.d")
- """
- [Service]
- Environment="NET_ID=010203"
- Environment="BAND=EU_863_870"
- Environment="BIND=127.0.0.1:8000"
- Environment="REDIS_URL=redis://localhost:6379"
- Environment="GW_MQTT_SERVER=tcp://localhost:1883"
- Environment="AS_SERVER=127.0.0.1:8001"
- """
- run("mkdir /etc/systemd/system/lora-app-server.service.d")
- """
- [Service]
- Environment="BIND=127.0.0.1:8001"
- Environment="HTTP_BIND=0.0.0.0:8080"
- Environment="NS_SERVER=127.0.0.1:8000"
- Environment="HTTP_TLS_CERT=/opt/lora-app-server/certs/http.pem"
- Environment="HTTP_TLS_KEY=/opt/lora-app-server/certs/http-key.pem"
- Environment="DB_AUTOMIGRATE=True"
- Environment="MIGRATE_NODE_SESSIONS=True"
- Environment="REDIS_URL=redis://localhost:6379"
- Environment="POSTGRES_DSN=postgres://loraserver:dbpassword@localhost/loraserver?sslmode=disable"
- """
- def restart_all_service():
- run("systemctl daemon-reload")
- run("systemctl restart lora-gateway-bridge")
- run("systemctl restart loraserver")
- run("systemctl restart lora-app-server")
- ### Service log check
- # For Gateway
- # For Lora Server
- # For Lora App Serv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement