-
Notifications
You must be signed in to change notification settings - Fork 12
/
singcvmfs
executable file
·178 lines (155 loc) · 5.23 KB
/
singcvmfs
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
#!/bin/bash
# Run a singularity container including cvmfs repositories mounted
# with the singularity --fusemount option.
# Written by Dave Dykstra March 2020
VERSION=4.42
ME="`basename $0`"
usage()
{
cat <<!EOF!
Usage: singcvmfs [-V] [global options] [command]
-V: print current $ME version and exit
global options: singularity global options (prior to its command)
If command starts with one of these singularity commands
exec
instance
run
shell
version
then the entire command is passed directly to singularity along
with options to mount cvmfs repositories when appropiate.
Otherwise the command is a shell command to run inside the chosen
container image, which may contain whitespace.
If command is missing then the shell is run.
Required environment variable:
SINGCVMFS_REPOSITORIES Comma-separated cvmfs repositories to mount
Required environment variable when singularity command not given:
SINGCVMFS_IMAGE singularity container path or URL
Optional environment variables:
SINGCVMFS_CACHEDIR Source directory for the cvmfs cache
SINGCVMFS_CACHEIMAGE Ext3 image file for the cvmfs cache
- If set, then ${SINGCVMFS_CACHEDIR:-/} is the
directory within the image used for the cache,
which must be writable by the user or contain
a 'shared' directory writable by the user
SINGCVMFS_OPTSFILE CVMFS options file (default.local)
- should set at least CVMFS_HTTP_PROXY
SINGCVMFS_SINGOPTS Extra singularity command options
SINGCVMFS_LOGDIR Directory for the cvmfs logs
SINGCVMFS_LOGLEVEL Set to debug to enable cvmfs debugging
!EOF!
exit 1
} >&2
HERE="$(cd `dirname $0` && pwd)"
ORIGPWD=$PWD
if [ "$1" = "-V" ]; then
echo "$VERSION"
exit
fi
if [ ! -f $HERE/dist/usr/lib*/libcvmfs_fuse3.so ]; then
echo "$ME: Must be run from where cvmfs distribution was made by 'makedist -s'" >&2
exit 1
fi
if [ -z "$SINGCVMFS_REPOSITORIES" ]; then
echo "$ME: SINGCVMFS_REPOSITORIES not set" >&2
usage
exit 1
fi
REPOS="$SINGCVMFS_REPOSITORIES"
# Add the config repo if not already asked for
CONFIG_REPO="`grep -h '^CVMFS_CONFIG_REPOSITORY=' $HERE/dist/etc/cvmfs/default.d/*.conf 2>/dev/null|tail -1|sed 's/^CVMFS_CONFIG_REPOSITORY=//'`"
if [[ ",$REPOS," != *",$CONFIG_REPO,"* ]]; then
REPOS="$CONFIG_REPO,$REPOS"
fi
CVMFSDEBUG=""
EXEC=exec
DEBUGCONF=$HERE/dist/etc/cvmfs/default.d/00-debug.conf
if [ "$SINGCVMFS_LOGLEVEL" = "debug" ]; then
CVMFSDEBUG="-o debug"
echo "CVMFS_DEBUGLOG=/var/log/cvmfs/@fqrn@-debug.log" >$DEBUGCONF
# would rather not leave this around because it interferes with
# use of cvmfsexec in same directory.
EXEC=""
trap "rm -f $DEBUGCONF" 0
else
rm -f $DEBUGCONF
fi
declare -a MOUNT_ARGS
for R in ${REPOS//,/ }; do
MOUNT_ARGS+=(--fusemount "\"container:cvmfs2-wrapper $CVMFSDEBUG $R /cvmfs/$R\"")
done
if [ -n "$APPTAINER_BINDPATH" ]; then
SINGULARITY_BINDPATH="$APPTAINER_BINDPATH"
fi
SINGULARITY_BINDPATH="$SINGULARITY_BINDPATH,$HERE/cvmfs2-wrapper:/usr/bin/cvmfs2-wrapper"
cd $HERE/dist
if [ -n "$SINGCVMFS_OPTSFILE" ]; then
cp $SINGCVMFS_OPTSFILE etc/cvmfs/default.local
fi
echo "CVMFS_NFILES=`ulimit -Hn`" >etc/cvmfs/default.d/00-nfiles.conf
echo "CVMFS_USYSLOG=/var/log/cvmfs/@fqrn@.log" >etc/cvmfs/default.d/00-usyslog.conf
if [ -n "$SINGCVMFS_LOGDIR" ]; then
LOGDIR=$SINGCVMFS_LOGDIR
else
LOGDIR=$HERE/log
fi
mkdir -p $LOGDIR
SINGULARITY_BINDPATH="$SINGULARITY_BINDPATH,$LOGDIR:/var/log/cvmfs"
for P in `find * ! -type d ! -path '*/doc/*' ! -path 'var/lib/cvmfs/*'| \
sed 's,/cvmfs/.*,/cvmfs,'|uniq`; do
SINGULARITY_BINDPATH="$SINGULARITY_BINDPATH,$PWD/$P:/$P"
done
SINGULARITY_BINDPATH="${SINGULARITY_BINDPATH#,}" # remove leading comma
export SINGULARITY_BINDPATH
export APPTAINER_BINDPATH="$SINGULARITY_BINDPATH"
CACHEBIND=""
if [ -n "$SINGCVMFS_CACHEIMAGE" ]; then
CACHEBIND="$SINGCVMFS_CACHEIMAGE:/var/lib/cvmfs:image-src=${SINGCVMFS_CACHEDIR:-/}"
else
CACHEBIND="${SINGCVMFS_CACHEDIR:-$PWD/var/lib/cvmfs}:/var/lib/cvmfs"
fi
cd $ORIGPWD
SINGGLOBALOPTS=""
while [ $# -gt 0 ]; do
if [[ "$1" = -* ]]; then
SINGGLOBALOPTS="$SINGGLOBALOPTS $1"
shift
else
break
fi
done
SINGCMD=""
SINGINSTCMD=""
case "$1" in
version)
exec singularity $SINGGLOBALOPTS "$@"
;;
version|exec|run|shell)
SINGCMD="$1"
shift
SINGCVMFS_IMAGE="" # just in case it is set
;;
instance)
SINGCMD="$1"
shift
# consume subcommand for instance
SINGINSTCMD=$1
shift
SINGCVMFS_IMAGE="" # just in case it is set
;;
*) if [ -z "$SINGCVMFS_IMAGE" ]; then
echo "$ME: SINGCVMFS_IMAGE not set" >&2
usage
exit 1
fi
SINGCMD=run
;;
esac
if [ "$SINGCMD" = instance -a "$SINGINSTCMD" != start ];
then
$EXEC singularity $SINGGLOBALOPTS $SINGCMD $SINGINSTCMD "$@"
else
$EXEC singularity $SINGGLOBALOPTS $SINGCMD $SINGINSTCMD \
-S /var/run/cvmfs -B $CACHEBIND \
"${MOUNT_ARGS[@]}" ${SINGCVMFS_SINGOPTS[@]} $SINGCVMFS_IMAGE "$@"
fi