[
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2025-01-02 15:31:03.095292",
  "name": "Create Server",
  "steps": [
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.provision()\n",
    "step_name": "Create Server",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Running\", False)\n",
    "step_name": "Wait for Server to start",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nserver.ping_ansible()\n\nplays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Ping Server\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", False)\n",
    "step_name": "Wait for Server to be accessible",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nserver.update_tls_certificate()",
    "step_name": "Update TLS Certificate",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Setup TLS Certificates\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status in (\"Success\", \"Failure\"), False)",
    "step_name": "Wait for TLS Certificate to be updated",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nserver.wait_for_cloud_init()",
    "step_name": "Check Cloud Init status",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Wait for Cloud Init to finish\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status in (\"Success\", \"Failure\"), False)",
    "step_name": "Wait for Cloud Init to finish",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nserver.update_agent_ansible()",
    "step_name": "Update Agent Ansible",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Update Agent\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status in (\"Success\", \"Failure\"), False)",
    "step_name": "Wait for Agent to be updated",
    "wait_until_true": 1
   },
   {
    "script": "if pg.server_type == \"Database Server\":\n    server = jingrow.get_pg(\"Database Server\", pg.server)\n    server.upgrade_mariadb()",
    "step_name": "Upgrade MariaDB",
    "wait_until_true": 0
   },
   {
    "script": "if pg.server_type == \"Database Server\":\n    plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Upgrade MariaDB\"}, [\"status\"], order_by=\"creation desc\", limit=1)\n    result = (plays and plays[0].status == \"Success\", plays and plays[0].status == \"Failure\")\nelse:\n    result = (True,)",
    "step_name": "Wait for MariaDB Upgrade to Complete",
    "wait_until_true": 1
   },
   {
    "script": "if pg.server_type == \"Database Server\":\n    default_variables = jingrow.get_all(\"MariaDB Variable\", {\"set_on_new_servers\":1}, pluck=\"name\")\n    for var_name in default_variables:\n        var = jingrow.get_pg(\"MariaDB Variable\", var_name)\n        var.set_on_server(pg.server)\n\nserver = jingrow.get_pg(pg.server_type, pg.server)\nserver.set_swappiness()\nserver.add_glass_file()\nserver.update_filebeat()\n\nif pg.server_type == \"Server\":\n    server.setup_mysqldump()\n    server.install_earlyoom()\n\nserver.validate_mounts()\nserver.save()",
    "step_name": "Set additional config",
    "wait_until_true": 0
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2025-01-02 15:33:27.252601",
  "name": "Resize Server",
  "steps": [
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.stop()",
    "step_name": "Stop Virtual Machine",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Stopped\", False)",
    "step_name": "Wait for Virtual Machine to Stop",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.resize(arguments.machine_type)",
    "step_name": "Resize Virtual Machine",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\ntry:\n    machine.start()\n    result = (True, False)\nexcept:\n    result = (False, False)",
    "step_name": "Start Virtual Machine",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Running\", False)",
    "step_name": "Wait for Virtual Machine to Start",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nserver.ping_ansible()\n\nplays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Ping Server\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", False)\n",
    "step_name": "Wait for Server to be accessible",
    "wait_until_true": 1
   },
   {
    "script": "if pg.server_type == \"Database Server\":\n    server = jingrow.get_pg(pg.server_type, pg.server)\n    server.adjust_memory_config()\nelif pg.server_type == \"Server\":\n    server = jingrow.get_pg(pg.server_type, pg.server)\n    server.auto_scale_workers()",
    "step_name": "Set additional config",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\n\nserver = jingrow.get_pg(pg.server_type, pg.server)\nif server.plan:\n    plan_disk_size = jingrow.db.get_value(\"Server Plan\", server.plan, \"disk\")\n    if plan_disk_size and plan_disk_size > machine.disk_size:\n        try:\n            server.increase_disk_size(increment=plan_disk_size - machine.disk_size)\n        except:\n            pass",
    "step_name": "Increase Disk Size",
    "wait_until_true": 0
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2024-02-05 17:08:00.514456",
  "name": "Create Server Snapshot",
  "steps": [
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.stop()\n",
    "step_name": "Stop Virtual Machine",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Stopped\", False)",
    "step_name": "Wait for Virtual Machine to Stop",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\narguments.image = machine.create_image()",
    "step_name": "Create Snapshot",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\ntry:\n    machine.start()\n    result = (True, False)\nexcept:\n    result = (False, False)",
    "step_name": "Start Virtual Machine",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Running\", False)",
    "step_name": "Wait for Virtual Machine to Start",
    "wait_until_true": 1
   },
   {
    "script": "image = jingrow.get_pg(\"Virtual Machine Image\", arguments.image)\nimage.sync()\nresult = (image.status == \"Available\", False)",
    "step_name": "Wait for Snapshot to Complete",
    "wait_until_true": 1
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2022-11-01 14:35:52.936503",
  "name": "Archive Server",
  "steps": [
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.disable_termination_protection()",
    "step_name": "Disable Termination Protection",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.terminate()",
    "step_name": "Terminate Virtual Machine",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Terminated\", False)",
    "step_name": "Wait for Virtual Machine to Terminate",
    "wait_until_true": 1
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2024-01-05 13:40:21.038901",
  "name": "Upgrade MariaDB",
  "steps": [
   {
    "script": "server = jingrow.get_pg(\"Database Server\", pg.server)\nserver.stop_mariadb()",
    "step_name": "Stop MariaDB",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Stop MariaDB\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", False)\n",
    "step_name": "Wait for MariaDB to Stop",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.create_snapshots()\nsnapshot = jingrow.get_last_pg(\"Virtual Disk Snapshot\", {\"virtual_machine\": pg.virtual_machine})\nsnapshot.add_comment(text=\"Before MariaDB Upgrade\")",
    "step_name": "Create Server Snapshot",
    "wait_until_true": 0
   },
   {
    "script": "server = jingrow.get_pg(\"Database Server\", pg.server)\nserver.upgrade_mariadb()",
    "step_name": "Upgrade MariaDB",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Upgrade MariaDB\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", plays and plays[0].status == \"Failure\")\n",
    "step_name": "Wait for MariaDB Upgrade to Complete",
    "wait_until_true": 1
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2025-02-14 14:30:00.676187",
  "name": "Increase Disk Size",
  "steps": [
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nmountpoint = arguments.labels.get(\"mountpoint\")\nserver.calculated_increase_disk_size(mountpoint=mountpoint)",
    "step_name": "Increase Disk Size",
    "wait_until_true": 0
   },
   {
    "script": "if jingrow.db.get_value(pg.server_type, pg.server, \"provider\") == \"AWS EC2\":\n    plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Extend EC2 Volume\"}, [\"status\"], order_by=\"creation desc\", limit=1)\n    result = (plays and plays[0].status == \"Success\", plays and plays[0].status == \"Failure\")\nelse:\n    result = (True, False)",
    "step_name": "Wait for partition to resize (AWS)",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nif server.provider == \"OCI\":\n    machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\n    machine.sync()\n    result = (machine.status == \"Running\", False)\nelse:\n    result = (True, False)",
    "step_name": "Wait for server to start (OCI)",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nif server.provider == \"OCI\":\n    server.ping_ansible()\n\n    plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Ping Server\"}, [\"status\"], order_by=\"creation desc\", limit=1)\n    result = (plays and plays[0].status == \"Success\", False)\nelse:\n    result = (True, False)\n",
    "step_name": "Wait for server to be accessible (OCI)",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nif server.provider == \"OCI\":\n    server.add_glass_file()\nelse:\n    result = (True, False)\n    # handled for aws already in extend playbook",
    "step_name": "Add glass file back (OCI)",
    "wait_until_true": 0
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2024-05-27 11:29:41.787719",
  "name": "Prune Docker system",
  "steps": [
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\ntelegram = jingrow.get_pg(\"Jcloud Settings\").telegram(\"Information\")\ntelegram.send(f\"Pruning docker cache on [{server.name}]({jingrow.utils.get_url_to_form(server.pagetype, server.name)})\")\nserver.prune_docker_system()",
    "step_name": "Prune Docker system",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Prune Docker System\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", plays and plays[0].status == \"Failure\")\n",
    "step_name": "Wait for docker system prune",
    "wait_until_true": 1
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2024-06-18 16:03:25.166898",
  "name": "Increase Swap",
  "steps": [
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\ntelegram = jingrow.get_pg(\"Jcloud Settings\").telegram(\"Information\")\ntelegram.send(f\"Increasing swap on [{server.name}]({jingrow.utils.get_url_to_form(server.pagetype, server.name)})\")\nserver.increase_swap(4)",
    "step_name": "Add swap on server",
    "wait_until_true": 0
   },
   {
    "script": "plays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Increase Swap\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", plays and plays[0].status == \"Failure\")",
    "step_name": "Wait for swap to be added",
    "wait_until_true": 1
   }
  ]
 },
 {
  "pagestatus": 0,
  "pagetype": "Jcloud Job Type",
  "modified": "2024-12-06 10:59:08.032149",
  "name": "Stop and Start Server",
  "steps": [
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.stop()",
    "step_name": "Stop Virtual Machine",
    "wait_until_true": 0
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Stopped\", False)",
    "step_name": "Wait for Virtual Machine to Stop",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\ntry:\n    machine.start()\n    result = (True, False)\nexcept:\n    result = (False, False)",
    "step_name": "Start Virtual Machine",
    "wait_until_true": 1
   },
   {
    "script": "machine = jingrow.get_pg(\"Virtual Machine\", pg.virtual_machine)\nmachine.sync()\nresult = (machine.status == \"Running\", False)",
    "step_name": "Wait for Virtual Machine to Start",
    "wait_until_true": 1
   },
   {
    "script": "server = jingrow.get_pg(pg.server_type, pg.server)\nserver.ping_ansible()\n\nplays = jingrow.get_all(\"Ansible Play\", {\"server\": pg.server, \"play\": \"Ping Server\"}, [\"status\"], order_by=\"creation desc\", limit=1)\nresult = (plays and plays[0].status == \"Success\", False)\n",
    "step_name": "Wait for Server to be accessible",
    "wait_until_true": 1
   }
  ]
 }
]