diff --git a/README.md b/README.md index f3bf0f6..53aa05b 100644 --- a/README.md +++ b/README.md @@ -89,37 +89,11 @@ afs::afs_cron_job_minute: '42' afs::package_adminfile: '/path/to/adminfile/noask' afs::package_source: '/path/to/package/openafs-x.x.x-x-Sol10' -afs::service_provider: 'init' ``` On Solaris containers, this module will not start the OpenAFS service and the cronjob will not be created. Packages are still installed for the included tools. -#### Service management - -There are three different modes the module can handle services. The supported -operating systems has been configured according to the list below: -``` -init: - <= EL6 - <= Suse 11 - Ubuntu - Solaris -hybrid: - Suse 12 - EL7 -systemd: - All versions not specified under `init` or `hybrid`. -``` - -Hybrid will use systemd to execute the init-script which will start the service. - -For non-supported operating systems you'll have to choose which setup you want -to use. -Setting `init_template` will make make it use `init` method, setting both `init` -and `systemd` it will use hybrid and finally with `systemd_script_template` which -will use systemd. - ## Limitations This module has been tested to work on the following systems with Puppet diff --git a/REFERENCE.md b/REFERENCE.md index a09fc93..86ea9ce 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -49,10 +49,6 @@ The following parameters are available in the `afs` class: * [`config_client_path`](#-afs--config_client_path) * [`config_client_update`](#-afs--config_client_update) * [`create_symlinks`](#-afs--create_symlinks) -* [`init_script`](#-afs--init_script) -* [`init_template`](#-afs--init_template) -* [`systemd_script_template`](#-afs--systemd_script_template) -* [`systemd_unit_template`](#-afs--systemd_unit_template) * [`links`](#-afs--links) * [`package_adminfile`](#-afs--package_adminfile) * [`package_name`](#-afs--package_name) @@ -197,7 +193,7 @@ Default value: `'-dynroot -afsdb -daemons 6 -volumes 1000'` Data type: `Boolean` Boolean trigger for the cleaning of the client cache on start. -If set to true, the provided init script will clean the client cache when starting the service. +If set to true, client cache will be cleaned when starting the service. Please check openafs-client config file for supported OS families. Default value: `false` @@ -223,8 +219,8 @@ Default value: `undef` Data type: `Boolean` -Boolean trigger for the selfupdating routine in the init script. -If set to true, the init skript checks for updated AFS packages in the available repositories and installs them. +Boolean trigger for the selfupdating routine in the start script. +If set to true, checks for updated AFS packages in the available repositories and installs them. Default value: `false` @@ -236,41 +232,6 @@ Create symlinks for convenient access to AFS structure. Path and target are take Default value: `false` -##### `init_script` - -Data type: `Stdlib::Unixpath` - -Filename for the init script. - -Default value: `'/etc/init.d/openafs-client'` - -##### `init_template` - -Data type: `Optional[String]` - -Name of the template file to be used for $init_script. -Installs init-script if specified. - -Default value: `undef` - -##### `systemd_script_template` - -Data type: `Optional[String]` - -Name of the template file to be used as startup script for systemd. -Installs systemd script if specified. - -Default value: `undef` - -##### `systemd_unit_template` - -Data type: `Optional[String]` - -Name of the template file to be used as unit file for systemd. -Installs systemd unit file if specified. - -Default value: `undef` - ##### `links` Data type: `Hash` diff --git a/data/os/RedHat/5.yaml b/data/os/RedHat/5.yaml index 4d10094..f032cbf 100644 --- a/data/os/RedHat/5.yaml +++ b/data/os/RedHat/5.yaml @@ -1,6 +1,4 @@ --- -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-RedHat-init afs::package_name: - openafs - openafs-client diff --git a/data/os/RedHat/6.yaml b/data/os/RedHat/6.yaml deleted file mode 100644 index ee132c6..0000000 --- a/data/os/RedHat/6.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-RedHat-init diff --git a/data/os/RedHat/7.yaml b/data/os/RedHat/7.yaml deleted file mode 100644 index 3a2b6be..0000000 --- a/data/os/RedHat/7.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-RedHat-init -afs::systemd_unit_template: openafs-client-RedHat-systemd-sysv.service diff --git a/data/os/RedHat/8.yaml b/data/os/RedHat/8.yaml deleted file mode 100644 index d890c12..0000000 --- a/data/os/RedHat/8.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -afs::systemd_unit_template: openafs-client-RedHat-systemd-exec.service -afs::systemd_script_template: openafs-client-RedHat-systemd-exec diff --git a/data/os/RedHat/9.yaml b/data/os/RedHat/9.yaml deleted file mode 100644 index d890c12..0000000 --- a/data/os/RedHat/9.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -afs::systemd_unit_template: openafs-client-RedHat-systemd-exec.service -afs::systemd_script_template: openafs-client-RedHat-systemd-exec diff --git a/data/os/Solaris.yaml b/data/os/Solaris.yaml index 8de2b04..090300f 100644 --- a/data/os/Solaris.yaml +++ b/data/os/Solaris.yaml @@ -1,9 +1,5 @@ --- -afs::service_provider: init -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-Solaris - afs::afs_config_path: /usr/vice/etc afs::cache_path: /usr/vice/cache afs::config_client_dkms: false diff --git a/data/os/Suse/10.yaml b/data/os/Suse/10.yaml deleted file mode 100644 index 65fb03e..0000000 --- a/data/os/Suse/10.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-Suse-init diff --git a/data/os/Suse/11.yaml b/data/os/Suse/11.yaml deleted file mode 100644 index 65fb03e..0000000 --- a/data/os/Suse/11.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-Suse-init diff --git a/data/os/Suse/12.yaml b/data/os/Suse/12.yaml deleted file mode 100644 index a7ce92b..0000000 --- a/data/os/Suse/12.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- - -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-Suse-init -afs::systemd_unit_template: openafs-client-Suse-systemd-sysv.service diff --git a/data/os/Suse/15.yaml b/data/os/Suse/15.yaml deleted file mode 100644 index 2d6febf..0000000 --- a/data/os/Suse/15.yaml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -afs::systemd_unit_template: openafs-client-Suse-systemd-exec.service -afs::systemd_script_template: openafs-client-Suse-systemd-exec diff --git a/data/os/Ubuntu.yaml b/data/os/Ubuntu.yaml index 6d263fa..ee63003 100644 --- a/data/os/Ubuntu.yaml +++ b/data/os/Ubuntu.yaml @@ -1,8 +1,5 @@ --- -afs::init_script: /etc/init.d/openafs-client -afs::init_template: openafs-client-Ubuntu-init - afs::afs_config_path: /etc/openafs afs::cache_path: /var/cache/openafs afs::config_client_dkms: true diff --git a/files/openafs-client-RedHat-init b/files/openafs-client-RedHat-init deleted file mode 100755 index bb6415f..0000000 --- a/files/openafs-client-RedHat-init +++ /dev/null @@ -1,606 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2020 AFS-Core Ericsson -# Version v1.25, 2020-07-16 -# -# openafs-client Start/Stop the OpenAFS Client -# -# chkconfig: 2345 50 50 -# description: OpenAFS is a distributed filesystem. -# Should-Start: dkms -# -# $Revision$ - -DAEMON_BIN=/usr/vice/etc/afsd -AFS_KERNEL_MODULE=libafs -AFS=/afs - -OPENAFS_VERSION=$(rpm --queryformat '%{version}' -q openafs) -OPENAFSDKMS=dkms-openafs -CACHEDIR=/usr/vice/cache -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/usr/vice/etc/SuidCells -LOCKFILE="/var/lock/$(basename $0)" -LOCKFD=99 - -# PATH is set via /etc/init.d/functions -[ -f /etc/init.d/functions ] && . /etc/init.d/functions -[ -f /etc/sysconfig/openafs-client ] && . /etc/sysconfig/openafs-client - -# Set the minimum required options for afsd if no options set in /etc/sysconfig/openafs-client -AFSD_ARGS=${AFSD_ARGS:-"-dynroot -afsdb"} -UPDATE=${UPDATE:-"false"} -DKMS=${DKMS:-"true"} -CHKKERNELPACK=${CHKKERNELPACK:-"true"} -CLEANCACHE=${CLEANCACHE:-"false"} - -noroot_check() { - if [ "$(whoami | awk '{print $1}' | cut -f2 -d\!)" != "root" ]; then - return 0 - else - return 1 - fi -} - -# Lock -lock_routine() { - if { flock -h; } >/dev/null 2>&1; then - _lock() { flock -$1 $LOCKFD; } - _no_more_locking() { - _lock u - _lock xn && rm -f $LOCKFILE - } - _prepare_locking() { - eval "exec $LOCKFD>\"$LOCKFILE\"" - trap _no_more_locking EXIT - } - exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail - exlock() { _lock x; } # obtain an exclusive lock - shlock() { _lock s; } # obtain a shared lock - unlock() { _lock u; } # drop a lock - _prepare_locking - return 0 - else - return 1 - fi -} - -setsuid() { - if [ -f $SUIDCELLS ]; then - while read -r CELLS; do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done <<<"$(grep '^[^#]' $SUIDCELLS)" - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -firstint() { - sed 's/^[^0-9]*//; s/[^0-9].*//' -} - -get_cell() { - CELL=$(fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/") - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -get_dist_release() { - if LsbDistributor=$(lsb_release -si 2>/dev/null); then - LsbDescription=$(lsb_release -sd) - LsbRelease=$(lsb_release -sr | cut -d . -f -2) - case $LsbDistributor in - "SUSE"*) - if [[ $LsbDescription == *openSUSE* ]]; then - OS="openSuse" - _DIST="osuse" - else - OS=$(echo "$LsbDescription" | cut -f1-4 -d" " | sed -e 's/\([a-zA-Z]\)[^ ]* */\1/g' -e 's/"//') - _DIST="sle" - if [[ $LsbRelease != *.* ]]; then - patchlevel=$(awk '/^PATCHLEVEL/ {print $3}' /etc/SuSE-release 2>/dev/null) - LsbRelease=${LsbRelease}.${patchlevel:-0} - fi - fi - ;; - "RedHatEnterprise"* | "CentOS"*) - OS="RedHat" - _DIST="rhel" - ;; - "Ubuntu"*) - OS="Ubuntu" - _DIST="ubunt" - ;; - "Debian"*) - OS="Debian" - _DIST="deb" - ;; - "Fedora"*) - _DIST="fc" - ;; - *) - echo "Distribution not detected or not supported" - return - ;; - esac - Release="${LsbRelease}" - elif [ -f /etc/redhat-release ]; then - Release=$( - sed -n ' - /Red Hat Enterprise /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - /CentOS /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - ' /etc/redhat-release - ) - OS="RedHat" - _DIST="rhel" - fi -} - -setsysname() { - _ARCH=$(uname -i | sed 's/x86_64/amd64/') - _DIST="" - _VER="" - - get_dist_release - case "$_DIST" in - fc | deb) - return - ;; - esac - _VER=$(echo "$Release" | firstint) - # Sysname list. The order here is from specific to general, with a - # fallback to the compiled-in value from sys. This will be - # used as the sysname search path. - if { SYS=$(sys); } >/dev/null 2>&1; then - if [ -n "$_VER" ]; then - SYSNAMELIST="${_ARCH}_${_DIST}${_VER} $SYS" - fi - fi - - # Set the sysname - if [ -n "$SYSNAMELIST" ]; then - SYSNAME=$(echo "$SYSNAMELIST" | awk 'BEGIN {ORS=" "} { for (i=1;i<=NF;i+=1) print "-newsys",$i }') - _CMD="fs sysname $SYSNAME" - echo "Setting sysname: $SYSNAMELIST" - $_CMD >/dev/null - fi -} - -killafs() { - SIGNAL=$1 - PIDS=$(lsof -Fp $AFS | sed -e 's/p//') - if [ -n "$PIDS" ]; then - kill -$SIGNAL $PIDS >/dev/null 2>&1 - sleep 3 - fi -} - -dkms_check() { - if [ "$DKMS" == "true" ]; then - if { rpm -q $OPENAFSDKMS; } >/dev/null 2>&1; then - AFS_KERNEL_MODULE=openafs - return 0 - else - echo $"Error: DKMS set to true but no package $OPENAFSDKMS installed" - failure $"Error: DKMS set to true but no package $OPENAFSDKMS installed" - echo - exit 1 - fi - else - return 1 - fi -} - -check_kernelpackages() { - KERNEL_VERSION="$1" - if [[ "$KERNEL_VERSION" =~ \.debug$ ]]; then - KERNEL_CHECK=$(sed -e 's/\.debug$//' <<<$KERNEL_VERSION) - # KERNEL_DEVEL="debug-devel-$KERNEL_CHECK" - echo "System is running with a non supported kernel debug version: $KERNEL_VERSION" - echo "To be able to build the AFS kernel-module the system needs to be running with a normal kernel like: kernel-$KERNEL_CHECK" - echo - exit 1 - else - KERNEL_CHECK=$KERNEL_VERSION - KERNEL_DEVEL="devel-$KERNEL_VERSION" - fi - if [ -n "$KERNEL_CHECK" ]; then - if ! { rpm -q kernel-headers-$KERNEL_CHECK kernel-$KERNEL_DEVEL; } >/dev/null 2>&1; then - echo "Needed packages for running kernel $KERNEL_VERSION missing: kernel-headers-$KERNEL_CHECK kernel-$KERNEL_DEVEL" - echo "Try to install..." - yum --nogpgcheck -q -y install kernel-headers-$KERNEL_CHECK kernel-$KERNEL_DEVEL - CHKKERNELPACK="false" - fi - fi -} - -check_kernelmodule() { - KERNEL_VERSION=$(uname -r) - if dkms_check; then - OPENAFS_VERSION_FULL=$(rpm --queryformat '%{PROVIDEVERSION}' -q openafs) - DKMSSTATUS=$(dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION") - if echo "${DKMSSTATUS}" | egrep 'installed-weak|Diff between built and installed module' >/dev/null; then - echo - echo "Weak module detected, will be removed.." - echo "DKMS stuff ..." - dkms remove "$AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL" -k "$KERNEL_VERSION" --no-initrd - if [ -h /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko ]; then - TARGETLINK=$(readlink -f /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko) - rm -fv /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko - fi - if [ -h /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko.xz ]; then - TARGETLINKXZ=$(readlink -f /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko.xz) - rm -fv /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko.xz - fi - echo - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - if ! dkms install "$AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL" -k "$KERNEL_VERSION" --no-initrd; then - echo "DKMS install problem for $AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL $KERNEL_VERSION, will try to relink from other kernel version..." - if [ -n "$TARGETLINK" ]; then - if [ -f "$TARGETLINK" ]; then - echo "Using $TARGETLINK" - ln -s "$TARGETLINK" "/lib/modules/$KERNEL_VERSION/weak-updates/${AFS_KERNEL_MODULE}.ko" - fi - fi - if [ -n "$TARGETLINKXZ" ]; then - if [ -n "$TARGETLINKXZ" ]; then - echo "Using $TARGETLINKXZ" - ln -s "$TARGETLINKXZ" "/lib/modules/$KERNEL_VERSION/weak-updates/${AFS_KERNEL_MODULE}.ko.xz" - fi - fi - fi - DKMSSTATUS=$(dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION") - fi - if echo "${DKMSSTATUS}" | grep '(original_module exists)' >/dev/null; then - echo "DKMS (original_module exists) problem detected, try to fix: /var/lib/dkms/openafs/original_module/$KERNEL_VERSION" - if [ -d /var/lib/dkms/openafs/original_module/"$KERNEL_VERSION" ]; then - \rm -r /var/lib/dkms/openafs/original_module/"$KERNEL_VERSION" - DKMSSTATUS=$(dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION") - fi - fi - if ! echo "${DKMSSTATUS}" | grep ': installed$' >/dev/null; then - echo - echo "No kernel-module detected for $AFS_KERNEL_MODULE version $OPENAFS_VERSION_FULL and kernel $KERNEL_VERSION .." - echo "DKMS stuff ..." - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - if ! dkms install "$AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL" -k "$KERNEL_VERSION" --no-initrd; then - echo "DKMS install problem for $AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL $KERNEL_VERSION" - return 1 - fi - fi - return 0 - fi - - modprobe $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - [ $RETVAL -eq 0 ] && return 0 # Kernel module loaded, continue... - - echo - echo $"Failed to load kernel module, attempting rebuild.." - warning $"Failed to load kernel module, attempting rebuild.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 1 - } - fi - echo - - KMOD_BUILDLOG=/tmp/openafs-kmod-build-$(date +%Y%m%d-%H%M).log - - echo "Build log for OpenAFS module: $(date)" >$KMOD_BUILDLOG - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - - if [ -d /usr/src/openafs-kernel-$OPENAFS_VERSION/src ] && [ -f /usr/src/openafs-kernel-$OPENAFS_VERSION/src/configure ]; then - cd /usr/src/openafs-kernel-$OPENAFS_VERSION/src || return 1 - - make clean >>$KMOD_BUILDLOG 2>&1 - - ./configure --with-linux-kernel-headers=/lib/modules/$KERNEL_VERSION/build >>$KMOD_BUILDLOG 2>&1 - make -j4 >>$KMOD_BUILDLOG 2>&1 - if [ $? -eq 0 ]; then - MODULEDIR=/lib/modules/$KERNEL_VERSION/kernel/fs/openafs - [ ! -d $MODULEDIR ] && mkdir $MODULEDIR - - for file in src/libafs/MODLOAD-$KERNEL_VERSION-*/openafs.ko; do - if [ -f "$file" ]; then - cp "$file" $MODULEDIR/ - ln $MODULEDIR/openafs.ko $MODULEDIR/libafs.ko - break - else - cp src/libafs/MODLOAD-$KERNEL_VERSION-*/libafs.ko $MODULEDIR/ - fi - done - - depmod -a - modprobe $AFS_KERNEL_MODULE >>$KMOD_BUILDLOG 2>&1 - RETVAL=$? - else - RETVAL=1 - fi - [ $RETVAL -eq 0 ] && rm -f $KMOD_BUILDLOG && echo -n "Build succeded!" && success "Build succeded!" && echo && return 0 - - echo "Failed to build kernel module, see $KMOD_BUILDLOG for more details. " - failure "Failed to build kernel module, see $KMOD_BUILDLOG for more details." - echo - return 1 - else - echo "OpenAFS Kernel source not installed." - failure "OpenAFS Kernel source not installed." - echo - return 1 - fi -} - -rm_wrong_module() { - # Only needed if dkms is not used - if dkms_check; then - return 0 - fi - KERNEL_VERSION=$(uname -r) - module="$(modinfo -F filename $AFS_KERNEL_MODULE 2>/dev/null)" - if [ -f "$module" ]; then - mod_version=$(strings $module | awk '{ for (i=1; i $pkg_version" - fi - fi -} - -package_update() { - if [ "$UPDATE" == "true" ]; then - echo "Checking for OpenAFS updates.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 1 - } - fi - echo - yum --nogpgcheck -q clean all >/dev/null - yum --nogpgcheck -q check-update openafs >/dev/null - RETVAL=$? - if [ "$RETVAL" -eq "100" ]; then - echo "Upgrading OpenAFS" - if [ "$DKMS" == "true" ]; then - yum --nogpgcheck -q -y install openafs openafs-client openafs-docs openafs-krb5 openafs-compat dkms-openafs dkms - else - yum --nogpgcheck -q -y install openafs openafs-client openafs-docs openafs-krb5 openafs-compat openafs-kernel-source - fi - echo "Done" - fi - fi -} - -start() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - echo -n $"Starting openafs-client: " - if [ -e /var/lock/subsys/openafs-client ]; then - echo $"cannot start openafs-client: already running" - failure $"cannot start openafs-client: already running" - echo - return 1 - fi - if [ "$DKMS" == "true" ]; then - AFS_KERNEL_MODULE=openafs - # Check if no dkms session is running already - if { pgrep -f "dkms .* -m $AFS_KERNEL_MODULE"; } >/dev/null 2>&1; then - echo "A dkms-session is running to install/remove $AFS_KERNEL_MODULE, will exit now." - exit 1 - fi - fi - # A configured yum repository is needed for the package-update - package_update - rm_wrong_module - if check_kernelmodule; then - echo -n $"Updating CellServDB: " - cat /usr/vice/etc/CellServDB.local /usr/vice/etc/CellServDB.dist >/usr/vice/etc/CellServDB - - chmod 644 /usr/vice/etc/CellServDB - echo - if [ "$CLEANCACHE" == "true" ]; then - if [ "${CACHEDIR}" == "/usr/vice/cache" ] || [ "${CACHEDIR}" == "/var/cache/openafs" ]; then - if [ -d ${CACHEDIR} ]; then - echo $"Cleaning up cache area ${CACHEDIR}/ ..." - rm -rf ${CACHEDIR:?}/* - fi - else - echo $"Cache area CACHEDIR ${CACHEDIR} not set correctly for cleanup-job in startup-script." - fi - fi - - # Only needed if dkms is used - if dkms_check; then - modprobe $AFS_KERNEL_MODULE - RETVAL=$? - if [ $RETVAL -ne 0 ]; then - echo $"failed to load openafs kernel module." - failure $"failed to load openafs kernel module." - echo - return $RETVAL - fi - fi - - $DAEMON_BIN $AFSD_ARGS - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/openafs-client - [ $RETVAL -eq 0 ] && [ "$AFS_POST_INIT" ] && $AFS_POST_INIT - if [ $RETVAL -eq 0 ]; then - setsysname - setsuid - setnocrypt - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - ( - sleep 60 - [ -x $SETSERVERPREFS ] && $SETSERVERPREFS - ) /dev/null 2>&1 & - fi - return $RETVAL - else - echo $"failed to load openafs kernel module." - failure $"failed to load openafs kernel module." - echo - return 1 - fi -} - -stop() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - echo -n $"Stopping openafs-client: " - if [ ! -e /var/lock/subsys/openafs-client ]; then - echo $"cannot stop openafs-client: not running" - failure $"cannot stop openafs-client: not running" - echo - return 1 - fi - if [ "$DKMS" == "true" ]; then - AFS_KERNEL_MODULE=openafs - fi - umount $AFS - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - $DAEMON_BIN -shutdown - lsmod | grep -w $AFS_KERNEL_MODULE >/dev/null - if [ $? -ne 0 ]; then - AFS_KERNEL_MODULE=$(lsmod | awk '/afs/ {print $1}') - fi - rmmod $AFS_KERNEL_MODULE - RETVAL=$? - fi - if [ $RETVAL -eq 0 ]; then - rm -f /var/lock/subsys/openafs-client - fi - return $RETVAL -} - -stop-force() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - echo -n $"Stopping openafs-client: " - if [ ! -e /var/lock/subsys/openafs-client ]; then - echo $"cannot stop openafs-client: not running" - failure $"cannot stop openafs-client: not running" - echo - return 1 - fi - if pgrep -xf 'afsd' &>/dev/null; then - echo - echo "Sending all processes using $AFS the TERM signal ..." - killafs TERM - echo "Sending all processes using $AFS the KILL signal ..." - killafs KILL - fi - if dkms_check; then - AFS_KERNEL_MODULE=openafs - fi - umount $AFS - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - $DAEMON_BIN -shutdown - lsmod | grep -w $AFS_KERNEL_MODULE >/dev/null - if [ $? -ne 0 ]; then - AFS_KERNEL_MODULE=$(lsmod | awk '/afs/ {print $1}') - fi - rmmod $AFS_KERNEL_MODULE - RETVAL=$? - fi - if [ $RETVAL -eq 0 ]; then - rm -f /var/lock/subsys/openafs-client - fi - return $RETVAL -} - -rhstatus() { - status afsd - return $? -} - -check() { - echo -n $"Checking openafs-client: " - if [ ! -e /var/lock/subsys/openafs-client ]; then - echo $"cannot check openafs-client: not running" - failure $"cannot check openafs-client: not running" - echo - return 1 - fi - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -x $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo $"Check-script not available: $HEALTHCHECK" - failure $"Check-script not available" - echo - return 1 - fi -} - -restart() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - stop || exit - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - stop-force) - stop-force - ;; - restart) - restart - ;; - status) - rhstatus - exit $? - ;; - check) - check - ;; - condrestart) - [ -f /var/lock/subsys/openafs-client ] && restart || : - ;; - *) - echo $"Usage: $0 {start|stop|stop-force|status|check|restart|condrestart}" - exit 1 - ;; -esac - -exit $? diff --git a/files/openafs-client-RedHat-systemd-exec b/files/openafs-client-RedHat-systemd-exec deleted file mode 100755 index af61550..0000000 --- a/files/openafs-client-RedHat-systemd-exec +++ /dev/null @@ -1,589 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2020 AFS-Core Ericsson -# Version v1.25, 2020-07-16 -# -# systemd-exec.openafs-client native system exec-script -# - -DAEMON_BIN=/usr/vice/etc/afsd -AFS_KERNEL_MODULE=libafs -AFS=/afs - -OPENAFS_VERSION=$(rpm --queryformat '%{version}' -q openafs) -OPENAFSDKMS=dkms-openafs -CACHEDIR=/usr/vice/cache -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/usr/vice/etc/SuidCells -LOCKFILE="/var/lock/$(basename $0)" -LOCKFD=99 - -[ -f /etc/sysconfig/openafs-client ] && . /etc/sysconfig/openafs-client - -# Set the minimum required options for afsd if no options set in /etc/sysconfig/openafs-client -AFSD_ARGS=${AFSD_ARGS:-"-dynroot -afsdb"} -UPDATE=${UPDATE:-"false"} -DKMS=${DKMS:-"true"} -CHKKERNELPACK=${CHKKERNELPACK:-"true"} -CLEANCACHE=${CLEANCACHE:-"false"} - -noroot_check() { - if [ "$(whoami | awk '{print $1}' | cut -f2 -d\!)" != "root" ]; then - return 0 - else - return 1 - fi -} - -# Lock -lock_routine() { - if { flock -h; } >/dev/null 2>&1; then - _lock() { flock -$1 $LOCKFD; } - _no_more_locking() { - _lock u - _lock xn && rm -f $LOCKFILE - } - _prepare_locking() { - eval "exec $LOCKFD>\"$LOCKFILE\"" - trap _no_more_locking EXIT - } - exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail - exlock() { _lock x; } # obtain an exclusive lock - shlock() { _lock s; } # obtain a shared lock - unlock() { _lock u; } # drop a lock - _prepare_locking - return 0 - else - return 1 - fi -} - -setsuid() { - if [ -f $SUIDCELLS ]; then - while read -r CELLS; do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done <<<"$(grep '^[^#]' $SUIDCELLS)" - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -firstint() { - sed 's/^[^0-9]*//; s/[^0-9].*//' -} - -get_cell() { - CELL=$(fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/") - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -get_dist_release() { - if LsbDistributor=$(lsb_release -si 2>/dev/null); then - LsbDescription=$(lsb_release -sd) - LsbRelease=$(lsb_release -sr | cut -d . -f -2) - case $LsbDistributor in - "SUSE"*) - if [[ $LsbDescription == *openSUSE* ]]; then - OS="openSuse" - _DIST="osuse" - else - OS=$(echo "$LsbDescription" | cut -f1-4 -d" " | sed -e 's/\([a-zA-Z]\)[^ ]* */\1/g' -e 's/"//') - _DIST="sle" - if [[ $LsbRelease != *.* ]]; then - patchlevel=$(awk '/^PATCHLEVEL/ {print $3}' /etc/SuSE-release 2>/dev/null) - LsbRelease=${LsbRelease}.${patchlevel:-0} - fi - fi - ;; - "RedHatEnterprise"* | "CentOS"*) - OS="RedHat" - _DIST="rhel" - ;; - "Ubuntu"*) - OS="Ubuntu" - _DIST="ubunt" - ;; - "Debian"*) - OS="Debian" - _DIST="deb" - ;; - "Fedora"*) - _DIST="fc" - ;; - *) - echo "Distribution not detected or not supported" - return - ;; - esac - Release="${LsbRelease}" - elif [ -f /etc/redhat-release ]; then - Release=$( - sed -n ' - /Red Hat Enterprise /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - /CentOS /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - ' /etc/redhat-release - ) - OS="RedHat" - _DIST="rhel" - fi -} - -setsysname() { - _ARCH=$(uname -i | sed 's/x86_64/amd64/') - _DIST="" - _VER="" - - get_dist_release - case "$_DIST" in - fc | deb) - return - ;; - esac - _VER=$(echo "$Release" | firstint) - # Sysname list. The order here is from specific to general, with a - # fallback to the compiled-in value from sys. This will be - # used as the sysname search path. - if { SYS=$(sys); } >/dev/null 2>&1; then - if [ -n "$_VER" ]; then - SYSNAMELIST="${_ARCH}_${_DIST}${_VER} $SYS" - fi - fi - - # Set the sysname - if [ -n "$SYSNAMELIST" ]; then - SYSNAME=$(echo "$SYSNAMELIST" | awk 'BEGIN {ORS=" "} { for (i=1;i<=NF;i+=1) print "-newsys",$i }') - _CMD="fs sysname $SYSNAME" - echo "Setting sysname: $SYSNAMELIST" - $_CMD >/dev/null - fi -} - -killafs() { - SIGNAL=$1 - PIDS=$(lsof -Fp $AFS | sed -e 's/p//') - if [ -n "$PIDS" ]; then - kill -$SIGNAL $PIDS >/dev/null 2>&1 - sleep 3 - fi -} - -dkms_check() { - if [ "$DKMS" == "true" ]; then - if { rpm -q $OPENAFSDKMS; } >/dev/null 2>&1; then - AFS_KERNEL_MODULE=openafs - return 0 - else - echo $"Error: DKMS set to true but no package $OPENAFSDKMS installed" - echo - exit 1 - fi - else - return 1 - fi -} - -check_kernelpackages() { - KERNEL_VERSION="$1" - if [[ "$KERNEL_VERSION" =~ \.debug$ ]]; then - KERNEL_CHECK=$(sed -e 's/\.debug$//' <<<$KERNEL_VERSION) - # KERNEL_DEVEL="debug-devel-$KERNEL_CHECK" - echo "System is running with a non supported kernel debug version: $KERNEL_VERSION" - echo "To be able to build the AFS kernel-module the system needs to be running with a normal kernel like: kernel-$KERNEL_CHECK" - echo - exit 1 - else - KERNEL_CHECK=$KERNEL_VERSION - KERNEL_DEVEL="devel-$KERNEL_VERSION" - fi - if [ -n "$KERNEL_CHECK" ]; then - if ! { rpm -q kernel-headers-$KERNEL_CHECK kernel-$KERNEL_DEVEL; } >/dev/null 2>&1; then - echo "Needed packages for running kernel $KERNEL_VERSION missing: kernel-headers-$KERNEL_CHECK kernel-$KERNEL_DEVEL" - echo "Try to install..." - yum --nogpgcheck -q -y install kernel-headers-$KERNEL_CHECK kernel-$KERNEL_DEVEL - CHKKERNELPACK="false" - fi - fi -} - -check_kernelmodule() { - KERNEL_VERSION=$(uname -r) - if dkms_check; then - OPENAFS_VERSION_FULL=$(rpm --queryformat '%{PROVIDEVERSION}' -q openafs) - DKMSSTATUS=$(dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION") - if echo "${DKMSSTATUS}" | egrep 'installed-weak|Diff between built and installed module' >/dev/null; then - echo - echo "Weak module detected, will be removed.." - echo "DKMS stuff ..." - dkms remove "$AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL" -k "$KERNEL_VERSION" --no-initrd - if [ -h /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko ]; then - TARGETLINK=$(readlink -f /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko) - rm -fv /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko - fi - if [ -h /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko.xz ]; then - TARGETLINKXZ=$(readlink -f /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko.xz) - rm -fv /lib/modules/"$KERNEL_VERSION"/weak-updates/${AFS_KERNEL_MODULE}.ko.xz - fi - echo - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - if ! dkms install "$AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL" -k "$KERNEL_VERSION" --no-initrd; then - echo "DKMS install problem for $AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL $KERNEL_VERSION, will try to relink from other kernel version..." - if [ -n "$TARGETLINK" ]; then - if [ -f "$TARGETLINK" ]; then - echo "Using $TARGETLINK" - ln -s "$TARGETLINK" "/lib/modules/$KERNEL_VERSION/weak-updates/${AFS_KERNEL_MODULE}.ko" - fi - fi - if [ -n "$TARGETLINKXZ" ]; then - if [ -n "$TARGETLINKXZ" ]; then - echo "Using $TARGETLINKXZ" - ln -s "$TARGETLINKXZ" "/lib/modules/$KERNEL_VERSION/weak-updates/${AFS_KERNEL_MODULE}.ko.xz" - fi - fi - fi - DKMSSTATUS=$(dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION") - fi - if echo "${DKMSSTATUS}" | grep '(original_module exists)' >/dev/null; then - echo "DKMS (original_module exists) problem detected, try to fix: /var/lib/dkms/openafs/original_module/$KERNEL_VERSION" - if [ -d /var/lib/dkms/openafs/original_module/"$KERNEL_VERSION" ]; then - \rm -r /var/lib/dkms/openafs/original_module/"$KERNEL_VERSION" - DKMSSTATUS=$(dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION") - fi - fi - if ! echo "${DKMSSTATUS}" | grep ': installed$' >/dev/null; then - echo - echo "No kernel-module detected for $AFS_KERNEL_MODULE version $OPENAFS_VERSION_FULL and kernel $KERNEL_VERSION .." - echo "DKMS stuff ..." - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - if ! dkms install "$AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL" -k "$KERNEL_VERSION" --no-initrd; then - echo "DKMS install problem for $AFS_KERNEL_MODULE/$OPENAFS_VERSION_FULL $KERNEL_VERSION" - return 1 - fi - fi - return 0 - fi - - modprobe $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - [ $RETVAL -eq 0 ] && return 0 # Kernel module loaded, continue... - - echo - echo $"Failed to load kernel module, attempting rebuild.." - warning $"Failed to load kernel module, attempting rebuild.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 1 - } - fi - echo - - KMOD_BUILDLOG=/tmp/openafs-kmod-build-$(date +%Y%m%d-%H%M).log - - echo "Build log for OpenAFS module: $(date)" >$KMOD_BUILDLOG - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - - if [ -d /usr/src/openafs-kernel-$OPENAFS_VERSION/src ] && [ -f /usr/src/openafs-kernel-$OPENAFS_VERSION/src/configure ]; then - cd /usr/src/openafs-kernel-$OPENAFS_VERSION/src || return 1 - - make clean >>$KMOD_BUILDLOG 2>&1 - - ./configure --with-linux-kernel-headers=/lib/modules/$KERNEL_VERSION/build >>$KMOD_BUILDLOG 2>&1 - make -j4 >>$KMOD_BUILDLOG 2>&1 - if [ $? -eq 0 ]; then - MODULEDIR=/lib/modules/$KERNEL_VERSION/kernel/fs/openafs - [ ! -d $MODULEDIR ] && mkdir $MODULEDIR - - for file in src/libafs/MODLOAD-$KERNEL_VERSION-*/openafs.ko; do - if [ -f "$file" ]; then - cp "$file" $MODULEDIR/ - ln $MODULEDIR/openafs.ko $MODULEDIR/libafs.ko - break - else - cp src/libafs/MODLOAD-$KERNEL_VERSION-*/libafs.ko $MODULEDIR/ - fi - done - - depmod -a - modprobe $AFS_KERNEL_MODULE >>$KMOD_BUILDLOG 2>&1 - RETVAL=$? - else - RETVAL=1 - fi - [ $RETVAL -eq 0 ] && rm -f $KMOD_BUILDLOG && echo -n "Build succeded!" && success "Build succeded!" && echo && return 0 - - echo "Failed to build kernel module, see $KMOD_BUILDLOG for more details." - echo - return 1 - else - echo "OpenAFS Kernel source not installed." - echo - return 1 - fi -} - -rm_wrong_module() { - # Only needed if dkms is not used - if dkms_check; then - return 0 - fi - KERNEL_VERSION=$(uname -r) - module="$(modinfo -F filename $AFS_KERNEL_MODULE 2>/dev/null)" - if [ -f "$module" ]; then - mod_version=$(strings $module | awk '{ for (i=1; i $pkg_version" - fi - fi -} - -package_update() { - if [ "$UPDATE" == "true" ]; then - echo "Checking for OpenAFS updates.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 1 - } - fi - echo - yum --nogpgcheck -q clean all >/dev/null - yum --nogpgcheck -q check-update openafs >/dev/null - RETVAL=$? - if [ "$RETVAL" -eq "100" ]; then - echo "Upgrading OpenAFS" - if [ "$DKMS" == "true" ]; then - yum --nogpgcheck -q -y install openafs openafs-client openafs-docs openafs-krb5 openafs-compat dkms-openafs dkms - else - yum --nogpgcheck -q -y install openafs openafs-client openafs-docs openafs-krb5 openafs-compat openafs-kernel-source - fi - echo "Done" - fi - fi -} - -start() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - echo -n $"Starting openafs-client: " - if [ -e /var/lock/subsys/openafs-client ]; then - echo $"cannot start openafs-client: already running" - echo - return 1 - fi - if [ "$DKMS" == "true" ]; then - AFS_KERNEL_MODULE=openafs - # Check if no dkms session is running already - if { pgrep -f "dkms .* -m $AFS_KERNEL_MODULE"; } >/dev/null 2>&1; then - echo "A dkms-session is running to install/remove $AFS_KERNEL_MODULE, will exit now." - exit 1 - fi - fi - # A configured yum repository is needed for the package-update - package_update - rm_wrong_module - if check_kernelmodule; then - echo -n $"Updating CellServDB: " - cat /usr/vice/etc/CellServDB.local /usr/vice/etc/CellServDB.dist >/usr/vice/etc/CellServDB - - chmod 644 /usr/vice/etc/CellServDB - echo - if [ "$CLEANCACHE" == "true" ]; then - if [ "${CACHEDIR}" == "/usr/vice/cache" ] || [ "${CACHEDIR}" == "/var/cache/openafs" ]; then - if [ -d ${CACHEDIR} ]; then - echo $"Cleaning up cache area ${CACHEDIR}/ ..." - rm -rf ${CACHEDIR:?}/* - fi - else - echo $"Cache area CACHEDIR ${CACHEDIR} not set correctly for cleanup-job in startup-script." - fi - fi - - # Only needed if dkms is used - if dkms_check; then - modprobe $AFS_KERNEL_MODULE - RETVAL=$? - if [ $RETVAL -ne 0 ]; then - echo $"failed to load openafs kernel module." - echo - return $RETVAL - fi - fi - - $DAEMON_BIN $AFSD_ARGS - RETVAL=$? - echo - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/openafs-client - [ $RETVAL -eq 0 ] && [ "$AFS_POST_INIT" ] && $AFS_POST_INIT - if [ $RETVAL -eq 0 ]; then - setsysname - setsuid - setnocrypt - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - ( - sleep 60 - [ -x $SETSERVERPREFS ] && $SETSERVERPREFS - ) /dev/null 2>&1 & - fi - return $RETVAL - else - echo $"failed to load openafs kernel module." - echo - return 1 - fi -} - -stop() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - echo -n $"Stopping openafs-client: " - if [ ! -e /var/lock/subsys/openafs-client ]; then - echo $"cannot stop openafs-client: not running" - echo - return 1 - fi - if [ "$DKMS" == "true" ]; then - AFS_KERNEL_MODULE=openafs - fi - umount $AFS - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - $DAEMON_BIN -shutdown - lsmod | grep -w $AFS_KERNEL_MODULE >/dev/null - if [ $? -ne 0 ]; then - AFS_KERNEL_MODULE=$(lsmod | awk '/afs/ {print $1}') - fi - rmmod $AFS_KERNEL_MODULE - RETVAL=$? - fi - if [ $RETVAL -eq 0 ]; then - rm -f /var/lock/subsys/openafs-client - fi - return $RETVAL -} - -stop-force() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - echo -n $"Stopping openafs-client: " - if [ ! -e /var/lock/subsys/openafs-client ]; then - echo $"cannot stop openafs-client: not running" - echo - return 1 - fi - if pgrep -xf 'afsd' &>/dev/null; then - echo - echo "Sending all processes using $AFS the TERM signal ..." - killafs TERM - echo "Sending all processes using $AFS the KILL signal ..." - killafs KILL - fi - if dkms_check; then - AFS_KERNEL_MODULE=openafs - fi - umount $AFS - RETVAL=$? - echo - if [ $RETVAL -eq 0 ]; then - $DAEMON_BIN -shutdown - lsmod | grep -w $AFS_KERNEL_MODULE >/dev/null - if [ $? -ne 0 ]; then - AFS_KERNEL_MODULE=$(lsmod | awk '/afs/ {print $1}') - fi - rmmod $AFS_KERNEL_MODULE - RETVAL=$? - fi - if [ $RETVAL -eq 0 ]; then - rm -f /var/lock/subsys/openafs-client - fi - return $RETVAL -} - -rhstatus() { - status afsd - return $? -} - -check() { - echo -n $"Checking openafs-client: " - if [ ! -e /var/lock/subsys/openafs-client ]; then - echo $"cannot check openafs-client: not running" - echo - return 1 - fi - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -x $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo $"Check-script not available: $HEALTHCHECK" - echo - return 1 - fi -} - -restart() { - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - stop || exit - start -} - -case "$1" in - start) - start - ;; - stop) - stop - ;; - stop-force) - stop-force - ;; - restart) - restart - ;; - status) - rhstatus - exit $? - ;; - check) - check - ;; - condrestart) - [ -f /var/lock/subsys/openafs-client ] && restart || : - ;; - *) - echo $"Usage: $0 {start|stop|stop-force|status|check|restart|condrestart}" - exit 1 - ;; -esac - -exit $? diff --git a/files/openafs-client-RedHat-systemd-exec.service b/files/openafs-client-RedHat-systemd-exec.service deleted file mode 100644 index 8045da1..0000000 --- a/files/openafs-client-RedHat-systemd-exec.service +++ /dev/null @@ -1,19 +0,0 @@ -[Unit] -Description=OpenAFS Client Service -Wants=network-online.target -After=syslog.target network-online.target -Before=remote-fs.target - -[Service] -Type=forking -Restart=no -TimeoutSec=25min -IgnoreSIGPIPE=no -KillMode=none -GuessMainPID=no -RemainAfterExit=yes -ExecStart=/usr/vice/etc/systemd-exec.openafs-client start -ExecStop=/usr/vice/etc/systemd-exec.openafs-client stop - -[Install] -WantedBy=multi-user.target remote-fs.target diff --git a/files/openafs-client-RedHat-systemd-sysv.service b/files/openafs-client-RedHat-systemd-sysv.service deleted file mode 100644 index 05a550f..0000000 --- a/files/openafs-client-RedHat-systemd-sysv.service +++ /dev/null @@ -1,20 +0,0 @@ -[Unit] -SourcePath=/etc/rc.d/init.d/openafs-client -Description=SYSV: OpenAFS Client Service -Wants=network-online.target -After=syslog.target network-online.target -Before=remote-fs.target - -[Service] -Type=forking -Restart=no -TimeoutSec=25min -IgnoreSIGPIPE=no -KillMode=none -GuessMainPID=no -RemainAfterExit=yes -ExecStart=/etc/rc.d/init.d/openafs-client start -ExecStop=/etc/rc.d/init.d/openafs-client stop - -[Install] -WantedBy=multi-user.target remote-fs.target diff --git a/files/openafs-client-Solaris b/files/openafs-client-Solaris deleted file mode 100755 index be926e3..0000000 --- a/files/openafs-client-Solaris +++ /dev/null @@ -1,276 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2020 AFS-Core Ericsson -# Version v1.13, 2020-01-10 -# -# openafs-client Start/Stop the OpenAFS Client -# rc script for AFS on Solaris 8/9/10/11 or OpenSolaris-based platforms -# -# - -DAEMON="OpenAFS Client" -DAEMON_BIN=/usr/vice/etc/afsd -CONFIG=/usr/vice/etc/sysconfig -AFSDOPT=$CONFIG/openafs-client -AFS=/afs -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/usr/vice/etc/SuidCells -DRVFS="" -TRUE=0 -FALSE=1 - -[ -f $AFSDOPT ] && . $AFSDOPT - -# Set the minimum required options for afsd if no options set in $AFSDOPT -AFSD_ARGS=${AFSD_ARGS:-"-dynroot -afsdb"} - -# Need the commands pgrep, awk, fs -PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/proc/bin:/usr/afsws/bin:/usr/afsws/etc:/usr/afs/bin:/usr/afs/etc:/opt/afssw/bin:/opt/afssw/etc:/usr/afsw/bin:/usr/afsw/sbin:/usr/afsw/etc:/usr/vice/bin:/usr/vice/etc -export PATH - -setsuid() { - if [ -f $SUIDCELLS ]; then - for CELLS in `grep '^[^#]' $SUIDCELLS`; do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -get_cell() { - CELL=`fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/"` - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -setsysname() { - if { SYS=`sys`; } >/dev/null 2>&1; then - ADDSYS=`echo "$SYS" | sed -n 's/_511$/_510/p'` - if [ -n "$ADDSYS" ]; then - echo "Setting sysname: $SYS $ADDSYS" - fs sysname "$SYS" "$ADDSYS" >/dev/null - fi - fi -} - -chkafsd() { - if pgrep -u 0 -x afsd >/dev/null; then - return ${TRUE} - else - return ${FALSE} - fi -} - -issol11() { - case `uname -r` in - 5.?|5.10) return ${FALSE};; - 5.??) return ${TRUE};; - esac - echo "unsupported OS" - exit 1 -} - -case $1 in - 'start') - # Not starting afsd on containers (non global zone) - if uname -v | grep Virtual >/dev/null || { zonename; } 2>/dev/null | fgrep -vx global >/dev/null; then - echo "Solaris Non-Global Zone: afsd will not start and is not needed !" - exit - fi - - if issol11; then - DRVFS=drv - else - DRVFS=fs - # - # Make sure afs exists in /etc/name_to_sysnum - # - if grep -s "afs" /etc/name_to_sysnum > /dev/null; then - echo "Entry for afs already exists in /etc/name_to_sysnum" - else - echo "Creating entry for afs in /etc/name_to_sysnum" - cp /etc/name_to_sysnum /etc/name_to_sysnum.orig - sed '/nfs/i\ - afs 65' /etc/name_to_sysnum > /tmp/name_to_sysnum - mv /tmp/name_to_sysnum /etc/name_to_sysnum - echo "Reboot the system now for new /etc/name_to_sysnum to take effect" - #reboot - fi - fi - - ## Check to see that /bin/isalist exists and is executable - if { ! isalist; } >/dev/null 2>&1; then - echo "isalist not available" - exit 1; - fi - - ## Determine if we are running the 64 bit OS - ## If sparcv9 then the location of the afs and nfs extensions differ - - case `isalist` in - *amd64* ) - nfssrv=/kernel/misc/amd64/nfssrv - afs=/kernel/$DRVFS/amd64/afs ;; - *sparcv9* ) - nfssrv=/kernel/misc/sparcv9/nfssrv - afs=/kernel/$DRVFS/sparcv9/afs ;; - * ) - nfssrv=/kernel/misc/nfssrv - afs=/kernel/$DRVFS/afs ;; - esac - - - # - # Load kernel extensions - # - # nfssrv has to be loaded first - - - if [ -f $nfssrv ]; then - echo "Loading NFS server kernel extensions" - modload $nfssrv - else - echo "$nfssrv does not exist. Skipping AFS startup." - exit 1 - fi - - ## Load AFS kernel extensions - - if [ -f $afs ]; then - echo "Loading AFS kernel extensions" - if issol11; then - if [ -f /kernel/drv/afs.conf ] ; then - echo "Kernel afs.conf already exists" - else - echo "Creating kernel afs.conf" - echo 'name="afs" parent="pseudo";' > /kernel/drv/afs.conf - fi - # load the module - if grep '^afs ' /etc/name_to_major >/dev/null ; then - echo "Loading AFS kernel extensions" - modload $afs - # this can sometimes be necessary to get the /devices afs device to attach - update_drv afs - else - echo "Installing AFS driver and loading kernel extensions" - add_drv -m '* 0666 root root' afs - fi - - # Create the /dev/afs link - if grep name=afs /etc/devlink.tab >/dev/null ; then - echo "Entry for afs already exists in /etc/devlink.tab" - else - echo "Adding entry for afs in /etc/devlink.tab" - print "type=ddi_pseudo;name=afs;addr=0;minor=afs\t\D" >> /etc/devlink.tab - devfsadm - fi - else - modload $afs - fi - else - echo "$afs does not exist. Skipping AFS startup." - exit 1 - fi - - # - # Check that all of the client configuration files exist - # - - for file in /usr/vice/etc/afsd /usr/vice/etc/cacheinfo \ - /usr/vice/etc/ThisCell /usr/vice/etc/CellServDB - do - if [ ! -f ${file} ]; then - echo "${file} does not exist. Not starting AFS client." - exit 1 - fi - done - - # - # Check that the root directory for AFS (/afs) - # and the cache directory (/usr/vice/cache) both exist - # - - for dir in `awk -F: '{print $1, $2}' /usr/vice/etc/cacheinfo` - do - if [ ! -d ${dir} ]; then - echo "${dir} does not exist. Not starting AFS client." - exit 2 - fi - done - - echo "Starting $DAEMON " - if chkafsd; then - echo " -> already running" - else - $DAEMON_BIN $AFSD_ARGS - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - setsuid - setnocrypt - if issol11; then - setsysname - fi - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - (sleep 60; [ -x $SETSERVERPREFS ] && $SETSERVERPREFS) /dev/null 2>&1 & - fi - fi - - echo ;; - - 'stop') - - # - # Stop the AFS client - # Note that the afsd processes cannot be killed - # - echo "Stopping openafs-client: " - if chkafsd; then - umount $AFS - RETVAL=$? - echo - if [ $RETVAL -eq 0 ] ; then - $DAEMON_BIN -shutdown - MODID=`modinfo -c | awk '/ afs / {print $1}'` - modunload -i $MODID - RETVAL=$? - if [ $RETVAL -eq 0 ] ; then - echo "Kernel module afs unloaded " - else - echo "Problems to unload kernel module " - fi - fi - else - echo " -> $DAEMON not running" - fi - echo ;; - - 'check') - # - # Check the running AFS client - # - - echo "Checking openafs-client: " - if chkafsd; then - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -f $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo "Check-script not available: $HEALTHCHECK" - fi - else - echo "Cannot check openafs-client: not running" - fi - echo ;; - - *) - echo "Usage: $0 {start|stop|check}" - exit 1;; -esac diff --git a/files/openafs-client-Suse-init b/files/openafs-client-Suse-init deleted file mode 100755 index 49c8ab5..0000000 --- a/files/openafs-client-Suse-init +++ /dev/null @@ -1,525 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2020 AFS-Core Ericsson -# Version v1.23, 2020-07-15 -# -# System startup script for OpenAFS -# -### BEGIN INIT INFO -# chkconfig: 2345 50 50 -# Provides: afs-client -# Required-Start: $local_fs $named $network $remote_fs -# Should-Start: $syslog -# Should-Stop: $null -# Required-Stop: $null -# Default-Start: 3 5 -# Default-Stop: 0 2 1 6 -# Short-Description: Start OpenAFS Client -# Description: Starts the OpenAFS Client by loading the required kernel-module and starting afsd. -### END INIT INFO - -DAEMON="OpenAFS Client" -DAEMON_BIN=/usr/sbin/afsd -AFS_KERNEL_MODULE=libafs -AFS=/afs -CACHEDIR=/var/cache/openafs -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/etc/openafs/SuidCells -LOCKFILE="/var/lock/$(basename $0)" -LOCKFD=99 - -PATH=/sbin:/bin:/usr/bin:/usr/sbin -export PATH - -#test -x $DAEMON_BIN || exit 5 - -# Shell functions sourced from /etc/rc.status: -# rc_check check and set local and overall rc status -# rc_status check and set local and overall rc status -# rc_status -v ditto but be verbose in local rc status -# rc_status -v -r ditto and clear the local rc status -# rc_failed set local and overall rc status to failed -# rc_failed set local and overall rc status to -# rc_reset clear local rc status (overall remains) -# rc_exit exit appropriate to overall rc status -. /etc/rc.status - -[ -f /etc/sysconfig/openafs-client ] && . /etc/sysconfig/openafs-client - -# Set the minimum required options for afsd if no options set in /etc/sysconfig/openafs-client -AFSD_ARGS=${AFSD_ARGS:-"-dynroot -afsdb"} -UPDATE=${UPDATE:-"false"} -CHKKERNELPACK=${CHKKERNELPACK:-"true"} -CLEANCACHE=${CLEANCACHE:-"false"} - -noroot_check() { - if [ "$(whoami | awk '{print $1}' | cut -f2 -d\!)" != "root" ]; then - return 0 - else - return 1 - fi -} - -# Lock -lock_routine() { - if { flock -h; } >/dev/null 2>&1; then - # Older versions of flock do not support -x option - flock -x 1>/dev/null 2>/dev/null - if [ $? -ne 1 ]; then - _lock() { flock -$1 $LOCKFD; } - _no_more_locking() { - _lock u - _lock xn && rm -f $LOCKFILE - } - _prepare_locking() { - eval "exec $LOCKFD>\"$LOCKFILE\"" - trap _no_more_locking EXIT - } - exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail - exlock() { _lock x; } # obtain an exclusive lock - shlock() { _lock s; } # obtain a shared lock - unlock() { _lock u; } # drop a lock - _prepare_locking - return 0 - fi - else - return 1 - fi -} - -setsuid() { - if [ -f $SUIDCELLS ]; then - while read -r CELLS; do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done <<<"$(grep '^[^#]' $SUIDCELLS)" - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -firstint() { - sed 's/^[^0-9]*//; s/[^0-9].*//' -} - -get_cell() { - CELL=$(fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/") - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -get_dist_release() { - if LsbDistributor=$(lsb_release -si 2>/dev/null); then - LsbDescription=$(lsb_release -sd) - LsbRelease=$(lsb_release -sr | cut -d . -f -2) - case $LsbDistributor in - "SUSE"*) - if [[ $LsbDescription == *openSUSE* ]]; then - OS="openSuse" - _DIST="osuse" - else - OS=$(echo "$LsbDescription" | cut -f1-4 -d" " | sed -e 's/\([a-zA-Z]\)[^ ]* */\1/g' -e 's/"//') - _DIST="sle" - if [[ $LsbRelease != *.* ]]; then - patchlevel=$(awk '/^PATCHLEVEL/ {print $3}' /etc/SuSE-release 2>/dev/null) - LsbRelease=${LsbRelease}.${patchlevel:-0} - fi - fi - ;; - "RedHatEnterprise"* | "CentOS"*) - OS="RedHat" - _DIST="rhel" - ;; - "Ubuntu"*) - OS="Ubuntu" - _DIST="ubunt" - ;; - "Debian"*) - OS="Debian" - _DIST="deb" - ;; - "Fedora"*) - _DIST="fc" - ;; - *) - echo "Distribution not detected or not supported" - return - ;; - esac - Release="${LsbRelease}" - elif [ -f /etc/redhat-release ]; then - Release=$( - sed -n ' - /Red Hat Enterprise /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - /CentOS /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - ' /etc/redhat-release - ) - OS="RedHat" - _DIST="rhel" - fi -} - -setsysname() { - _ARCH=$(uname -i | sed 's/x86_64/amd64/') - _DIST="" - _VER="" - - get_dist_release - case "$_DIST" in - fc | deb) - return - ;; - esac - _VER=$(echo "$Release" | firstint) - # Sysname list. The order here is from specific to general, with a - # fallback to the compiled-in value from sys. This will be - # used as the sysname search path. - if { SYS=$(sys); } >/dev/null 2>&1; then - if [ -n "$_VER" ]; then - SYSNAMELIST="${_ARCH}_${_DIST}${_VER} $SYS" - fi - fi - - # Set the sysname - if [ -n "$SYSNAMELIST" ]; then - SYSNAME=$(echo "$SYSNAMELIST" | awk 'BEGIN {ORS=" "} { for (i=1;i<=NF;i+=1) print "-newsys",$i }') - _CMD="fs sysname $SYSNAME" - echo "Setting sysname: $SYSNAMELIST" - $_CMD >/dev/null - fi -} - -killafs() { - SIGNAL=$1 - PIDS=$(lsof -Fp $AFS | sed -e 's/p//') - if [ -n "$PIDS" ]; then - kill -$SIGNAL $PIDS >/dev/null 2>&1 - sleep 3 - fi -} - -check_kernelpackages() { - KERNEL_VERSION="$1" - # Output from `uname -r` does not match package version. Get it by checking vmlinuz image - KERNEL_PKG=$(rpm -qf /boot/vmlinuz-${KERNEL_VERSION}) - KERNEL_PKG_VERSION=$(rpm -q --queryformat '%{version}-%{release}' "${KERNEL_PKG}") - # Get kernel type such as: xen, trace etc. - KERNEL_TYPE=$(echo $KERNEL_PKG | cut -d- -f2) - - if [ -f /etc/os-release ]; then - FULL_RELEASE=$(awk -F'"' '/VERSION_ID/ { print $2 }' /etc/os-release) - MAJOR_RELEASE=$(echo $FULL_RELEASE | cut -d. -f1) - MINOR_RELEASE=$(echo $FULL_RELEASE | cut -d. -f2) - else - MAJOR_RELEASE=$(awk '/VERSION/ { print $3 }' /etc/SuSE-release) - MINOR_RELEASE=$(awk '/PATCHLEVEL/ { print $3 }' /etc/SuSE-release) - fi - - if [ $MAJOR_RELEASE -ge 12 ]; then - PKG_ARGS="--oldpackage" - KERNEL_PACKAGES="kernel-${KERNEL_TYPE}-devel-${KERNEL_PKG_VERSION} kernel-devel-${KERNEL_PKG_VERSION}" - elif [ $MAJOR_RELEASE -ge 11 ] && [ $MINOR_RELEASE -ge 1 ]; then - PKG_ARGS="--oldpackage" - KERNEL_PACKAGES="kernel-${KERNEL_TYPE}-devel-${KERNEL_PKG_VERSION} kernel-source-${KERNEL_PKG_VERSION}" - else - PKG_ARGS="" - KERNEL_PACKAGES="kernel-source-${KERNEL_PKG_VERSION}" - fi - - if ! { rpm -q $KERNEL_PACKAGES; } >/dev/null 2>&1; then - echo "Needed packages for running kernel ${KERNEL_VERSION} missing: ${KERNEL_PACKAGES}" - echo "Try to install..." - zypper -q install -y ${PKG_ARGS} ${KERNEL_PACKAGES} - fi -} - -check_kernelmodule() { - modprobe --allow-unsupported-modules -V $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - MODPROBEOPT="--allow-unsupported-modules" - else - MODPROBEOPT="" - fi - modprobe $MODPROBEOPT $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - [ $RETVAL -eq 0 ] && return 0 # Kernel module loaded, continue... - echo -n "Attempting to recompile kernel module..." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 0 - } - fi - echo - KERNEL_VERSION=$(uname -r) - KMOD_BUILDLOG=/tmp/openafs-kmod-build-$(date +%Y%m%d-%H%M).log - echo "Build log for OpenAFS module: $(date)" >$KMOD_BUILDLOG - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - - if [ -d /usr/src/kernel-modules/openafs/libafs_tree ]; then - cd /usr/src/kernel-modules/openafs/libafs_tree || return 1 - make clean >>$KMOD_BUILDLOG 2>&1 - ./configure --with-linux-kernel-headers=/lib/modules/$KERNEL_VERSION/build >>$KMOD_BUILDLOG 2>&1 - make -j4 >>$KMOD_BUILDLOG 2>&1 - if [ $? -eq 0 ]; then - MODULEDIR=/lib/modules/$KERNEL_VERSION/kernel/fs/openafs - if [ -d $MODULEDIR ]; then # Clean out any occurance of old modules. - rm -rf $MODULEDIR - fi - mkdir $MODULEDIR - cp src/libafs/MODLOAD-$KERNEL_VERSION-*/libafs.ko $MODULEDIR/libafs.ko - ln $MODULEDIR/libafs.ko $MODULEDIR/openafs.ko - depmod -a >>$KMOD_BUILDLOG 2>&1 - modprobe $MODPROBEOPT $AFS_KERNEL_MODULE >>$KMOD_BUILDLOG 2>&1 - RETVAL=$? - else - RETVAL=1 - fi - echo - [ $RETVAL -eq 0 ] && rm -f $KMOD_BUILDLOG && echo "Build succeded!" && return 0 - echo - echo "Failed to build kernel module." - echo -n "See $KMOD_BUILDLOG for more details." - return 1 - else - echo - echo -n "OpenAFS Kernel source not installed." - return 1 - fi -} - -rm_wrong_module() { - module="$(modinfo -F filename $AFS_KERNEL_MODULE 2>/dev/null)" - if [ -f "$module" ]; then - mod_version=$(strings $module | awk '{ for (i=1; i $pkg_version" - fi - fi -} - -package_update() { - if [ "$UPDATE" == "true" ]; then - echo "Checking for OpenAFS updates.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 0 - } - fi - echo - zypper --no-gpg-checks refresh - package_status=$(zypper --no-gpg-checks info openafs 2>/dev/null | grep ^Status | cut -d: -f2 | awk '{print $1}') - if [ "$package_status" == "out-of-date" ]; then - echo "Upgrading OpenAFS" - zypper -q -V >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - # --allow-vendor-change - ZYPPEROPTS="-q" - else - ZYPPEROPTS="" - fi - zypper --no-gpg-checks $ZYPPEROPTS -n in openafs openafs-docs openafs-krb5-mit openafs-client openafs-kernel-source 2>/dev/null - # Make a clean cache in case of package upgrades, even if option is not set. - if [ "$CLEANCACHE" != "true" ]; then - if [ "${CACHEDIR}" == "/usr/vice/cache" ] || [ "${CACHEDIR}" == "/var/cache/openafs" ]; then - if [ -d ${CACHEDIR} ]; then - echo "Cleaning up cache area ${CACHEDIR}/ ..." - rm -rf ${CACHEDIR:?}/* - fi - else - echo "Cache area CACHEDIR ${CACHEDIR} not set correctly for cleanup-job in startup-script." - fi - fi - fi - fi -} - -# First reset status of this service -rc_reset - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - insufficient privilege -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signalling is not supported) are -# considered a success. - -case "$1" in - start) - if noroot_check; then - echo "Script has to be run as root" - exit 4 - fi - echo "Starting $DAEMON " - mkdir -p $AFS - if grep -q ^$AFS_KERNEL_MODULE /proc/modules; then - echo -n " -> $DAEMON already running " - else - # A configured zypper repository is needed for the package-update - package_update - rm_wrong_module - if check_kernelmodule; then - if ! pgrep -xf 'afsd' &>/dev/null; then - if [ "$CLEANCACHE" == "true" ]; then - if [ "${CACHEDIR}" == "/usr/vice/cache" ] || [ "${CACHEDIR}" == "/var/cache/openafs" ]; then - if [ -d ${CACHEDIR} ]; then - echo "Cleaning up cache area ${CACHEDIR}/ ..." - rm -rf ${CACHEDIR:?}/* - fi - else - echo "Cache area CACHEDIR ${CACHEDIR} not set correctly for cleanup-job in startup-script." - fi - fi - $DAEMON_BIN $AFSD_ARGS - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - setsysname - setsuid - setnocrypt - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - ( - sleep 60 - [ -x $SETSERVERPREFS ] && $SETSERVERPREFS - ) /dev/null 2>&1 & - else - rc_failed 1 - fi - fi - else - #modprobe failed - rc_failed 5 - fi - fi - # Remember status and be verbose - rc_status -v - ;; - stop) - if noroot_check; then - echo "Script has to be run as root" - exit 4 - fi - echo -n "Shutting down $DAEMON " - if pgrep -xf 'afsd' &>/dev/null; then - umount $AFS - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - $DAEMON_BIN -shutdown - fi - else - echo -n " -> $DAEMON not running " - RETVAL=0 - fi - if [ $RETVAL -eq 0 ]; then - if grep -q ^$AFS_KERNEL_MODULE /proc/modules; then - rmmod $AFS_KERNEL_MODULE || rc_failed 1 - fi - else - rc_failed 1 - fi - # rmtsys doesn't go away, so kill them all to be sure - #killall $DAEMON_BIN > /dev/null 2>&1 - # Remember status and be verbose - rc_status -v - ;; - stop-force) - if noroot_check; then - echo "Script has to be run as root" - exit 4 - fi - echo -n "Shutting down $DAEMON " - if pgrep -xf 'afsd' &>/dev/null; then - echo - echo "Sending all processes using $AFS the TERM signal ..." - killafs TERM - echo "Sending all processes using $AFS the KILL signal ..." - killafs KILL - umount $AFS - $DAEMON_BIN -shutdown - fi - if grep -q ^$AFS_KERNEL_MODULE /proc/modules; then - rmmod $AFS_KERNEL_MODULE || rc_failed 1 - fi - # rmtsys doesn't go away, so kill them all to be sure - #killall $DAEMON_BIN > /dev/null 2>&1 - # Remember status and be verbose - rc_status -v - ;; - try-restart) - ## Stop the service and if this succeeds (i.e. the - ## service was running before), start it again. - $0 stop && $0 start - - # Remember status and be quiet - rc_status - ;; - restart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - $0 stop - $0 start - - # Remember status and be quiet - rc_status - ;; - status) - echo -n "Checking for $DAEMON: " - ## Check status with checkproc(8), if process is running - ## checkproc will return with exit status 0. - - # Status has a slightly different for the status command: - # 0 - service running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running - - # NOTE: checkproc returns LSB compliant status values. - - pgrep -xf 'afsd' &>/dev/null || rc_failed 3 - - rc_status -v - ;; - check) - echo -n "Checking $DAEMON " - if pgrep -xf 'afsd' &>/dev/null; then - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -x $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo -n $"Check-script not available: $HEALTHCHECK" - echo - RETVAL=1 - fi - else - echo -n " -> $DAEMON not running " - RETVAL=0 - fi - ;; - *) - echo "Usage: $0 {start|stop|stop-force|status|check|try-restart|restart}" - exit 1 - ;; -esac -rc_exit diff --git a/files/openafs-client-Suse-systemd-exec b/files/openafs-client-Suse-systemd-exec deleted file mode 100755 index 65d4320..0000000 --- a/files/openafs-client-Suse-systemd-exec +++ /dev/null @@ -1,513 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2020 AFS-Core Ericsson -# Version v1.23, 2020-07-15 -# -# systemd-exec.openafs-client native system exec-script -# - -DAEMON="OpenAFS Client" -DAEMON_BIN=/usr/sbin/afsd -AFS_KERNEL_MODULE=libafs -AFS=/afs -CACHEDIR=/var/cache/openafs -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/etc/openafs/SuidCells -LOCKFILE="/var/lock/$(basename $0)" -LOCKFD=99 - -PATH=/sbin:/bin:/usr/bin:/usr/sbin -export PATH - -#test -x $DAEMON_BIN || exit 5 - -# Shell functions sourced from /etc/rc.status: -# rc_check check and set local and overall rc status -# rc_status check and set local and overall rc status -# rc_status -v ditto but be verbose in local rc status -# rc_status -v -r ditto and clear the local rc status -# rc_failed set local and overall rc status to failed -# rc_failed set local and overall rc status to -# rc_reset clear local rc status (overall remains) -# rc_exit exit appropriate to overall rc status -. /etc/rc.status - -[ -f /etc/sysconfig/openafs-client ] && . /etc/sysconfig/openafs-client - -# Set the minimum required options for afsd if no options set in /etc/sysconfig/openafs-client -AFSD_ARGS=${AFSD_ARGS:-"-dynroot -afsdb"} -UPDATE=${UPDATE:-"false"} -CHKKERNELPACK=${CHKKERNELPACK:-"true"} -CLEANCACHE=${CLEANCACHE:-"false"} - -noroot_check() { - if [ "$(whoami | awk '{print $1}' | cut -f2 -d\!)" != "root" ]; then - return 0 - else - return 1 - fi -} - -# Lock -lock_routine() { - if { flock -h; } >/dev/null 2>&1; then - # Older versions of flock do not support -x option - flock -x 1>/dev/null 2>/dev/null - if [ $? -ne 1 ]; then - _lock() { flock -$1 $LOCKFD; } - _no_more_locking() { - _lock u - _lock xn && rm -f $LOCKFILE - } - _prepare_locking() { - eval "exec $LOCKFD>\"$LOCKFILE\"" - trap _no_more_locking EXIT - } - exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail - exlock() { _lock x; } # obtain an exclusive lock - shlock() { _lock s; } # obtain a shared lock - unlock() { _lock u; } # drop a lock - _prepare_locking - return 0 - fi - else - return 1 - fi -} - -setsuid() { - if [ -f $SUIDCELLS ]; then - while read -r CELLS; do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done <<<"$(grep '^[^#]' $SUIDCELLS)" - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -firstint() { - sed 's/^[^0-9]*//; s/[^0-9].*//' -} - -get_cell() { - CELL=$(fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/") - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -get_dist_release() { - if LsbDistributor=$(lsb_release -si 2>/dev/null); then - LsbDescription=$(lsb_release -sd) - LsbRelease=$(lsb_release -sr | cut -d . -f -2) - case $LsbDistributor in - "SUSE"*) - if [[ $LsbDescription == *openSUSE* ]]; then - OS="openSuse" - _DIST="osuse" - else - OS=$(echo "$LsbDescription" | cut -f1-4 -d" " | sed -e 's/\([a-zA-Z]\)[^ ]* */\1/g' -e 's/"//') - _DIST="sle" - if [[ $LsbRelease != *.* ]]; then - patchlevel=$(awk '/^PATCHLEVEL/ {print $3}' /etc/SuSE-release 2>/dev/null) - LsbRelease=${LsbRelease}.${patchlevel:-0} - fi - fi - ;; - "RedHatEnterprise"* | "CentOS"*) - OS="RedHat" - _DIST="rhel" - ;; - "Ubuntu"*) - OS="Ubuntu" - _DIST="ubunt" - ;; - "Debian"*) - OS="Debian" - _DIST="deb" - ;; - "Fedora"*) - _DIST="fc" - ;; - *) - echo "Distribution not detected or not supported" - return - ;; - esac - Release="${LsbRelease}" - elif [ -f /etc/redhat-release ]; then - Release=$( - sed -n ' - /Red Hat Enterprise /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - /CentOS /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - ' /etc/redhat-release - ) - OS="RedHat" - _DIST="rhel" - fi -} - -setsysname() { - _ARCH=$(uname -i | sed 's/x86_64/amd64/') - _DIST="" - _VER="" - - get_dist_release - case "$_DIST" in - fc | deb) - return - ;; - esac - _VER=$(echo "$Release" | firstint) - # Sysname list. The order here is from specific to general, with a - # fallback to the compiled-in value from sys. This will be - # used as the sysname search path. - if { SYS=$(sys); } >/dev/null 2>&1; then - if [ -n "$_VER" ]; then - SYSNAMELIST="${_ARCH}_${_DIST}${_VER} $SYS" - fi - fi - - # Set the sysname - if [ -n "$SYSNAMELIST" ]; then - SYSNAME=$(echo "$SYSNAMELIST" | awk 'BEGIN {ORS=" "} { for (i=1;i<=NF;i+=1) print "-newsys",$i }') - _CMD="fs sysname $SYSNAME" - echo "Setting sysname: $SYSNAMELIST" - $_CMD >/dev/null - fi -} - -killafs() { - SIGNAL=$1 - PIDS=$(lsof -Fp $AFS | sed -e 's/p//') - if [ -n "$PIDS" ]; then - kill -$SIGNAL $PIDS >/dev/null 2>&1 - sleep 3 - fi -} - -check_kernelpackages() { - KERNEL_VERSION="$1" - # Output from `uname -r` does not match package version. Get it by checking vmlinuz image - KERNEL_PKG=$(rpm -qf /boot/vmlinuz-${KERNEL_VERSION}) - KERNEL_PKG_VERSION=$(rpm -q --queryformat '%{version}-%{release}' "${KERNEL_PKG}") - # Get kernel type such as: xen, trace etc. - KERNEL_TYPE=$(echo $KERNEL_PKG | cut -d- -f2) - - if [ -f /etc/os-release ]; then - FULL_RELEASE=$(awk -F'"' '/VERSION_ID/ { print $2 }' /etc/os-release) - MAJOR_RELEASE=$(echo $FULL_RELEASE | cut -d. -f1) - MINOR_RELEASE=$(echo $FULL_RELEASE | cut -d. -f2) - else - MAJOR_RELEASE=$(awk '/VERSION/ { print $3 }' /etc/SuSE-release) - MINOR_RELEASE=$(awk '/PATCHLEVEL/ { print $3 }' /etc/SuSE-release) - fi - - if [ $MAJOR_RELEASE -ge 12 ]; then - PKG_ARGS="--oldpackage" - KERNEL_PACKAGES="kernel-${KERNEL_TYPE}-devel-${KERNEL_PKG_VERSION} kernel-devel-${KERNEL_PKG_VERSION}" - elif [ $MAJOR_RELEASE -ge 11 ] && [ $MINOR_RELEASE -ge 1 ]; then - PKG_ARGS="--oldpackage" - KERNEL_PACKAGES="kernel-${KERNEL_TYPE}-devel-${KERNEL_PKG_VERSION} kernel-source-${KERNEL_PKG_VERSION}" - else - PKG_ARGS="" - KERNEL_PACKAGES="kernel-source-${KERNEL_PKG_VERSION}" - fi - - if ! { rpm -q $KERNEL_PACKAGES; } >/dev/null 2>&1; then - echo "Needed packages for running kernel ${KERNEL_VERSION} missing: ${KERNEL_PACKAGES}" - echo "Try to install..." - zypper -q install -y ${PKG_ARGS} ${KERNEL_PACKAGES} - fi -} - -check_kernelmodule() { - modprobe --allow-unsupported-modules -V $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - MODPROBEOPT="--allow-unsupported-modules" - else - MODPROBEOPT="" - fi - modprobe $MODPROBEOPT $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - [ $RETVAL -eq 0 ] && return 0 # Kernel module loaded, continue... - echo -n "Attempting to recompile kernel module..." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 0 - } - fi - echo - KERNEL_VERSION=$(uname -r) - KMOD_BUILDLOG=/tmp/openafs-kmod-build-$(date +%Y%m%d-%H%M).log - echo "Build log for OpenAFS module: $(date)" >$KMOD_BUILDLOG - if [ "$CHKKERNELPACK" == "true" ]; then - check_kernelpackages $KERNEL_VERSION - fi - - if [ -d /usr/src/kernel-modules/openafs/libafs_tree ]; then - cd /usr/src/kernel-modules/openafs/libafs_tree || return 1 - make clean >>$KMOD_BUILDLOG 2>&1 - ./configure --with-linux-kernel-headers=/lib/modules/$KERNEL_VERSION/build >>$KMOD_BUILDLOG 2>&1 - make -j4 >>$KMOD_BUILDLOG 2>&1 - if [ $? -eq 0 ]; then - MODULEDIR=/lib/modules/$KERNEL_VERSION/kernel/fs/openafs - if [ -d $MODULEDIR ]; then # Clean out any occurance of old modules. - rm -rf $MODULEDIR - fi - mkdir $MODULEDIR - cp src/libafs/MODLOAD-$KERNEL_VERSION-*/libafs.ko $MODULEDIR/libafs.ko - ln $MODULEDIR/libafs.ko $MODULEDIR/openafs.ko - depmod -a >>$KMOD_BUILDLOG 2>&1 - modprobe $MODPROBEOPT $AFS_KERNEL_MODULE >>$KMOD_BUILDLOG 2>&1 - RETVAL=$? - else - RETVAL=1 - fi - echo - [ $RETVAL -eq 0 ] && rm -f $KMOD_BUILDLOG && echo "Build succeded!" && return 0 - echo - echo "Failed to build kernel module." - echo -n "See $KMOD_BUILDLOG for more details." - return 1 - else - echo - echo -n "OpenAFS Kernel source not installed." - return 1 - fi -} - -rm_wrong_module() { - module="$(modinfo -F filename $AFS_KERNEL_MODULE 2>/dev/null)" - if [ -f "$module" ]; then - mod_version=$(strings $module | awk '{ for (i=1; i $pkg_version" - fi - fi -} - -package_update() { - if [ "$UPDATE" == "true" ]; then - echo "Checking for OpenAFS updates.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 0 - } - fi - echo - zypper --no-gpg-checks refresh - package_status=$(zypper --no-gpg-checks info openafs 2>/dev/null | grep ^Status | cut -d: -f2 | awk '{print $1}') - if [ "$package_status" == "out-of-date" ]; then - echo "Upgrading OpenAFS" - zypper -q -V >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - # --allow-vendor-change - ZYPPEROPTS="-q" - else - ZYPPEROPTS="" - fi - zypper --no-gpg-checks $ZYPPEROPTS -n in openafs openafs-docs openafs-krb5-mit openafs-client openafs-kernel-source 2>/dev/null - # Make a clean cache in case of package upgrades, even if option is not set. - if [ "$CLEANCACHE" != "true" ]; then - if [ "${CACHEDIR}" == "/usr/vice/cache" ] || [ "${CACHEDIR}" == "/var/cache/openafs" ]; then - if [ -d ${CACHEDIR} ]; then - echo "Cleaning up cache area ${CACHEDIR}/ ..." - rm -rf ${CACHEDIR:?}/* - fi - else - echo "Cache area CACHEDIR ${CACHEDIR} not set correctly for cleanup-job in startup-script." - fi - fi - fi - fi -} - -# First reset status of this service -rc_reset - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - insufficient privilege -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signalling is not supported) are -# considered a success. - -case "$1" in - start) - if noroot_check; then - echo "Script has to be run as root" - exit 4 - fi - echo "Starting $DAEMON " - mkdir -p $AFS - if grep -q ^$AFS_KERNEL_MODULE /proc/modules; then - echo -n " -> $DAEMON already running " - else - # A configured zypper repository is needed for the package-update - package_update - rm_wrong_module - if check_kernelmodule; then - if ! pgrep -xf 'afsd' &>/dev/null; then - if [ "$CLEANCACHE" == "true" ]; then - if [ "${CACHEDIR}" == "/usr/vice/cache" ] || [ "${CACHEDIR}" == "/var/cache/openafs" ]; then - if [ -d ${CACHEDIR} ]; then - echo "Cleaning up cache area ${CACHEDIR}/ ..." - rm -rf ${CACHEDIR:?}/* - fi - else - echo "Cache area CACHEDIR ${CACHEDIR} not set correctly for cleanup-job in startup-script." - fi - fi - $DAEMON_BIN $AFSD_ARGS - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - setsysname - setsuid - setnocrypt - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - ( - sleep 60 - [ -x $SETSERVERPREFS ] && $SETSERVERPREFS - ) /dev/null 2>&1 & - else - rc_failed 1 - fi - fi - else - #modprobe failed - rc_failed 5 - fi - fi - # Remember status and be verbose - rc_status -v - ;; - stop) - if noroot_check; then - echo "Script has to be run as root" - exit 4 - fi - echo -n "Shutting down $DAEMON " - if pgrep -xf 'afsd' &>/dev/null; then - umount $AFS - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - $DAEMON_BIN -shutdown - fi - else - echo -n " -> $DAEMON not running " - RETVAL=0 - fi - if [ $RETVAL -eq 0 ]; then - if grep -q ^$AFS_KERNEL_MODULE /proc/modules; then - rmmod $AFS_KERNEL_MODULE || rc_failed 1 - fi - else - rc_failed 1 - fi - # rmtsys doesn't go away, so kill them all to be sure - #killall $DAEMON_BIN > /dev/null 2>&1 - # Remember status and be verbose - rc_status -v - ;; - stop-force) - if noroot_check; then - echo "Script has to be run as root" - exit 4 - fi - echo -n "Shutting down $DAEMON " - if pgrep -xf 'afsd' &>/dev/null; then - echo - echo "Sending all processes using $AFS the TERM signal ..." - killafs TERM - echo "Sending all processes using $AFS the KILL signal ..." - killafs KILL - umount $AFS - $DAEMON_BIN -shutdown - fi - if grep -q ^$AFS_KERNEL_MODULE /proc/modules; then - rmmod $AFS_KERNEL_MODULE || rc_failed 1 - fi - # rmtsys doesn't go away, so kill them all to be sure - #killall $DAEMON_BIN > /dev/null 2>&1 - # Remember status and be verbose - rc_status -v - ;; - try-restart) - ## Stop the service and if this succeeds (i.e. the - ## service was running before), start it again. - $0 stop && $0 start - - # Remember status and be quiet - rc_status - ;; - restart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - $0 stop - $0 start - - # Remember status and be quiet - rc_status - ;; - status) - echo -n "Checking for $DAEMON: " - ## Check status with checkproc(8), if process is running - ## checkproc will return with exit status 0. - - # Status has a slightly different for the status command: - # 0 - service running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running - - # NOTE: checkproc returns LSB compliant status values. - - pgrep -xf 'afsd' &>/dev/null || rc_failed 3 - - rc_status -v - ;; - check) - echo -n "Checking $DAEMON " - if pgrep -xf 'afsd' &>/dev/null; then - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -x $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo -n $"Check-script not available: $HEALTHCHECK" - echo - RETVAL=1 - fi - else - echo -n " -> $DAEMON not running " - RETVAL=0 - fi - ;; - *) - echo "Usage: $0 {start|stop|stop-force|status|check|try-restart|restart}" - exit 1 - ;; -esac -rc_exit diff --git a/files/openafs-client-Suse-systemd-exec.service b/files/openafs-client-Suse-systemd-exec.service deleted file mode 100644 index d6fa5ab..0000000 --- a/files/openafs-client-Suse-systemd-exec.service +++ /dev/null @@ -1,20 +0,0 @@ -[Unit] -Description=OpenAFS Client Service -Wants=network-online.target -After=syslog.target network-online.target -Before=remote-fs.target - -[Service] -Type=forking -EnvironmentFile=/etc/sysconfig/openafs-client -Restart=no -TimeoutSec=15min -IgnoreSIGPIPE=no -KillMode=none -GuessMainPID=no -RemainAfterExit=yes -ExecStart=/etc/openafs/systemd-exec.openafs-client start -ExecStop=/etc/openafs/systemd-exec.openafs-client stop - -[Install] -WantedBy=multi-user.target remote-fs.target diff --git a/files/openafs-client-Suse-systemd-sysv.service b/files/openafs-client-Suse-systemd-sysv.service deleted file mode 100644 index 2f401a7..0000000 --- a/files/openafs-client-Suse-systemd-sysv.service +++ /dev/null @@ -1,21 +0,0 @@ -[Unit] -SourcePath=/etc/init.d/openafs-client -Description=SYSV: OpenAFS Client Service -Wants=network-online.target -After=syslog.target network-online.target -Before=remote-fs.target - -[Service] -Type=forking -EnvironmentFile=/etc/sysconfig/openafs-client -Restart=no -TimeoutSec=15min -IgnoreSIGPIPE=no -KillMode=none -GuessMainPID=no -RemainAfterExit=yes -ExecStart=/etc/init.d/openafs-client start -ExecStop=/etc/init.d/openafs-client stop - -[Install] -WantedBy=multi-user.target remote-fs.target diff --git a/files/openafs-client-Ubuntu-init b/files/openafs-client-Ubuntu-init deleted file mode 100755 index 623c4cc..0000000 --- a/files/openafs-client-Ubuntu-init +++ /dev/null @@ -1,543 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2020 AFS-Core Ericsson -# Version v1.10, 2020-07-15 -# -### BEGIN INIT INFO -# Provides: openafs-client -# Required-Start: $remote_fs $network $time -# Required-Stop: $remote_fs $network -# Should-Start: $syslog $named openafs-fileserver -# Should-Stop: openafs-fileserver -# X-Stop-After: autofs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: OpenAFS client -# Description: Starts or stops the OpenAFS client, loading the -# OpenAFS kernel module as necessary. -### END INIT INFO -# -# Modified by Sam Hartman for Debian -# Copyright 2000, International Business Machines Corporation and others. -# All Rights Reserved. -# -# This software has been released under the terms of the IBM Public -# License. For details, see the LICENSE file in the top-level source -# directory or online at http://www.openafs.org/dl/license10.html - -PATH=/bin:/usr/bin:/sbin:/usr/sbin -export PATH - -CACHEINFO=${CACHEINFO:-/etc/openafs/cacheinfo} -MODULEROOT=${MODULEROOT:-/lib/modules/$(uname -r)} -MODULEDIR=${MODULEDIR:-$MODULEROOT/kernel/fs} -DKMSDIR=${DKMSDIR:-$MODULEROOT/updates/dkms} -AFS_KERNEL_MODULE=libafs -OPENAFSDKMS=openafs-modules-dkms -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/etc/openafs/SuidCells -LOCKFILE="/var/lock/$(basename $0)" -LOCKFD=99 - -# Exit if the package is not installed. -[ -x /sbin/afsd ] || exit 0 - -# Define LSB log_* functions and get other support infrastructure. -. /lib/lsb/init-functions - -exec 3>/dev/null -exec /dev/null 2>&1; then - _lock() { flock -$1 $LOCKFD; } - _no_more_locking() { - _lock u - _lock xn && rm -f $LOCKFILE - } - _prepare_locking() { - eval "exec $LOCKFD>\"$LOCKFILE\"" - trap _no_more_locking EXIT - } - exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail - exlock() { _lock x; } # obtain an exclusive lock - shlock() { _lock s; } # obtain a shared lock - unlock() { _lock u; } # drop a lock - _prepare_locking - return 0 - else - return 1 - fi -} - -setsuid() { - if [ -f $SUIDCELLS ]; then - while read -r CELLS; do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done <<<"$(grep '^[^#]' $SUIDCELLS)" - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -firstint() { - sed 's/^[^0-9]*//; s/[^0-9].*//' -} - -get_cell() { - CELL=$(fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/") - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -get_dist_release() { - if LsbDistributor=$(lsb_release -si 2>/dev/null); then - LsbDescription=$(lsb_release -sd) - LsbRelease=$(lsb_release -sr | cut -d . -f -2) - case $LsbDistributor in - "SUSE"*) - if [[ $LsbDescription == *openSUSE* ]]; then - OS="openSuse" - _DIST="osuse" - else - OS=$(echo "$LsbDescription" | cut -f1-4 -d" " | sed -e 's/\([a-zA-Z]\)[^ ]* */\1/g' -e 's/"//') - _DIST="sle" - if [[ $LsbRelease != *.* ]]; then - patchlevel=$(awk '/^PATCHLEVEL/ {print $3}' /etc/SuSE-release 2>/dev/null) - LsbRelease=${LsbRelease}.${patchlevel:-0} - fi - fi - ;; - "RedHatEnterprise"* | "CentOS"*) - OS="RedHat" - _DIST="rhel" - ;; - "Ubuntu"*) - OS="Ubuntu" - _DIST="ubunt" - ;; - "Debian"*) - OS="Debian" - _DIST="deb" - ;; - "Fedora"*) - _DIST="fc" - ;; - *) - echo "Distribution not detected or not supported" - return - ;; - esac - Release="${LsbRelease}" - elif [ -f /etc/redhat-release ]; then - Release=$( - sed -n ' - /Red Hat Enterprise /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - /CentOS /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - ' /etc/redhat-release - ) - OS="RedHat" - _DIST="rhel" - fi -} - -setsysname() { - _ARCH=$(uname -i | sed 's/x86_64/amd64/') - _DIST="" - _VER="" - - get_dist_release - case "$_DIST" in - fc | deb) - return - ;; - esac - _VER=$(echo "$Release" | firstint) - # Sysname list. The order here is from specific to general, with a - # fallback to the compiled-in value from sys. This will be - # used as the sysname search path. - if { SYS=$(sys); } >/dev/null 2>&1; then - if [ -n "$_VER" ]; then - SYSNAMELIST="${_ARCH}_${_DIST}${_VER} $SYS" - fi - fi - - # Set the sysname - if [ -n "$SYSNAMELIST" ]; then - SYSNAME=$(echo "$SYSNAMELIST" | awk 'BEGIN {ORS=" "} { for (i=1;i<=NF;i+=1) print "-newsys",$i }') - _CMD="fs sysname $SYSNAME" - echo "Setting sysname: $SYSNAMELIST" - $_CMD >/dev/null - fi -} - -dkms_check() { - if [ "$DKMS" == "true" ]; then - dpkg --status $OPENAFSDKMS >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -ne 0 ]; then - echo -n $"Error: DKMS set to true but no package $OPENAFSDKMS installed" - echo - exit 1 - fi - AFS_KERNEL_MODULE=openafs - return $RETVAL - else - return 1 - fi -} - -check_kernelmodule() { - KERNEL_VERSION=$(uname -r) - if dkms_check; then - if ! dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION" | grep ': installed$' >/dev/null; then - echo - echo "No kernel-module detected for $AFS_KERNEL_MODULE and kernel $(uname -r) .." - if { AFSVERSION=$(dpkg-query --showformat='${VERSION}' --show openafs-client | sed -e 's/-.*//'); } >/dev/null 2>&1; then - echo "DKMS stuff ..." - dkms add -m $AFS_KERNEL_MODULE -v $AFSVERSION --kernelver "$KERNEL_VERSION" - dkms autoinstall -m $AFS_KERNEL_MODULE --kernelver "$KERNEL_VERSION" - fi - fi - return 0 - fi - - modprobe $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - [ $RETVAL -eq 0 ] && return 0 # Kernel module loaded, continue... - - echo - echo -n $"Failed to load kernel module, attempting rebuild.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 1 - } - fi - echo - - KMOD_BUILDLOG=/tmp/openafs-kmod-build-$(date +%Y%m%d-%H%M).log - - echo "Build log for OpenAFS module: $(date)" >$KMOD_BUILDLOG - - dpkg --status openafs-modules-source >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - if [ -f /usr/src/openafs.tar.bz2 ]; then - cd /usr/src || return 1 - tar xjf /usr/src/openafs.tar.bz2 - cd modules/openafs || return 1 - - make clean >>$KMOD_BUILDLOG 2>&1 - ./configure --with-linux-kernel-headers=/lib/modules/$KERNEL_VERSION/build >>$KMOD_BUILDLOG 2>&1 - make -j4 >>$KMOD_BUILDLOG 2>&1 - if [ $? -eq 0 ]; then - MODULEDIR=/lib/modules/$KERNEL_VERSION/kernel/fs/openafs - [ ! -d $MODULEDIR ] && mkdir $MODULEDIR - - for file in src/libafs/MODLOAD-$KERNEL_VERSION-*/openafs.ko; do - if [ -f "$file" ]; then - cp "$file" $MODULEDIR/ - ln $MODULEDIR/openafs.ko $MODULEDIR/libafs.ko - break - else - cp src/libafs/MODLOAD-$KERNEL_VERSION-*/libafs.ko $MODULEDIR/ - fi - done - - depmod -a - modprobe $AFS_KERNEL_MODULE >>$KMOD_BUILDLOG 2>&1 - RETVAL=$? - else - RETVAL=1 - fi - [ $RETVAL -eq 0 ] && rm -f $KMOD_BUILDLOG && echo -n "Build succeeded!" && echo && return 0 - - echo -n "Failed to build kernel module." - echo "See $KMOD_BUILDLOG for more details." - echo - return 1 - else - echo "No Modules source archive found: /usr/src/openafs.tar.bz2" - echo - return 1 - fi - else - echo -n "OpenAFS Modules source not installed." - echo - return 1 - fi -} - -rm_wrong_module() { - # Only needed if dkms is not used - if dkms_check; then - return 0 - fi - KERNEL_VERSION=$(uname -r) - module="$(modinfo -F filename $AFS_KERNEL_MODULE 2>/dev/null)" - if [ -f "$module" ]; then - mod_version=$(strings $module | awk '{ for (i=1; i $pkg_version" - fi - fi -} - -check() { - echo -n $"Checking openafs-client: " - if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null; then - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -x $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo -n $"Check-script not available: $HEALTHCHECK" - echo - return 1 - fi - else - echo -n $"cannot check openafs-client: not running" - echo - return 1 - fi -} - -# Determine if kernel module loading is disabled. If it's not, don't attempt -# to stop or restart AFS, since we'll end up in a bad inconsistent state. -is_loading_disabled() { - disabled=$(cat /proc/sys/kernel/modules_disabled 2>/dev/null) - if [ "$disabled" = 1 ]; then - return 0 - else - return 1 - fi -} - -# Load the AFS client module if it's not already loaded. Set $MODULEDIR and -# $LIBAFS to override the default location and module name. Also check before -# loading whether the module is listed in the module dependencies so that we -# can exit with a 0 status in that case. -load_client() { - if [ "$DKMS" == "true" ]; then - AFS_KERNEL_MODULE=openafs - # Check if no dkms session is running already - if { pgrep -f "dkms .* -m $AFS_KERNEL_MODULE"; } >/dev/null 2>&1; then - echo "A dkms-session is running to install/remove $AFS_KERNEL_MODULE, will exit now." - exit 1 - fi - fi - if check_kernelmodule; then - sawdep=0 - if grep -q "$AFS_KERNEL_MODULE" "$MODULEROOT/modules.dep"; then - sawdep=1 - fi - LOADED=$(lsmod | fgrep "$AFS_KERNEL_MODULE") - if [ -z "$LOADED" ]; then - if dkms_check; then - modprobe $AFS_KERNEL_MODULE - status=$? - if [ $status = 0 ]; then - echo -n " openafs" - fi - - # We must exit successfully here if the openafs module just isn't - # listed in the dependency information for modprobe, which can happen - # if openafs-client and the module package are installed at the same - # time and the module hasn't been set up yet. - if [ $sawdep = 0 ]; then - return 0 - else - return $status - fi - fi - fi - return 0 - else - echo -n "failed to load openafs kernel module." - return 1 - fi -} - -# Start afsd. Be careful not to start it if another one is already running, -# as that has a bad tendency to hang the system. Earlier versions of the -# openafs-client package put afsd in /usr/sbin. -start_client() { - if pidof /sbin/afsd >/dev/null || pidof /usr/sbin/afsd >/dev/null; then - echo "." - else - echo " afsd." - start-stop-daemon --start --quiet --exec /sbin/afsd -- $AFSD_ARGS - setsysname - setsuid - setnocrypt - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - ( - sleep 60 - [ -x $SETSERVERPREFS ] && $SETSERVERPREFS - ) /dev/null 2>&1 & - fi -} - -# Kill all processes that are accessing AFS. Not enabled by default, and -# normally called via kill_all_afs. -kill_afs() { - signal=$1 - mount=$(grep ^'AFS ' /etc/mtab | awk '{ print $2 }') - if [ -n "$mount" ]; then - pids=$(lsof -Fp $mount | sed 's/p//') - if [ -n "$pids" ]; then - kill -$signal $pids >/dev/null 2>&1 - sleep 1 - fi - fi -} - -# Repeatedly call kill_afs for a series of signals to give AFS-using processes -# a hope of shutting down cleanly if the system is shutting down. Not enabled -# by default. Enable this in /etc/openafs/afs.conf. -# -# Warns and does nothing if lsof is not installed. -kill_all_afs() { - if { lsof -h; } >/dev/null 2>&1; then - echo -n "Killing processes with AFS files open: " - kill_afs HUP - kill_afs TERM - kill_afs ABRT - kill_afs KILL - echo "done." - else - echo 'lsof not found, not killing processes' >&2 - fi -} - -case "$1" in - start) - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - if test -x /sbin/afsd; then - echo -n "Starting AFS services:" - rm_wrong_module - if load_client; then - start_client - else - echo "" - echo "Failed to load AFS kernel module, not starting AFS" >&2 - exit 1 - fi - fi - ;; - - stop) - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - if is_loading_disabled; then - echo "Module loading disabled, cannot stop AFS" >&2 - exit 1 - fi - echo -n "Stopping AFS services:" - if grep -q '^AFS ' /etc/mtab; then - umount "$(awk '/^AFS / {print $2}' /etc/mtab)" - echo -n " afsd" - fi - if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null; then - afsd -shutdown - fi - - # If running with the -rmtsys option, afsd doesn't kill the rmtsys helper - # on afsd -shutdown. Run start-stop-daemon to make sure that everything - # is dead. - start-stop-daemon --stop --quiet --name afsd - - AFS_KERNEL_MODULE=$(lsmod | awk 'BEGIN { FS = " " } /afs/ { print $1 }') - if [ -n "$AFS_KERNEL_MODULE" ]; then - rmmod $AFS_KERNEL_MODULE - echo -n " openafs" - fi - echo "." - ;; - - stop-force) - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - if is_loading_disabled; then - echo "Module loading disabled, cannot stop AFS" >&2 - exit 1 - fi - echo -n "Stopping AFS services:" - if grep -q '^AFS ' /etc/mtab; then - kill_all_afs - umount "$(awk '/^AFS / {print $2}' /etc/mtab)" - echo -n " afsd" - fi - - if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null; then - afsd -shutdown - fi - - # If running with the -rmtsys option, afsd doesn't kill the rmtsys helper - # on afsd -shutdown. Run start-stop-daemon to make sure that everything - # is dead. - start-stop-daemon --stop --quiet --name afsd - - AFS_KERNEL_MODULE=$(lsmod | awk 'BEGIN { FS = " " } /afs/ { print $1 }') - if [ -n "$AFS_KERNEL_MODULE" ]; then - rmmod $AFS_KERNEL_MODULE - echo -n " openafs" - fi - echo "." - ;; - - restart | force-reload) - "$0" stop - "$0" start - ;; - - check) - check - ;; - - *) - echo Usage: \ - 'openafs-client {start|stop|stop-force|restart|check|force-reload}' >&2 - exit 1 - ;; - -esac diff --git a/files/openafs-client-Ubuntu-systemd b/files/openafs-client-Ubuntu-systemd deleted file mode 100644 index 8006e8a..0000000 --- a/files/openafs-client-Ubuntu-systemd +++ /dev/null @@ -1,555 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2019 AFS-Core Ericsson -# Version v1.8, 2019-12-19 -# -### BEGIN INIT INFO -# Provides: openafs-client -# Required-Start: $remote_fs $network $time -# Required-Stop: $remote_fs $network -# Should-Start: $syslog $named openafs-fileserver -# Should-Stop: openafs-fileserver -# X-Stop-After: autofs -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: OpenAFS client -# Description: Starts or stops the OpenAFS client, loading the -# OpenAFS kernel module as necessary. -### END INIT INFO -# -# Modified by Sam Hartman for Debian -# Copyright 2000, International Business Machines Corporation and others. -# All Rights Reserved. -# -# This software has been released under the terms of the IBM Public -# License. For details, see the LICENSE file in the top-level source -# directory or online at http://www.openafs.org/dl/license10.html - -PATH=/bin:/usr/bin:/sbin:/usr/sbin -export PATH - -CACHEINFO=${CACHEINFO:-/etc/openafs/cacheinfo} -MODULEROOT=${MODULEROOT:-/lib/modules/$(uname -r)} -MODULEDIR=${MODULEDIR:-$MODULEROOT/kernel/fs} -DKMSDIR=${DKMSDIR:-$MODULEROOT/updates/dkms} -AFS_KERNEL_MODULE=libafs -OPENAFSDKMS=openafs-modules-dkms -DEFAULTCELL="sunrise.ericsson.se" -SUIDCELLS=/etc/openafs/SuidCells -LOCKFILE="/var/lock/$(basename $0)" -LOCKFD=99 - -# Exit if the package is not installed. -[ -x /sbin/afsd ] || exit 0 - -# Define LSB log_* functions and get other support infrastructure. -. /lib/lsb/init-functions - -exec 3>/dev/null -exec /dev/null 2>&1; then - _lock() { flock -$1 $LOCKFD; } - _no_more_locking() { - _lock u - _lock xn && rm -f $LOCKFILE - } - _prepare_locking() { - eval "exec $LOCKFD>\"$LOCKFILE\"" - trap _no_more_locking EXIT - } - exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail - exlock() { _lock x; } # obtain an exclusive lock - shlock() { _lock s; } # obtain a shared lock - unlock() { _lock u; } # drop a lock - _prepare_locking - return 0 - else - return 1 - fi -} - -setsuid() { - if [ -f $SUIDCELLS ]; then - for CELLS in $(grep '^[^#]' $SUIDCELLS); do - echo "Setting $CELLS suid" - fs setcell -cell $CELLS -suid - done - fi -} - -setnocrypt() { - fs setcrypt -crypt off -} - -firstint() { - sed 's/^[^0-9]*//; s/[^0-9].*//' -} - -get_cell() { - CELL=$(fs wscell 2>/dev/null | sed -e "s/.*to cell '\(.*\)'/\1/") - if [ -z "$CELL" ]; then - CELL="$DEFAULTCELL" - fi -} - -get_dist_release() { - if LsbDistributor=$(lsb_release -si 2>/dev/null); then - LsbDescription=$(lsb_release -sd) - LsbRelease=$(lsb_release -sr | cut -d . -f -2) - case $LsbDistributor in - "SUSE"*) - if [[ $LsbDescription == *openSUSE* ]]; then - OS="openSuse" - _DIST="osuse" - else - OS=$(echo "$LsbDescription" -sd | cut -f1-4 -d" " | tr -cs '[:alpha:]' '[\n*]' | grep -v '^$' | cut -c1 | tr -d '[\n]') - _DIST="sle" - if [[ $LsbRelease != *.* ]]; then - patchlevel=$(awk '/^PATCHLEVEL/ {print $3}' /etc/SuSE-release 2>/dev/null) - LsbRelease=${LsbRelease}.${patchlevel:-0} - fi - fi - ;; - "RedHatEnterprise"* | "CentOS"*) - OS="RedHat" - _DIST="rhel" - ;; - "Ubuntu"*) - OS="Ubuntu" - _DIST="ubunt" - ;; - "Debian"*) - OS="Debian" - _DIST="deb" - ;; - "Fedora"*) - _DIST="fc" - ;; - *) - echo "Distribution not detected or not supported" - return - ;; - esac - Release="${LsbRelease}" - elif [ -f /etc/redhat-release ]; then - Release=$( - sed -n ' - /Red Hat Enterprise /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - /CentOS /{s/^[^0-9]*\([0-9]\{1,\}[.]\{0,1\}[0-9]*\).*/\1/p;q;} - ' /etc/redhat-release - ) - OS="RedHat" - _DIST="rhel" - fi -} - -setsysname() { - _ARCH=$(uname -i | sed 's/x86_64/amd64/') - _DIST="" - _VER="" - - get_dist_release - case "$_DIST" in - fc | deb) - return - ;; - esac - _VER=$(echo "$Release" | firstint) - # Sysname list. The order here is from specific to general, with a - # fallback to the compiled-in value from sys. This will be - # used as the sysname search path. - if { SYS=$(sys); } >/dev/null 2>&1; then - if [ -n "$_VER" ]; then - SYSNAMELIST="${_ARCH}_${_DIST}${_VER} $SYS" - fi - fi - - # Set the sysname - if [ -n "$SYSNAMELIST" ]; then - SYSNAME=$(echo "$SYSNAMELIST" | awk 'BEGIN {ORS=" "} { for (i=1;i<=NF;i+=1) print "-newsys",$i }') - _CMD="fs sysname $SYSNAME" - echo "Setting sysname: $SYSNAMELIST" - $_CMD >/dev/null - fi -} - -dkms_check() { - if [ "$DKMS" == "true" ]; then - dpkg --status $OPENAFSDKMS >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -ne 0 ]; then - echo -n $"Error: DKMS set to true but no package $OPENAFSDKMS installed" - echo - exit 1 - fi - AFS_KERNEL_MODULE=openafs - return $RETVAL - else - return 1 - fi -} - -check_kernelmodule() { - KERNEL_VERSION=$(uname -r) - if dkms_check; then - # dkms status -m $AFS_KERNEL_MODULE -k `uname -r` | grep -w 'installed-weak' > /dev/null - # if [ $? -eq 0 ]; then - # echo - # echo "Weak module detected, will be removed.." - # if [ -h /lib/modules/`uname -r`/weak-updates/${AFS_KERNEL_MODULE}.ko ]; then - # rm -fv /lib/modules/`uname -r`/weak-updates/${AFS_KERNEL_MODULE}.ko - # fi - # echo - # echo "DKMS stuff ..." - # dkms autoinstall -m $AFS_KERNEL_MODULE --kernelver `uname -r` - # fi - dkms status -m $AFS_KERNEL_MODULE -k "$KERNEL_VERSION" | grep ': installed$' >/dev/null - if [ $? -ne 0 ]; then - echo - echo "No kernel-module detected for $AFS_KERNEL_MODULE and kernel $(uname -r) .." - if { AFSVERSION=$(dpkg-query --showformat='${VERSION}' --show openafs-client | sed -e 's/-.*//'); } >/dev/null 2>&1; then - echo "DKMS stuff ..." - dkms add -m $AFS_KERNEL_MODULE -v $AFSVERSION --kernelver "$KERNEL_VERSION" - dkms autoinstall -m $AFS_KERNEL_MODULE --kernelver "$KERNEL_VERSION" - fi - fi - return 0 - fi - - modprobe $AFS_KERNEL_MODULE >/dev/null 2>&1 - RETVAL=$? - [ $RETVAL -eq 0 ] && return 0 # Kernel module loaded, continue... - - echo - echo -n $"Failed to load kernel module, attempting rebuild.." - if lock_routine; then - exlock_now || { - echo - echo " -> Lock-file $LOCKFILE exists! Will exit now." - exit 1 - } - fi - echo - - KMOD_BUILDLOG=/tmp/openafs-kmod-build-$(date +%Y%m%d-%H%M).log - - echo "Build log for OpenAFS module: $(date)" >$KMOD_BUILDLOG - - dpkg --status openafs-modules-source >/dev/null 2>&1 - RETVAL=$? - if [ $RETVAL -eq 0 ]; then - if [ -f /usr/src/openafs.tar.bz2 ]; then - cd /usr/src || return 1 - tar xjf /usr/src/openafs.tar.bz2 - cd modules/openafs || return 1 - - make clean >>$KMOD_BUILDLOG 2>&1 - ./configure --with-linux-kernel-headers=/lib/modules/$KERNEL_VERSION/build >>$KMOD_BUILDLOG 2>&1 - make -j4 >>$KMOD_BUILDLOG 2>&1 - if [ $? -eq 0 ]; then - MODULEDIR=/lib/modules/$KERNEL_VERSION/kernel/fs/openafs - [ ! -d $MODULEDIR ] && mkdir $MODULEDIR - - for file in src/libafs/MODLOAD-$KERNEL_VERSION-*/openafs.ko; do - if [ -f "$file" ]; then - cp "$file" $MODULEDIR/ - ln $MODULEDIR/openafs.ko $MODULEDIR/libafs.ko - break - else - cp src/libafs/MODLOAD-$KERNEL_VERSION-*/libafs.ko $MODULEDIR/ - fi - done - - depmod -a - modprobe $AFS_KERNEL_MODULE >>$KMOD_BUILDLOG 2>&1 - RETVAL=$? - else - RETVAL=1 - fi - [ $RETVAL -eq 0 ] && rm -f $KMOD_BUILDLOG && echo -n "Build succeeded!" && echo && return 0 - - echo -n "Failed to build kernel module." - echo "See $KMOD_BUILDLOG for more details." - echo - return 1 - else - echo "No Modules source archive found: /usr/src/openafs.tar.bz2" - echo - return 1 - fi - else - echo -n "OpenAFS Modules source not installed." - echo - return 1 - fi -} - -rm_wrong_module() { - # Only needed if dkms is not used - if dkms_check; then - return 0 - fi - KERNEL_VERSION=$(uname -r) - module="$(modinfo -F filename $AFS_KERNEL_MODULE 2>/dev/null)" - if [ -f "$module" ]; then - mod_version=$(strings $module | awk '{ for (i=1; i $pkg_version" - fi - fi -} - -check() { - echo -n $"Checking openafs-client: " - if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null; then - get_cell - HEALTHCHECK=/afs/$CELL/afsadm/bin/afs_site_health_check.sh - if [ -x $HEALTHCHECK ]; then - $HEALTHCHECK - else - echo -n $"Check-script not available: $HEALTHCHECK" - echo - return 1 - fi - else - echo -n $"cannot check openafs-client: not running" - echo - return 1 - fi -} - -# Determine if kernel module loading is disabled. If it's not, don't attempt -# to stop or restart AFS, since we'll end up in a bad inconsistent state. -is_loading_disabled() { - disabled=$(cat /proc/sys/kernel/modules_disabled 2>/dev/null) - if [ "$disabled" = 1 ]; then - return 0 - else - return 1 - fi -} - -# Load the AFS client module if it's not already loaded. Set $MODULEDIR and -# $LIBAFS to override the default location and module name. Also check before -# loading whether the module is listed in the module dependencies so that we -# can exit with a 0 status in that case. -load_client() { - if [ "$DKMS" == "true" ]; then - AFS_KERNEL_MODULE=openafs - # Check if no dkms session is running already - if { pgrep -f "dkms .* -m $AFS_KERNEL_MODULE"; } >/dev/null 2>&1; then - echo "A dkms-session is running to install/remove $AFS_KERNEL_MODULE, will exit now." - exit 1 - fi - fi - if check_kernelmodule; then - sawdep=0 - if grep -q "$AFS_KERNEL_MODULE" "$MODULEROOT/modules.dep"; then - sawdep=1 - fi - LOADED=$(lsmod | fgrep "$AFS_KERNEL_MODULE") - if [ -z "$LOADED" ]; then - if dkms_check; then - modprobe $AFS_KERNEL_MODULE - status=$? - if [ $status = 0 ]; then - echo -n " openafs" - fi - - # We must exit successfully here if the openafs module just isn't - # listed in the dependency information for modprobe, which can happen - # if openafs-client and the module package are installed at the same - # time and the module hasn't been set up yet. - if [ $sawdep = 0 ]; then - return 0 - else - return $status - fi - fi - fi - return 0 - else - echo -n "failed to load openafs kernel module." - return 1 - fi -} - -# Start afsd. Be careful not to start it if another one is already running, -# as that has a bad tendency to hang the system. Earlier versions of the -# openafs-client package put afsd in /usr/sbin. -start_client() { - if pidof /sbin/afsd >/dev/null || pidof /usr/sbin/afsd >/dev/null; then - echo "." - else - echo " afsd." - start-stop-daemon --start --quiet --exec /sbin/afsd -- $AFSD_ARGS - setsysname - setsuid - setnocrypt - get_cell - SETSERVERPREFS=/afs/$CELL/afsadm/sbin/afs_setserverprefs.sh - # background job that should run after the AFS initialization... - ( - sleep 60 - [ -x $SETSERVERPREFS ] && $SETSERVERPREFS - ) /dev/null 2>&1 & - fi -} - -# Kill all processes that are accessing AFS. Not enabled by default, and -# normally called via kill_all_afs. -kill_afs() { - signal=$1 - mount=$(grep ^'AFS ' /etc/mtab | awk '{ print $2 }') - if [ -n "$mount" ]; then - pids=$(lsof -Fp $mount | sed 's/p//') - if [ -n "$pids" ]; then - kill -$signal $pids >/dev/null 2>&1 - sleep 1 - fi - fi -} - -# Repeatedly call kill_afs for a series of signals to give AFS-using processes -# a hope of shutting down cleanly if the system is shutting down. Not enabled -# by default. Enable this in /etc/openafs/afs.conf. -# -# Warns and does nothing if lsof is not installed. -kill_all_afs() { - if { lsof -h; } >/dev/null 2>&1; then - echo -n "Killing processes with AFS files open: " - kill_afs HUP - kill_afs TERM - kill_afs ABRT - kill_afs KILL - echo "done." - else - echo 'lsof not found, not killing processes' >&2 - fi -} - -case "$1" in - start) - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - if test -x /sbin/afsd; then - echo -n "Starting AFS services:" - rm_wrong_module - if load_client; then - start_client - else - echo "" - echo "Failed to load AFS kernel module, not starting AFS" >&2 - exit 1 - fi - fi - ;; - - stop) - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - if is_loading_disabled; then - echo "Module loading disabled, cannot stop AFS" >&2 - exit 1 - fi - echo -n "Stopping AFS services:" - if grep -q '^AFS ' /etc/mtab; then - umount "$(awk '/^AFS / {print $2}' /etc/mtab)" - echo -n " afsd" - fi - if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null; then - afsd -shutdown - fi - - # If running with the -rmtsys option, afsd doesn't kill the rmtsys helper - # on afsd -shutdown. Run start-stop-daemon to make sure that everything - # is dead. - start-stop-daemon --stop --quiet --name afsd - - AFS_KERNEL_MODULE=$(lsmod | awk 'BEGIN { FS = " " } /afs/ { print $1 }') - if [ -n "$AFS_KERNEL_MODULE" ]; then - rmmod $AFS_KERNEL_MODULE - echo -n " openafs" - fi - echo "." - ;; - - stop-force) - if noroot_check; then - echo "Script has to be run as root" - exit 1 - fi - if is_loading_disabled; then - echo "Module loading disabled, cannot stop AFS" >&2 - exit 1 - fi - echo -n "Stopping AFS services:" - if grep -q '^AFS ' /etc/mtab; then - kill_all_afs - umount "$(awk '/^AFS / {print $2}' /etc/mtab)" - echo -n " afsd" - fi - - if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null; then - afsd -shutdown - fi - - # If running with the -rmtsys option, afsd doesn't kill the rmtsys helper - # on afsd -shutdown. Run start-stop-daemon to make sure that everything - # is dead. - start-stop-daemon --stop --quiet --name afsd - - AFS_KERNEL_MODULE=$(lsmod | awk 'BEGIN { FS = " " } /afs/ { print $1 }') - if [ -n "$AFS_KERNEL_MODULE" ]; then - rmmod $AFS_KERNEL_MODULE - echo -n " openafs" - fi - echo "." - ;; - - restart | force-reload) - "$0" stop - "$0" start - ;; - - check) - check - ;; - - *) - echo Usage: \ - 'openafs-client {start|stop|stop-force|restart|check|force-reload}' >&2 - exit 1 - ;; - -esac diff --git a/manifests/init.pp b/manifests/init.pp index 66272f2..f19f53e 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -69,7 +69,7 @@ # # @param config_client_clean_cache_on_start # Boolean trigger for the cleaning of the client cache on start. -# If set to true, the provided init script will clean the client cache when starting the service. +# If set to true, client cache will be cleaned when starting the service. # Please check openafs-client config file for supported OS families. # # @param config_client_dkms @@ -80,27 +80,12 @@ # Path to the openafs-client configuration file. # # @param config_client_update -# Boolean trigger for the selfupdating routine in the init script. -# If set to true, the init skript checks for updated AFS packages in the available repositories and installs them. +# Boolean trigger for the selfupdating routine in the start script. +# If set to true, checks for updated AFS packages in the available repositories and installs them. # # @param create_symlinks # Create symlinks for convenient access to AFS structure. Path and target are taken from hash in $links. # -# @param init_script -# Filename for the init script. -# -# @param init_template -# Name of the template file to be used for $init_script. -# Installs init-script if specified. -# -# @param systemd_script_template -# Name of the template file to be used as startup script for systemd. -# Installs systemd script if specified. -# -# @param systemd_unit_template -# Name of the template file to be used as unit file for systemd. -# Installs systemd unit file if specified. -# # @param links # Hash of path and target to create symlinks from if $create_links is true. # @@ -140,10 +125,6 @@ Boolean $config_client_update = false, Boolean $create_symlinks = false, Hash $links = {}, - Stdlib::Unixpath $init_script = '/etc/init.d/openafs-client', - Optional[String] $init_template = undef, - Optional[String] $systemd_script_template = undef, - Optional[String] $systemd_unit_template = undef, Optional[String] $package_adminfile = undef, Variant[Array[String], String] $package_name = undef, Optional[String] $package_provider = undef, @@ -163,71 +144,14 @@ # TODO: Replace with Stdlib::Fqdn afs::validate_domain_names { $afs_suidcells_array: } - if $init_template and $systemd_unit_template { - $init_script_ensure = 'file' - $systemd_script_ensure = 'absent' - $systemd_unit_ensure = 'file' - - $package_before = [ - File[afs_init_script], - File[afs_systemd_unit], - File[afs_config_cacheinfo], - File[afs_config_client], - ] - $service_require = [ - File[afs_init_script], - File[afs_systemd_unit], - File[afs_config_cacheinfo], - File[afs_config_client], - ] - $cron_require = [ - File[afs_init_script], - File[afs_systemd_script], - ] - } elsif $init_template { - $init_script_ensure = 'file' - $systemd_script_ensure = 'absent' - $systemd_unit_ensure = 'absent' - - $package_before = [ - File[afs_init_script], - File[afs_config_cacheinfo], - File[afs_config_client], - ] - $service_require = [ - File[afs_init_script], - File[afs_config_cacheinfo], - File[afs_config_client], - ] - $cron_require = [ - File[afs_init_script], - ] - } elsif $systemd_unit_template { - assert_type(String, $systemd_script_template) |$expected, $actual| { - fail("afs::systemd_script_template must be ${expected} when afs::systemd_unit_template is set but not afs::init_template. Got ${actual}.") #lint:ignore:140chars - } - $init_script_ensure = 'absent' - $systemd_script_ensure = 'file' - $systemd_unit_ensure = 'file' - - $package_before = [ - File[afs_systemd_script], - File[afs_systemd_unit], - File[afs_config_cacheinfo], - File[afs_config_client], - ] - $service_require = [ - File[afs_systemd_script], - File[afs_systemd_unit], - File[afs_config_cacheinfo], - File[afs_config_client], - ] - $cron_require = [ - File[afs_systemd_script], - ] - } else { - fail('AFS module requires to be either init, hybrid or systemd. Please read README for more information.') - } + $package_before = [ + File[afs_config_cacheinfo], + File[afs_config_client], + ] + $service_require = [ + File[afs_config_cacheinfo], + File[afs_config_client], + ] if $package_adminfile != undef { Package { @@ -284,33 +208,6 @@ } } - file { 'afs_init_script' : - ensure => $init_script_ensure, - path => $init_script, - owner => 'root', - group => 'root', - mode => '0755', - source => "puppet:///modules/afs/${init_template}", # lint:ignore:fileserver - } - - file { 'afs_systemd_script' : - ensure => $systemd_script_ensure, - path => "${afs_config_path}/systemd-exec.openafs-client", - owner => 'root', - group => 'root', - mode => '0755', - source => "puppet:///modules/afs/${systemd_script_template}", # lint:ignore:fileserver - } - - file { 'afs_systemd_unit' : - ensure => $systemd_unit_ensure, - path => '/usr/lib/systemd/system/openafs-client.service', - owner => 'root', - group => 'root', - mode => '0644', - source => "puppet:///modules/afs/${systemd_unit_template}", # lint:ignore:fileserver - } - file { 'afs_config_cacheinfo' : ensure => file, path => "${afs_config_path}/cacheinfo", @@ -399,7 +296,6 @@ month => $afs_cron_job_month, weekday => $afs_cron_job_weekday, monthday => $afs_cron_job_monthday, - require => $cron_require, } } else { @@ -410,7 +306,6 @@ group => 'root', mode => '0755', content => $afs_cron_job_content, - require => $cron_require, } } } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index b1d05e4..318bd19 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -7,69 +7,14 @@ platforms["#{os_facts[:os]['name']}-#{os_facts[:os]['release']['major']}-#{os_facts[:os]['architecture']}"] end - # Hybrid installation with both init script and systemd unit - if !os_data[:init_template].nil? && !os_data[:systemd_unit_template].nil? - init_script_ensure = 'file' - systemd_script_ensure = 'absent' - systemd_unit_ensure = 'file' - - package_before = [ - 'File[afs_init_script]', - 'File[afs_systemd_unit]', - 'File[afs_config_cacheinfo]', - 'File[afs_config_client]', - ] - service_require = [ - 'File[afs_init_script]', - 'File[afs_systemd_unit]', - 'File[afs_config_cacheinfo]', - 'File[afs_config_client]', - ] - cron_require = [ - 'File[afs_init_script]', - 'File[afs_systemd_script]', - ] - # init script installation - elsif !os_data[:init_template].nil? - init_script_ensure = 'file' - systemd_script_ensure = 'absent' - systemd_unit_ensure = 'absent' - - package_before = [ - 'File[afs_init_script]', - 'File[afs_config_cacheinfo]', - 'File[afs_config_client]', - ] - service_require = [ - 'File[afs_init_script]', - 'File[afs_config_cacheinfo]', - 'File[afs_config_client]', - ] - cron_require = [ - 'File[afs_init_script]', - ] - # systemd installation - elsif !os_data[:systemd_unit_template].nil? - init_script_ensure = 'absent' - systemd_script_ensure = 'file' - systemd_unit_ensure = 'file' - - package_before = [ - 'File[afs_systemd_script]', - 'File[afs_systemd_unit]', - 'File[afs_config_cacheinfo]', - 'File[afs_config_client]', - ] - service_require = [ - 'File[afs_systemd_script]', - 'File[afs_systemd_unit]', - 'File[afs_config_cacheinfo]', - 'File[afs_config_client]', - ] - cron_require = [ - 'File[afs_systemd_script]', - ] - end + package_before = [ + 'File[afs_config_cacheinfo]', + 'File[afs_config_client]', + ] + service_require = [ + 'File[afs_config_cacheinfo]', + 'File[afs_config_client]', + ] context "on #{os}" do describe 'with default values for parameters' do @@ -95,43 +40,6 @@ is_expected.to contain_common__mkdir_p(File.dirname(os_data[:config_client_path])) } - # file { 'afs_init_script' :} - it { - is_expected.to contain_file('afs_init_script').with( - 'ensure' => init_script_ensure, - 'path' => os_data[:init_script], - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0755', - 'source' => "puppet:///modules/afs/#{os_data[:init_template]}", - 'before' => 'Service[afs_openafs_client_service]', - ) - } - - # file { 'afs_systemd_unit': } - it { - is_expected.to contain_file('afs_systemd_script').with( - 'ensure' => systemd_script_ensure, - 'path' => "#{os_data[:afs_config_path]}/systemd-exec.openafs-client", - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0755', - 'source' => "puppet:///modules/afs/#{os_data[:systemd_script_template]}", - 'before' => 'Service[afs_openafs_client_service]', - ) - } - it { - is_expected.to contain_file('afs_systemd_unit').with( - 'ensure' => systemd_unit_ensure, - 'path' => '/usr/lib/systemd/system/openafs-client.service', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', - 'source' => "puppet:///modules/afs/#{os_data[:systemd_unit_template]}", - 'before' => 'Service[afs_openafs_client_service]', - ) - } - # file { 'afs_config_cacheinfo' :} it { is_expected.to contain_file('afs_config_cacheinfo').with( @@ -325,7 +233,6 @@ 'group' => 'root', 'mode' => '0755', 'content' => '#!/bin/sh\\n/sw/RedHat/afs_setserverprefs.sh', - 'require' => cron_require, ) } end @@ -354,7 +261,6 @@ 'month' => '2', 'weekday' => '4', 'monthday' => '2', - 'require' => cron_require, ) } end @@ -427,7 +333,6 @@ } end - it { is_expected.to contain_file('afs_init_script').with_before(nil) } it { is_expected.to contain_file('afs_config_cacheinfo').with_before(nil) } it { is_expected.to contain_file('afs_config_client').with_before(nil) } it { is_expected.to contain_file('afs_config_suidcells').with_before(nil) } @@ -445,7 +350,6 @@ package_adminfile: '/sw/Solaris/Sparc/noask', package_provider: 'sun', package_source: '/sw/Solaris/Sparc/EISopenafs', - service_provider: 'init', package_name: ['EISopenafs'] } end @@ -467,13 +371,6 @@ is_expected.to contain_package('EISopenafs').with('source' => '/sw/Solaris/Sparc/EISopenafs') } end - - context 'where service_provider is ' do - # service { 'afs_openafs_client_service':} - it { - is_expected.to contain_service('afs_openafs_client_service').with('provider' => 'init') - } - end end end end diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 8b9ff25..02d0f29 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -6,8 +6,6 @@ def platforms cache_path: '/usr/vice/cache', config_client_dkms: true, config_client_path: '/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-RedHat-init', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-compat', 'openafs-krb5', 'dkms', 'dkms-openafs', 'glibc-devel', 'libgcc.i386'], allow_unsupported_modules: false, }, @@ -17,8 +15,6 @@ def platforms cache_path: '/usr/vice/cache', config_client_dkms: true, config_client_path: '/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-RedHat-init', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-compat', 'openafs-krb5', 'dkms', 'dkms-openafs', 'glibc-devel', 'libgcc.i686'], allow_unsupported_modules: false, }, @@ -28,9 +24,6 @@ def platforms cache_path: '/usr/vice/cache', config_client_dkms: true, config_client_path: '/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-RedHat-init', - systemd_unit_template: 'openafs-client-RedHat-systemd-sysv.service', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-compat', 'openafs-krb5', 'dkms', 'dkms-openafs', 'glibc-devel', 'libgcc.i686'], allow_unsupported_modules: false, }, @@ -40,10 +33,6 @@ def platforms cache_path: '/usr/vice/cache', config_client_dkms: true, config_client_path: '/etc/sysconfig/openafs-client', - service_provider: 'systemd', - init_script: '/etc/init.d/openafs-client', - systemd_script_template: 'openafs-client-RedHat-systemd-exec', - systemd_unit_template: 'openafs-client-RedHat-systemd-exec.service', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-compat', 'openafs-krb5', 'dkms', 'dkms-openafs', 'glibc-devel', 'libgcc.i686'], allow_unsupported_modules: false, }, @@ -53,10 +42,6 @@ def platforms cache_path: '/usr/vice/cache', config_client_dkms: true, config_client_path: '/etc/sysconfig/openafs-client', - service_provider: 'systemd', - init_script: '/etc/init.d/openafs-client', - systemd_script_template: 'openafs-client-RedHat-systemd-exec', - systemd_unit_template: 'openafs-client-RedHat-systemd-exec.service', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-compat', 'openafs-krb5', 'dkms', 'dkms-openafs', 'glibc-devel', 'libgcc.i686'], allow_unsupported_modules: false, }, @@ -66,8 +51,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: false, config_client_path: '/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Suse-init', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-kernel-source', 'openafs-krb5-mit'], allow_unsupported_modules: false, }, @@ -77,9 +60,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: false, config_client_path: '/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Suse-init', - systemd_unit_template: 'openafs-client-Suse-systemd-sysv.service', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-kernel-source', 'openafs-krb5-mit'], allow_unsupported_modules: true, }, @@ -89,9 +69,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: false, config_client_path: '/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - systemd_script_template: 'openafs-client-Suse-systemd-exec', - systemd_unit_template: 'openafs-client-Suse-systemd-exec.service', package_name: ['openafs', 'openafs-client', 'openafs-docs', 'openafs-kernel-source', 'openafs-krb5-mit'], allow_unsupported_modules: true, }, @@ -101,8 +78,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: true, config_client_path: '/etc/default/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Ubuntu-init', package_name: ['openafs-modules-dkms', 'openafs-modules-source', 'openafs-client', 'openafs-doc', 'openafs-krb5', 'dkms'], allow_unsupported_modules: false, }, @@ -112,8 +87,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: true, config_client_path: '/etc/default/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Ubuntu-init', package_name: ['openafs-modules-dkms', 'openafs-modules-source', 'openafs-client', 'openafs-doc', 'openafs-krb5', 'dkms'], allow_unsupported_modules: false, }, @@ -123,8 +96,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: true, config_client_path: '/etc/default/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Ubuntu-init', package_name: ['openafs-modules-dkms', 'openafs-modules-source', 'openafs-client', 'openafs-doc', 'openafs-krb5', 'dkms'], allow_unsupported_modules: false, }, @@ -134,8 +105,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: true, config_client_path: '/etc/default/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Ubuntu-init', package_name: ['openafs-modules-dkms', 'openafs-modules-source', 'openafs-client', 'openafs-doc', 'openafs-krb5', 'dkms'], allow_unsupported_modules: false, }, @@ -145,8 +114,6 @@ def platforms cache_path: '/var/cache/openafs', config_client_dkms: true, config_client_path: '/etc/default/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Ubuntu-init', package_name: ['openafs-modules-dkms', 'openafs-modules-source', 'openafs-client', 'openafs-doc', 'openafs-krb5', 'dkms'], allow_unsupported_modules: false, }, @@ -156,8 +123,6 @@ def platforms cache_path: '/usr/vice/cache', config_client_dkms: false, config_client_path: '/usr/vice/etc/sysconfig/openafs-client', - init_script: '/etc/init.d/openafs-client', - init_template: 'openafs-client-Solaris', package_name: ['EISopenafs'], allow_unsupported_modules: false, },