1
- usage_nomad () {
1
+ usage_nomadbackend () {
2
2
usage " nomad" " Backend: manages a Cardano cluster using Nomad" << EOF
3
3
4
4
Please see documentation for 'wb backend' for the supported commands.
65
65
66
66
backend_nomad () {
67
67
68
- op=${1:? $(usage_nomad)} ; shift
69
-
70
- # Stateful Nomad server and agent(s):
71
- # Calling `wb backend XXX` inside a Nix derivation will make everything fail:
72
- # "mkdir: cannot create directory '/homeless-shelter': Permission denied"
73
- # Better here rather than hidden in a function well below
74
- local nomad_agents_dir=" $( envjqr ' cacheDir' ) " /nomad
75
- mkdir -p " ${nomad_agents_dir} "
76
- local nomad_servers_dir=" ${nomad_agents_dir} " /server
77
- mkdir -p " ${nomad_servers_dir} "
78
- local nomad_clients_dir=" ${nomad_agents_dir} " /client
79
- mkdir -p " ${nomad_clients_dir} "
80
- local webfs_dir=" $( envjqr ' cacheDir' ) " /webfs
81
- mkdir -p " ${webfs_dir} "
82
- # TODO: Which directory ? State, cache, config ?
83
- # local nomad_state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/cardano-workbench/nomad
84
- # $XDG_STATE_HOME defines the base directory relative to which user-specific
85
- # state files should be stored.
86
- # (analogous to /var/lib).
87
- # https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
68
+ op=${1:? $(usage_nomadbackend)} ; shift
88
69
89
70
case " $op " in
90
71
@@ -125,7 +106,7 @@ backend_nomad() {
125
106
126
107
while test $# -gt 0
127
108
do case " $1 " in
128
- --* ) msg " FATAL: unknown flag '$1 '" ; usage_nomad ;;
109
+ --* ) msg " FATAL: unknown flag '$1 '" ; usage_nomadbackend ;;
129
110
* ) break ;; esac ; shift ; done
130
111
131
112
# The "nomad" folder is created by the sub-backends ("podman", "exec",
@@ -899,7 +880,7 @@ backend_nomad() {
899
880
900
881
while test $# -gt 0
901
882
do case " $1 " in
902
- --* ) msg " FATAL: unknown flag '$1 '" ; usage_nomad ;;
883
+ --* ) msg " FATAL: unknown flag '$1 '" ; usage_nomadbackend ;;
903
884
* ) break ;; esac ; shift ; done
904
885
905
886
if ! backend_nomad task-program-start " $dir " node-0 generator
@@ -2273,7 +2254,7 @@ backend_nomad() {
2273
2254
nomad job stop -global -no-shutdown-delay -purge -yes -verbose " ${job_name} "
2274
2255
;;
2275
2256
* )
2276
- usage_nomad
2257
+ usage_nomadbackend
2277
2258
;;
2278
2259
esac # nomad -> job
2279
2260
;;
@@ -2349,7 +2330,7 @@ backend_nomad() {
2349
2330
backend_nomad nomad server stop " ${server_name} " || true
2350
2331
;;
2351
2332
* )
2352
- usage_nomad
2333
+ usage_nomadbackend
2353
2334
;;
2354
2335
esac # nomad -> agents
2355
2336
;;
@@ -2363,6 +2344,7 @@ backend_nomad() {
2363
2344
state-dir-path )
2364
2345
local usage=" USAGE: wb backend pass $op $agent $subop SERVER-NAME"
2365
2346
local name=${1:? $usage } ; shift
2347
+ local nomad_servers_dir=" $( wb_nomad dir-path server) "
2366
2348
echo " ${nomad_servers_dir} " /" ${name} "
2367
2349
;;
2368
2350
config-file-path )
@@ -2530,7 +2512,7 @@ backend_nomad() {
2530
2512
fi
2531
2513
;;
2532
2514
* )
2533
- usage_nomad
2515
+ usage_nomadbackend
2534
2516
;;
2535
2517
esac # nomad -> server
2536
2518
;;
@@ -2544,6 +2526,7 @@ backend_nomad() {
2544
2526
state-dir-path )
2545
2527
local usage=" USAGE: wb backend pass $op $agent $subop CLIENT-NAME"
2546
2528
local name=${1:? $usage } ; shift
2529
+ local nomad_clients_dir=" $( wb_nomad dir-path client) "
2547
2530
echo " ${nomad_clients_dir} " /" ${name} "
2548
2531
;;
2549
2532
config-file-path )
@@ -2838,7 +2821,7 @@ backend_nomad() {
2838
2821
;;
2839
2822
# Client specific subcommands here (not available for servers):
2840
2823
* )
2841
- usage_nomad
2824
+ usage_nomadbackend
2842
2825
;;
2843
2826
esac # nomad -> client
2844
2827
;;
@@ -2880,7 +2863,8 @@ backend_nomad() {
2880
2863
echo " ${XDG_RUNTIME_DIR:-/ run/ user/ $UID } /workbench-podman.sock"
2881
2864
;;
2882
2865
pid-filepath )
2883
- echo " ${nomad_agents_dir} " /nomad-driver-podman.pid
2866
+ local plugin_dir=" $( wb_nomad dir-path plugin) "
2867
+ echo " ${plugin_dir} " /nomad-driver-podman.pid
2884
2868
;;
2885
2869
pid )
2886
2870
local pid_file=$( backend_nomad nomad plugin nomad-driver-podman pid-filepath)
@@ -2961,12 +2945,12 @@ backend_nomad() {
2961
2945
fi
2962
2946
;;
2963
2947
* )
2964
- usage_nomad
2948
+ usage_nomadbackend
2965
2949
;;
2966
2950
esac # nomad -> plugin -> nomad-driver-podman
2967
2951
;;
2968
2952
* )
2969
- usage_nomad
2953
+ usage_nomadbackend
2970
2954
;;
2971
2955
esac # nomad -> plugin
2972
2956
;;
@@ -2978,6 +2962,8 @@ backend_nomad() {
2978
2962
local subop=${1:? $usage } ; shift
2979
2963
case " $subop " in
2980
2964
nuke )
2965
+ local nomad_servers_dir=" $( wb_nomad dir-path server) "
2966
+ local nomad_clients_dir=" $( wb_nomad dir-path client) "
2981
2967
# Nuke all Nomad clients
2982
2968
for client_name in $( ls " ${nomad_clients_dir} " ) ; do
2983
2969
if backend_nomad nomad client is-running " ${client_name} "
@@ -3004,8 +2990,10 @@ backend_nomad() {
3004
2990
backend_nomad nomad server cleanup " ${server_name} "
3005
2991
fi
3006
2992
done
3007
- # Nuke the Nomad .cache dir
3008
- rm -rf " ${nomad_agents_dir} " > /dev/null 2>&1
2993
+ # Nuke the Nomad Agents' .cache dir
2994
+ # Keep top level Nomad cache dir because it includes Vault's dirs.
2995
+ rm -rf " ${nomad_servers_dir} " > /dev/null 2>&1
2996
+ rm -rf " ${nomad_clients_dir} " > /dev/null 2>&1
3009
2997
# Bye HTTP server
3010
2998
if backend_nomad webfs is-running
3011
2999
then
@@ -3018,15 +3006,15 @@ backend_nomad() {
3018
3006
# rm -rf ~/.config/containers/podman/
3019
3007
;;
3020
3008
* )
3021
- usage_nomad
3009
+ usage_nomadbackend
3022
3010
;;
3023
3011
esac # nomad -> all
3024
3012
;;
3025
3013
# ###############################################################################
3026
3014
# ###############################################################################
3027
3015
# ###############################################################################
3028
3016
* )
3029
- usage_nomad
3017
+ usage_nomadbackend
3030
3018
;;
3031
3019
esac # nomad
3032
3020
;;
@@ -3082,6 +3070,7 @@ EOF
3082
3070
# Nomad actions
3083
3071
case " $subop " in
3084
3072
state-dir-path)
3073
+ local webfs_dir=" $( wb_nomad dir-path webfs) "
3085
3074
echo " ${webfs_dir} "
3086
3075
;;
3087
3076
document-root-path )
@@ -3161,7 +3150,7 @@ EOF
3161
3150
# ###############################################################################
3162
3151
3163
3152
* )
3164
- usage_nomad
3153
+ usage_nomadbackend
3165
3154
;;
3166
3155
3167
3156
esac
@@ -3445,6 +3434,7 @@ nomad_create_client_config() {
3445
3434
local config_file=$( backend_nomad nomad client config-file-path " ${name} " )
3446
3435
# Look for the running servers to connect to ("wired" in the config file).
3447
3436
local servers_addresses=" "
3437
+ local nomad_servers_dir=" $( wb_nomad dir-path server) "
3448
3438
for server_name in $( ls " ${nomad_servers_dir} " ) ; do
3449
3439
if backend_nomad nomad server is-running " ${server_name} "
3450
3440
then
0 commit comments