-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud.sh
More file actions
98 lines (86 loc) · 2.61 KB
/
Copy pathcloud.sh
File metadata and controls
98 lines (86 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
#
# cloud.sh
# Main entry point & argument parser for the Local Micro-Cloud &
# Monitoring Engine.
set -euo pipefail
# Resolve the directory this script lives in, regardless of the caller's
# current working directory, so sourced libraries and config always
# resolve correctly.
APP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
source "${APP_DIR}/lib/core.sh"
source "${APP_DIR}/config/global.conf"
source "${APP_DIR}/lib/provisioner.sh"
source "${APP_DIR}/lib/monitor.sh"
source "${APP_DIR}/lib/notifier.sh"
# Path to the text-based state database. Provisioner functions read/write
# this file directly.
STATUS_DB="${APP_DIR}/storage/status.db"
usage() {
cat <<EOF
Usage: ./cloud.sh <command> [options]
Commands:
deploy --name <name> --cpu <limit> --mem <limit> [--stress] Deploy a service
list List registered services
clear Clear all service records
monitor Continuously monitor running services
EOF
}
main() {
local command="${1:-}"
case "$command" in
deploy)
shift
local name=""
local cpu=""
local mem=""
local stress=""
while [[ $# -gt 0 ]]; do
case "$1" in
--name)
name="${2:-}"
shift 2
;;
--cpu)
cpu="${2:-}"
shift 2
;;
--mem)
mem="${2:-}"
shift 2
;;
--stress)
stress="stress"
shift 1
;;
*)
log "ERROR" "Unknown deploy option: $1"
usage
exit 1
;;
esac
done
if [[ -z "$name" || -z "$cpu" || -z "$mem" ]]; then
log "ERROR" "deploy requires --name, --cpu, and --mem"
usage
exit 1
fi
db_add_service "$name" "$cpu" "$mem" "$stress"
;;
list)
db_list_services
;;
clear)
db_clear_services
;;
monitor)
run_monitoring_loop
;;
*)
log "ERROR" "Unknown command: ${command}"
usage
exit 1
;;
esac
}
main "$@"