-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocs.sh
More file actions
849 lines (762 loc) · 29.5 KB
/
ocs.sh
File metadata and controls
849 lines (762 loc) · 29.5 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
#!/bin/sh
#
# Improved Open Cluster Scheduler Installation Script
# Works across Linux distributions
#
# Usage:
# curl -s <script_url> | sh # Installs default version
# curl -s <script_url> | OCS_VERSION=9.0.6 sh # Installs specific version
# OCS_PACKAGE_DIR=/path/to/packages ./ocs.sh # Uses pre-downloaded packages
#
set -e # Exit on error
#set -u # Treat unset variables as errors
# Default version - can be overridden by environment variable
OCS_VERSION="${OCS_VERSION:-9.1.1}"
echo "Starting Open Cluster Scheduler installation (version: $OCS_VERSION)..."
# Function to check hostname resolution
check_hostname_resolution() {
local hostname=$(hostname)
local resolved_ip=""
echo "Checking hostname resolution for: $hostname"
# Try getent first
if command -v getent > /dev/null 2>&1; then
resolved_ip=$(getent hosts "$hostname" 2>/dev/null | awk '{ print $1 }' | head -n 1)
fi
# Fallback to parsing /etc/hosts if getent didn't work
if [ -z "$resolved_ip" ] && [ -f /etc/hosts ]; then
resolved_ip=$(grep -E "^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+[[:space:]]" /etc/hosts | grep -w "$hostname" | awk '{ print $1 }' | head -n 1)
fi
# Check if we got a resolution
if [ -z "$resolved_ip" ]; then
echo "ERROR: Unable to resolve hostname '$hostname'" >&2
echo "Please ensure your hostname is properly configured in /etc/hosts" >&2
exit 1
fi
# Check if it resolves to loopback
if [ "$resolved_ip" = "127.0.0.1" ] || [ "$resolved_ip" = "127.0.1.1" ]; then
echo "ERROR: Hostname '$hostname' resolves to loopback address ($resolved_ip)" >&2
echo "Open Cluster Scheduler requires hostname to resolve to a network IP address," >&2
echo "not 127.0.0.1 or localhost." >&2
echo "" >&2
echo "Please update /etc/hosts to map '$hostname' to your actual IP address" >&2
echo "(e.g., 10.x.x.x or 192.168.x.x or a public IP)." >&2
exit 1
fi
echo "OK: Hostname resolves to $resolved_ip"
}
# Function to get download URLs based on version
get_download_urls() {
local version="$1"
local arch="$2" # lx-amd64, lx-arm64, ulx-amd64
case "$version" in
"9.0.5")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/10529/?tmstv=1745334305"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/10535/?tmstv=1745334305"
;;
"doc")
echo "https://hpc-gridware.com/download/10543/?tmstv=1745334305"
;;
"common")
echo "https://hpc-gridware.com/download/10541/?tmstv=1745334305"
;;
*)
echo ""
;;
esac
;;
"9.0.6")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/10646/?tmstv=1749092703"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/10648/?tmstv=1749092703"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/10652/?tmstv=1749092703"
;;
"doc")
echo "https://hpc-gridware.com/download/10656/?tmstv=1749092703"
;;
"common")
echo "https://hpc-gridware.com/download/10654/?tmstv=1749092703"
;;
*)
echo ""
;;
esac
;;
"9.0.7")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/10802/?tmstv=1751900704"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/10804/?tmstv=1751900704"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/10808/?tmstv=1751900704"
;;
"doc")
echo "https://hpc-gridware.com/download/10818/?tmstv=1751900704"
;;
"common")
echo "https://hpc-gridware.com/download/10816/?tmstv=1751900704"
;;
*)
echo ""
;;
esac
;;
"9.0.8")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11126/?tmstv=1756559953"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11128/?tmstv=1756559954"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11132/?tmstv=1756559954"
;;
"doc")
echo "https://hpc-gridware.com/download/11140/?tmstv=1756559954"
;;
"common")
echo "https://hpc-gridware.com/download/11138/?tmstv=1756559954"
;;
*)
echo ""
;;
esac
;;
"9.0.9")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11419/?tmstv=1763537222"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11421/?tmstv=1763537222"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11425/?tmstv=1763537222"
;;
"doc")
echo "https://hpc-gridware.com/download/11433/?tmstv=1763537222"
;;
"common")
echo "https://hpc-gridware.com/download/11431/?tmstv=1763537222"
;;
*)
echo ""
;;
esac
;;
"9.0.10")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11543/?tmstv=1765743707"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11546/?tmstv=1765743707"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11550/?tmstv=1765743707"
;;
"doc")
echo "https://hpc-gridware.com/download/11558/?tmstv=1765743707"
;;
"common")
echo "https://hpc-gridware.com/download/11556/?tmstv=1765743707"
;;
*)
echo ""
;;
esac
;;
"9.0.11")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11782/?tmstv=1773039540"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11784/?tmstv=1773039540"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11788/?tmstv=1773039540"
;;
"doc")
echo "https://hpc-gridware.com/download/11796/?tmstv=1773039540"
;;
"common")
echo "https://hpc-gridware.com/download/11794/?tmstv=1773039540"
;;
*)
echo ""
;;
esac
;;
"9.0.12")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11948/?tmstv=1776666481"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11950/?tmstv=1776666481"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11954/?tmstv=1776666481"
;;
"doc")
echo "https://hpc-gridware.com/download/11962/?tmstv=1776666481"
;;
"common")
echo "https://hpc-gridware.com/download/11960/?tmstv=1776666481"
;;
*)
echo ""
;;
esac
;;
"9.1.0")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11892/?tmstv=1774075397"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11894/?tmstv=1774075397"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11898/?tmstv=1774075397"
;;
"doc")
echo "https://hpc-gridware.com/download/11907/?tmstv=1774075397"
;;
"common")
echo "https://hpc-gridware.com/download/11905/?tmstv=1774075397"
;;
*)
echo ""
;;
esac
;;
"9.1.1")
case "$arch" in
"lx-amd64")
echo "https://hpc-gridware.com/download/11984/?tmstv=1777878816"
;;
"lx-arm64")
echo "https://hpc-gridware.com/download/11986/?tmstv=1777878816"
;;
"ulx-amd64")
echo "https://hpc-gridware.com/download/11990/?tmstv=1777878816"
;;
"doc")
echo "https://hpc-gridware.com/download/11998/?tmstv=1777878816"
;;
"common")
echo "https://hpc-gridware.com/download/11996/?tmstv=1777878816"
;;
*)
echo ""
;;
esac
;;
*)
echo "ERROR: Unsupported OCS version: $version" >&2
echo "Supported versions: 9.0.5, 9.0.6, 9.0.7, 9.0.8, 9.0.9, 9.0.10, 9.0.11, 9.0.12, 9.1.0, 9.1.1" >&2
exit 1
;;
esac
}
# Function to check for pre-downloaded packages in specified directory
check_predownloaded_packages() {
local package_dir="$1"
local version="$2"
local sys_arch="$3"
if [ ! -d "$package_dir" ]; then
echo "ERROR: Specified package directory does not exist: $package_dir" >&2
exit 1
fi
# Check for required packages with both ocs and gcs prefixes
local binary_found=0
local common_found=0
local doc_found=0
# Check binary package (architecture specific)
for prefix in "ocs" "gcs"; do
local binary_file="${prefix}-${version}-bin-${sys_arch}.tar.gz"
if [ -f "${package_dir}/${binary_file}" ]; then
echo "Found binary package: $binary_file"
binary_found=1
break
fi
done
# Check common package
for prefix in "ocs" "gcs"; do
local common_file="${prefix}-${version}-common.tar.gz"
if [ -f "${package_dir}/${common_file}" ]; then
echo "Found common package: $common_file"
common_found=1
break
fi
done
# Check doc package
for prefix in "ocs" "gcs"; do
local doc_file="${prefix}-${version}-doc.tar.gz"
if [ -f "${package_dir}/${doc_file}" ]; then
echo "Found doc package: $doc_file"
doc_found=1
break
fi
done
# Verify all required packages are present
if [ $binary_found -eq 0 ]; then
echo "ERROR: Binary package not found for architecture $sys_arch in $package_dir" >&2
echo "Expected: ocs-${version}-bin-${sys_arch}.tar.gz or gcs-${version}-bin-${sys_arch}.tar.gz" >&2
exit 1
fi
if [ $common_found -eq 0 ]; then
echo "ERROR: Common package not found in $package_dir" >&2
echo "Expected: ocs-${version}-common.tar.gz or gcs-${version}-common.tar.gz" >&2
exit 1
fi
if [ $doc_found -eq 0 ]; then
echo "ERROR: Doc package not found in $package_dir" >&2
echo "Expected: ocs-${version}-doc.tar.gz or gcs-${version}-doc.tar.gz" >&2
exit 1
fi
echo "All required packages found in $package_dir"
}
# Function to copy pre-downloaded packages to download directory
copy_predownloaded_files() {
local package_dir="$1"
local version="$2"
local sys_arch="$3"
local download_dir="$4"
echo "Using pre-downloaded packages from: $package_dir"
# Copy binary package
for prefix in "ocs" "gcs"; do
local binary_file="${prefix}-${version}-bin-${sys_arch}.tar.gz"
if [ -f "${package_dir}/${binary_file}" ]; then
echo " Copying $binary_file..."
cp "${package_dir}/${binary_file}" "$download_dir/"
break
fi
done
# Copy common package
for prefix in "ocs" "gcs"; do
local common_file="${prefix}-${version}-common.tar.gz"
if [ -f "${package_dir}/${common_file}" ]; then
echo " Copying $common_file..."
cp "${package_dir}/${common_file}" "$download_dir/"
break
fi
done
# Copy doc package
for prefix in "ocs" "gcs"; do
local doc_file="${prefix}-${version}-doc.tar.gz"
if [ -f "${package_dir}/${doc_file}" ]; then
echo " Copying $doc_file..."
cp "${package_dir}/${doc_file}" "$download_dir/"
break
fi
done
}
# Function to detect system architecture
detect_architecture() {
local arch=$(uname -m)
local os_release=""
# Check if it's an old Linux system (like CentOS 7)
if [ -f /etc/os-release ]; then
. /etc/os-release
if [ "$ID" = "centos" ] && [ "${VERSION_ID%%.*}" -le 7 ]; then
echo "ulx-amd64"
return
fi
# Add more old Linux checks here if needed
fi
# Map architecture
case "$arch" in
x86_64)
echo "lx-amd64"
;;
aarch64|arm64)
echo "lx-arm64"
;;
*)
echo "ERROR: Unsupported architecture: $arch" >&2
exit 1
;;
esac
}
# Function to install packages based on the package manager
install_packages() {
local packages="git tar binutils sudo make wget bash"
local epel_installed=0
if command -v apt &> /dev/null; then
echo "Detected apt package manager"
sudo apt update
sudo apt install -y $packages
# On Ubuntu, the package names are libtirpc3 and libtirpc-dev
echo "Installing libtirpc packages..."
sudo apt install -y libtirpc3 libtirpc-dev
elif command -v dnf &> /dev/null; then
echo "Detected dnf package manager"
# First install dnf-plugins-core if not already installed
if ! rpm -q dnf-plugins-core &> /dev/null; then
echo "Installing dnf-plugins-core for repository management..."
sudo dnf install -y dnf-plugins-core
fi
# Try to install packages directly first
sudo dnf install -y $packages
echo "Enabling CRB/CodeReady repo for development packages..."
source /etc/os-release
if [ "${ID}" = "ol" ] && [[ "${VERSION_ID}" == 9* ]]; then
sudo dnf config-manager --set-enabled ol9_codeready_builder
else
sudo dnf config-manager --set-enabled crb || sudo dnf config-manager --set-enabled powertools || true
fi
# Install libtirpc and libtirpc-devel directly from the repository
echo "Installing libtirpc from repository..."
sudo dnf install -y libtirpc libtirpc-devel
# Try to install screen, if it fails, add EPEL repo
if ! sudo dnf install -y screen; then
echo "Screen package not found in default repositories, adding EPEL..."
# Install EPEL repository
if sudo dnf install -y epel-release; then
echo "EPEL repository installed successfully"
epel_installed=1
else
echo "WARNING: Failed to install EPEL repository"
fi
# Try to install screen again if EPEL was installed
if [ $epel_installed -eq 1 ]; then
if ! sudo dnf install -y screen; then
echo "WARNING: Screen package not available even with EPEL. Continuing without screen..."
fi
fi
fi
elif command -v yum &> /dev/null; then
echo "Detected yum package manager"
sudo yum install -y $packages
# Enable optional repositories
echo "Enabling required repositories..."
sudo yum install -y yum-utils
sudo yum-config-manager --enable powertools || sudo yum-config-manager --enable crb || true
# Install libtirpc directly
sudo yum install -y libtirpc libtirpc-devel
# Try to install screen, if it fails, add EPEL repo
if ! sudo yum install -y screen; then
echo "Screen package not found in default repositories, adding EPEL..."
# Install EPEL repository
if sudo yum install -y epel-release; then
echo "EPEL repository installed successfully"
epel_installed=1
else
echo "WARNING: Failed to install EPEL repository"
fi
# Try to install screen again if EPEL was installed
if [ $epel_installed -eq 1 ]; then
if ! sudo yum install -y screen; then
echo "WARNING: Screen package not available even with EPEL. Continuing without screen..."
fi
fi
fi
elif command -v pacman &> /dev/null; then
echo "Detected pacman package manager"
sudo pacman -Sy --noconfirm $packages screen libtirpc
elif command -v zypper &> /dev/null; then
echo "Detected zypper package manager"
# Detect distribution and version
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTID=$ID
DISTVERSION=${VERSION_ID%%.*}
else
echo "ERROR: Cannot detect SUSE distribution version."
exit 1
fi
# Default package list
packages="git tar binutils sudo make wget bash screen libtirpc libtirpc-devel"
if [ "$DISTID" = "sles" ]; then
echo "Detected SUSE Linux Enterprise Server $DISTVERSION"
# Register Desktop Applications module FIRST
sudo SUSEConnect -p sle-module-desktop-applications/${VERSION_ID}/x86_64 || \
sudo SUSEConnect -p sle-module-desktop-applications/15/x86_64
# Register Development Tools module
sudo SUSEConnect -p sle-module-development-tools/${VERSION_ID}/x86_64 || \
sudo SUSEConnect -p sle-module-development-tools/15/x86_64
packages="git-core tar binutils sudo make wget bash screen libtirpc3 libtirpc-devel which"
elif [ "$DISTID" = "opensuse-leap" ]; then
echo "Detected openSUSE Leap $DISTVERSION"
# On openSUSE, package names are as expected
packages="git tar binutils sudo make wget bash screen libtirpc3 libtirpc-devel which"
else
echo "WARNING: Unknown SUSE variant; attempting with default package names."
fi
# Install packages with zypper
sudo zypper install -y --no-recommends $packages
# Check for errors if critical packages are missing
if ! rpm -q libtirpc-devel > /dev/null; then
echo "ERROR: libtirpc-devel could not be installed."
exit 1
fi
if ! command -v git &>/dev/null; then
echo "ERROR: git could not be installed."
exit 1
fi
else
echo "ERROR: Unsupported package manager. Please install the following packages manually:"
echo "$packages screen libtirpc libtirpc-devel"
exit 1
fi
}
# Setup directories
setup_directories() {
echo "Setting up installation directories..."
# No need to create download directory here as we re-create it in download_files
sudo mkdir -p /opt/ocs
}
# Download installation files
download_files() {
echo "Preparing Open Cluster Scheduler $OCS_VERSION files..."
# Detect system architecture
local sys_arch=$(detect_architecture)
echo "Detected system architecture: $sys_arch"
# Use the local directory for downloads
local download_dir="./ocs_downloads"
# Clean up existing downloads
echo "Cleaning up existing downloads..."
rm -rf "$download_dir"
mkdir -p "$download_dir"
# Check if OCS_PACKAGE_DIR is set for pre-downloaded packages
if [ -n "${OCS_PACKAGE_DIR:-}" ]; then
echo "OCS_PACKAGE_DIR is set: $OCS_PACKAGE_DIR"
check_predownloaded_packages "$OCS_PACKAGE_DIR" "$OCS_VERSION" "$sys_arch"
copy_predownloaded_files "$OCS_PACKAGE_DIR" "$OCS_VERSION" "$sys_arch" "$download_dir"
echo "Pre-downloaded packages copied successfully"
else
echo "Downloading Open Cluster Scheduler $OCS_VERSION files..."
cd "$download_dir"
download_from_web "$OCS_VERSION" "$sys_arch"
cd ..
fi
# Extract files to installation directory
echo "Extracting files to installation directory..."
cd "$download_dir"
for file in *.tar.gz; do
if [ -f "$file" ]; then
echo " Extracting $file..."
sudo tar xpf "$file" -C /opt/ocs/
fi
done
cd - > /dev/null
}
# Function to download files from web
download_from_web() {
local version="$1"
local sys_arch="$2"
# Download architecture-specific binary package
local bin_url=$(get_download_urls "$version" "$sys_arch")
if [ -n "$bin_url" ] && [ "$bin_url" != "https://hpc-gridware.com/download/XXXXX/?tmstv=XXXXXXXXXX" ]; then
echo "Downloading $sys_arch binary package..."
wget -q --show-progress -k --content-disposition "$bin_url"
else
echo "ERROR: No valid URL for $sys_arch binary package for version $version"
exit 1
fi
# For ARM64 systems with version 9.0.6+, also check if lx-arm64 is available
if [ "$sys_arch" = "lx-amd64" ] && [ "$version" != "9.0.5" ]; then
local arm64_url=$(get_download_urls "$version" "lx-arm64")
if [ -n "$arm64_url" ] && [ "$arm64_url" != "https://hpc-gridware.com/download/XXXXX/?tmstv=XXXXXXXXXX" ]; then
echo "Note: ARM64 binary is also available for this version"
fi
fi
# Download common packages
for pkg in "doc" "common"; do
local url=$(get_download_urls "$version" "$pkg")
if [ -n "$url" ] && [ "$url" != "https://hpc-gridware.com/download/XXXXX/?tmstv=XXXXXXXXXX" ]; then
echo "Downloading $pkg package..."
wget -q --show-progress -k --content-disposition "$url"
else
echo "ERROR: No valid URL for $pkg package for version $version"
exit 1
fi
done
}
# Create autoinstall template
create_autoinstall_template() {
local hostname=$(hostname)
local template_file="$(pwd)/autoinstall.template"
# Check if OCS_EXEC_HOSTS is set for multi-node configuration
# Expected format: "host1 host2 host3"
local exec_hosts="${OCS_EXEC_HOSTS:-$hostname}"
local admin_hosts="${OCS_ADMIN_HOSTS:-$exec_hosts}"
local submit_hosts="${OCS_SUBMIT_HOSTS:-$exec_hosts}"
echo "Creating installation template with:"
echo " Admin hosts: $admin_hosts"
echo " Submit hosts: $submit_hosts"
echo " Execution hosts: $exec_hosts"
cat > "$template_file" << EOF
SGE_ROOT="/opt/ocs"
SGE_QMASTER_PORT="6444"
SGE_EXECD_PORT="6445"
SGE_ENABLE_SMF="false"
SGE_CLUSTER_NAME="p6444"
CELL_NAME="default"
ADMIN_USER="root"
QMASTER_SPOOL_DIR="/opt/ocs/default/spool/master"
EXECD_SPOOL_DIR="/opt/ocs/default/spool/execd"
GID_RANGE="20000-20200"
SPOOLING_METHOD="classic"
DB_SPOOLING_DIR="/opt/ocs/default/spool/bdb"
PAR_EXECD_INST_COUNT="20"
ADMIN_HOST_LIST="$admin_hosts"
SUBMIT_HOST_LIST="$submit_hosts"
EXEC_HOST_LIST="$exec_hosts"
EXECD_SPOOL_DIR_LOCAL=""
HOSTNAME_RESOLVING="true"
SHELL_NAME="ssh"
COPY_COMMAND="scp"
DEFAULT_DOMAIN="none"
ADMIN_MAIL="none"
ADD_TO_RC="true"
SET_FILE_PERMS="true"
RESCHEDULE_JOBS="wait"
SCHEDD_CONF="3"
SHADOW_HOST=""
EXEC_HOST_LIST_RM=""
REMOVE_RC="false"
CSP_RECREATE="true"
CSP_COPY_CERTS="false"
CSP_COUNTRY_CODE="DE"
CSP_STATE="Germany"
CSP_LOCATION="Building"
CSP_ORGA="Organisation"
CSP_ORGA_UNIT="Organisation_unit"
CSP_MAIL_ADDRESS="name@yourdomain.com"
EOF
}
# Install Open Cluster Scheduler
install_ocs() {
echo "Installing Open Cluster Scheduler..."
export MOUNT_DIR="/opt/ocs"
export LD_LIBRARY_PATH=""
local template_file="$(pwd)/autoinstall.template"
local tmp_template_host="$(pwd)/template_host"
local current_user=$(whoami)
local tmp_config_script="/tmp/ocs_config_$$.sh"
# Check if already installed
if [ -d ${MOUNT_DIR}/default/common ]; then
echo "Open Cluster Scheduler seems to be already installed!"
echo "Starting Open Cluster Scheduler daemons."
${MOUNT_DIR}/default/common/sgemaster
${MOUNT_DIR}/default/common/sgeexecd
return 0
fi
echo "Open Cluster Scheduler is not yet installed in ${MOUNT_DIR}. Starting installation."
# Copy autoinstall template
sudo cp "$template_file" "${MOUNT_DIR}/"
# Fix filestat issue with Linux namespaces
cd "${MOUNT_DIR}"
local sys_arch=$(./util/arch)
sudo rm -f ./utilbin/${sys_arch}/filestat
sudo sh -c "echo '#!/bin/sh' > ./utilbin/${sys_arch}/filestat"
sudo sh -c "echo 'echo root' >> ./utilbin/${sys_arch}/filestat"
sudo chmod +x ./utilbin/${sys_arch}/filestat
# Install qmaster and execd
local hostname=$(hostname)
# Create template_host in the current directory first, then copy to installation dir
sed "s:docker:${hostname}:g" "$template_file" > "$tmp_template_host"
sudo cp "$tmp_template_host" "${MOUNT_DIR}/template_host"
# Run the installation
cd "${MOUNT_DIR}"
# On more recent distros the rc directory is missing. Installing rc scripts, switching
# to systemd later.
# Rocky 9
sudo mkdir -p /etc/rc.d/rc3.d/
# openSUSE Leap 15.6
sudo mkdir -p /etc/rc.d/init.d/
sudo ./inst_sge -m -x -auto ./template_host
# Configure environment
if [ -f "${MOUNT_DIR}/default/common/settings.sh" ]; then
# Use . instead of source for POSIX compatibility
. "${MOUNT_DIR}/default/common/settings.sh"
# Create a temporary shell script to run with sudo
cat > "$tmp_config_script" << EOL
#!/bin/sh
# Source the settings file to set up the environment
. ${MOUNT_DIR}/default/common/settings.sh
# Enable root to submit jobs
qconf -sconf | sed -e 's:100:0:g' > ${MOUNT_DIR}/global
qconf -Mconf ${MOUNT_DIR}/global
# Allow 10 single-core jobs to be processed at once per node
qconf -rattr queue slots 10 all.q
# Make current user a manager
echo "Adding current user (${current_user}) as a manager..."
qconf -am "${current_user}"
# Add settings to root's bashrc
if ! grep -q "${MOUNT_DIR}/default/common/settings.sh" /root/.bashrc; then
echo ". ${MOUNT_DIR}/default/common/settings.sh" >> /root/.bashrc
fi
EOL
# Make the script executable
chmod +x "$tmp_config_script"
# Run the configuration script with sudo
echo "Running OCS configuration..."
sudo "$tmp_config_script"
# Add settings to current user's bashrc if not already there
if ! grep -q "${MOUNT_DIR}/default/common/settings.sh" "$HOME/.bashrc"; then
echo "" >> "$HOME/.bashrc"
echo "# Open Cluster Scheduler settings" >> "$HOME/.bashrc"
echo ". ${MOUNT_DIR}/default/common/settings.sh" >> "$HOME/.bashrc"
fi
# Clean up temporary script
rm -f "$tmp_config_script"
else
echo "ERROR: Installation failed. Could not find settings.sh"
exit 1
fi
# Clean up temporary files
rm -f "$tmp_template_host"
echo "Open Cluster Scheduler $OCS_VERSION installation completed successfully!"
echo "Current user ($current_user) has been added as a manager"
echo "Open Cluster Scheduler environment has been added to your ~/.bashrc"
echo "Please run: source ~/.bashrc or start a new terminal to use Open Cluster Scheduler (qhost, qstat, qsub, ...)"
}
# Main execution
main() {
# Display version information
echo "================================"
echo "Open Cluster Scheduler Installer"
echo "Version to install: $OCS_VERSION"
echo "================================"
echo ""
# Check hostname resolution before proceeding
check_hostname_resolution
echo ""
# Validate version before proceeding
case "$OCS_VERSION" in
"9.0.5"|"9.0.6"|"9.0.7"|"9.0.8"|"9.0.9"|"9.0.10"|"9.0.11"|"9.0.12"|"9.1.0"|"9.1.1")
# Supported versions
;;
*)
echo "ERROR: Unsupported version: $OCS_VERSION"
echo "Supported versions: 9.0.5, 9.0.6, 9.0.7, 9.0.8, 9.0.9, 9.0.10, 9.0.11, 9.0.12, 9.1.0, 9.1.1"
echo "Usage: OCS_VERSION=9.0.6 $0"
exit 1
;;
esac
install_packages
setup_directories
download_files
create_autoinstall_template
install_ocs
}
# Run the script
main
exit 0