On my system (shellcheck v0.7.1) make lint shows a few warnings about
needing to quote variables.
Fix those.
PS I am not sure why those are not shown by GHA CI, I assume there is
different shellcheck version used. Add shellcheck -- version to the
appropriate Makefile target to avoid confusion.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Shellcheck (https://github.com/koalaman/shellcheck) can identify common
errors in shell scripts. This initial integration of shellcheck only
checks the scripts in the 'scripts/' folder. This commit fixes (or
disables) all reports of shellcheck to ensure this part starts error
free. I am not convinced this is really necessary as most changes do not
seem to be necessary for their circumstances. On the other hand it
probably does not hurt to use a checker to avoid unnecessary errors.
Signed-off-by: Adrian Reber <areber@redhat.com>
The script checks if $NSENTER is executable and sets $NS_ENTER if not.
This seems to be a typo (once with '_' and once without).
Untested and not reproducible. It just looks wrong.
Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
"Check_fs_type" helper was repalce by "get_fs_type".
This reference is a silly mistake.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This helper uses other binaries (like awk), which can fail or be killed.
It this case might be, that no mountpoint is found.
Or, on other hand, the whole mount point path is wrong, and is absend in
mountinfo.
Return explicit error in this case.
Without this patch, script will proceed further, and, since returned value is
empty, it doesn't equal to "autofs", so script will try to bind-mount autofs
mount, resulting in hung.
travis-ci: success for systemd-autofs-restart.sh: explicitly return result from get_fs_type
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Without this patch any error in check_fs_type function is considered as a
grant to process to bind-mount.
This patch splits mount point fs type discovering and comparison to autofs
type, thus allowing to check for discovery errors.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
There can be autofs direct mount point without target mount on top.
In this case there won't be any bindmount and nothing to restore on top of the
autofs mount point.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
restore_mountpoint() should never be called without saved mountpoint.
If this happens, this is bug in script logic, which needs fixing.
https://jira.sw.ru/browse/PSBM-44207
Signed-off-by: Eugene Kolomeetz <klm@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
In such case, we must not proceed: without saved mountpoint, we risk
losing data when restarting automount service (think about tmpfs).
Currently, zero will be returned as exit status of preceeding echo.
https://jira.sw.ru/browse/PSBM-44207
Signed-off-by: Eugene Kolomeetz <klm@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
When we want to just execute command (without capturing output), we must
not do it via $(cmd). With such form, shell first gets output of 'cmd',
and then evaluates it. If this is empty string, it is successfully
executed. If not empty, all breaks down.
https://jira.sw.ru/browse/PSBM-44207
Signed-off-by: Eugene Kolomeetz <klm@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
When read bultin detects EOF, it sets empty string as value of specified
variable, and returns non-zero exit code. So we can rely just on exit
code, and not check variable value. This is standard approach.
https://jira.sw.ru/browse/PSBM-44207
Signed-off-by: Eugene Kolomeetz <klm@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Now readlink is called in host context, this is obviously wrong.
Signed-off-by: Eugene Kolomeetz <klm@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Let's use $(...) form, it is more readable, and used in other places.
Signed-off-by: Eugene Kolomeetz <klm@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Otherwise the following errors can be triggered:
/usr/libexec/criu/scripts/systemd-autofs-restart.sh: line 64: [: =: unary
operator expected
/usr/libexec/criu/scripts/systemd-autofs-restart.sh: line 77: [: =: unary
operator expected
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Fily system type is not necessarily located in the column number 9.
But look like we can rely on " - " pattern: it's always located immediately
after dash.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Unfortunatelly, autofs doesn't allow to discover it's type. At least without
accessing master process. That means, that stat can be used to determine
whether some other file system is mounted on top of autofs (which we need to
take a decision whether to move restore fs aside or not), because it simply
stuck.
This patch does fs type discovering by parsing CTs mountinfo.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This patch slightly changes the logic on systemd autofs service restart script:
1) It tries to bind-mount the mountpoint on top of autofs (if any) somewhere
before service restart, and replace new mount point on top of autofs (if any)
by the saved one after.
2) It doesn't exit in case of error, trying to recover as much as
possible in case of failure instead and then continue services restarting.
The reason for introducing new logic is that there can be some other,
stateful, file system on top of autofs (say, tmpfs), which state was restore
during migration.
With current script this state will be lost, while this patch allows to
preserve restored mount point after service restart.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Without correct pid namespace systemctl is not able to determine whether
autofs is active or not.
The reason is unaccessible proc due to mount namespace change without pid
namespace change.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This script restarts systemd autofs services to workaround a problem, when
systemd doesn't consider autofs mount as own after restore (alien device ID
problem)
v4:
Environment variable NS_PID was renamed to CRTOOLS_INIT_PID
v2:
1) Added different checks: for process with pid, active service, systemd based
container.
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>