-
Notifications
You must be signed in to change notification settings - Fork 0
/
.studiorc
119 lines (91 loc) · 3.16 KB
/
.studiorc
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
hab pkg install chef/ci-studio-common >/dev/null
source "$(hab pkg path chef/ci-studio-common)/bin/studio-common"
# This removes the visual mode when select text with the mouse in vim.
echo "set mouse-=a" >> ~/.vimrc
install_if_missing core/curl curl
PORT=8080
SERVICE_NAME="notifications-service"
function htop() {
install_if_missing core/which which;
install_if_missing core/htop htop
TOOL_BIN=$(which htop 2>/dev/null);
eval $TOOL_BIN $@
}
function start() {
install_if_missing core/busybox-static netstat
netstat -an | grep $PORT | grep LISTEN >/dev/null 2>/dev/null
if [ $? == 0 ]; then
echo "already running";
return;
fi
build
start_sup
echo "starting $HAB_ORIGIN/$SERVICE_NAME"
hab svc load $HAB_ORIGIN/$SERVICE_NAME
wait_or_fail_for_port_to_listen $PORT
}
function rebuild() {
build
if [ $? != 0 ]; then
echo "build Faild";
return;
fi
hab svc unload $HAB_ORIGIN/$SERVICE_NAME
sleep 3
hab svc load $HAB_ORIGIN/$SERVICE_NAME
}
function send_success_example() {
install_if_missing core/curl curl
install_if_missing core/jq-static jq
local examples_json_path="/src/pkg/examples/compliance-success-tiny-report.json"
local endpoint="http://localhost:$PORT/inspec_reports/data-collector/v0/"
local uuid=$(uuidgen)
local entity_uuid=$(uuidgen)
local date=$(date --rfc-3339=seconds | sed 's/ /T/' | sed 's/\+.*/Z/')
tmp_report_json="$(jq --arg date "$date" --arg id "$uuid" --arg nodeid "$entity_uuid" '.report_uuid = $id | .node_uuid = $nodeid | .end_time = $date' <$examples_json_path)"
echo "$tmp_report_json" | curl --data "@-" $endpoint
}
function send_failure_example() {
install_if_missing core/curl curl
install_if_missing core/jq-static jq
local examples_json_path="/src/pkg/examples/compliance-failure-big-report.json"
local endpoint="http://localhost:$PORT/inspec_reports/data-collector/v0/"
local uuid=$(uuidgen)
local entity_uuid=$(uuidgen)
local date=$(date --rfc-3339=seconds | sed 's/ /T/' | sed 's/\+.*/Z/')
tmp_report_json="$(jq --arg date "$date" --arg id "$uuid" --arg nodeid "$entity_uuid" '.report_uuid = $id | .node_uuid = $nodeid | .end_time = $date' <$examples_json_path)"
echo "$tmp_report_json" | curl --data "@-" $endpoint
}
function start_sup() {
load_dev_config
hab sup status 2>/dev/null 1>&2
[[ $? == 0 ]] && return
mkdir -p /hab/sup/default
echo "=> Launching the Habitat Supervisor in the background..."
hab sup run $* > /hab/sup/default/sup.log &
while : ; do
hab sup status >/dev/null
[[ $? -eq 0 ]] && break || sleep 1
done
}
function status() {
hab sup status;
}
function create_config_file() {
mkdir -p /hab/user/$SERVICE_NAME/config/
touch /hab/user/$SERVICE_NAME/config/user.toml
}
# Saves the in memory bash history to a file
function save_history() {
history -a /src/.bash_history
}
# if .studiorc is being sourced from an already running studio, don't reset bash
# history -- this is achieved by saving the current history before it is re-read
save_history
# Load the bash history from a file
history -r /src/.bash_history
function cleanup() {
save_history
}
# When exiting the studio save the bash history to a file
trap cleanup EXIT