# ------------------------------------------------------------------------------ # Configure machine for ceph (or samba) mount # This file is part of the init.sh project # Copyright (c) 2019-2021 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: # https://opensource.org/licenses/BSD-3-Clause # ------------------------------------------------------------------------------ # Variable: # * CEPHSRVNAMES: hosts names of ceph servers # * CEPHIP_srv: with "srv" being a ceph server hostname, its corresponding IP # * SHAREDHOME: Set at yes if homedir is a directory of the ceph mount # * SMBSRV: Fallback samba server on unsupported architectures # Mount points are hardcoded and should bet set differently # ------------------------------------------------------------------------------ export VER_conf_ceph="0.0.2" export DEP_conf_ceph="upgrade_dist" conf_ceph() { # Create mount point directories echo "Creating mount points" mkdir -pv /srv/ceph/share mkdir -pv /share local success=undef if [[ $CEPH_STATUS == ceph ]]; then # Install ceph package pkginst ceph-common # hosts files required for Ceph bootstrap when DNS not yet started if [[ ! $(grep "# Ceph" /etc/hosts) ]]; then prnt I "Adding server list to /etc/hosts" backupdist /etc/hosts echo >> /etc/hosts echo "# Ceph servers:" >> /etc/hosts for srv in $CEPH_SRV_NAMES; do local line="$(eval echo \$CEPHIP_$srv) $srv.$MAINDOM $srv" prnt m " - Adding line $line to /etc/hosts" echo "$line" >> /etc/hosts done else prnt W "Ceph servers already in /etc/hosts, nothing to do" fi backupdist /etc/fstab prnt I "Adding ceph entries to /etc/fstab" echo >> /etc/fstab local srvlist=$(echo $CEPH_SRV_NAMES | sed "s/ /,/g") if [[ ! $(grep $srvlist /etc/fstab) ]]; then echo "# Ceph :" >> /etc/fstab echo "$srvlist:/ /srv/ceph ceph defaults,_netdev,name=admin,secret=$CEPH_SECRET 0 0" >> /etc/fstab else prnt W "Ceph entry already in /etc/fstab, nothing to do" fi unset srvlist success=yes elif [[ $CEPH_STATUS == smb ]]; then pkginst smbclient backupdist /etc/fstab prnt I "Adding Samba entries to /etc/fstab" echo >> /etc/fstab if [[ ! $(grep $SMBSRV /etc/fstab) ]]; then echo "# Samba:" >> /etc/fstab echo "//$SMBSRV/share /srv/ceph/share cifs defaults,_netdev,username=root,password= 0 0" >> /etc/fstab else prnt W "Samba entry already in /etc/fstab, nothing to do" fi success=yes else prnt E "Ceph status not understood, the next tasks will probably fail" fi if [[ $success == yes ]]; then if [[ ! $(grep "^/srv/ceph/share" /etc/fstab) ]]; then echo "/srv/ceph/share /share none defaults,_netdev,bind 0 0" >> /etc/fstab if [[ $SHARED_HOME == 1 ]]; then echo "/srv/ceph/share/home /home none defaults,_netdev,bind 0 0" >> /etc/fstab fi fi else prnt E "Failed creating original mount, not adding binded ones" fi # Mount Ceph volumes if required prnt I "Mounting ceph volumes" [[ ! $(mount | grep "on /srv/ceph") ]] && mount -v /srv/ceph || mount -v /srv/ceph/share [[ ! $(mount | grep "on /share") ]] && mount -v /share if [[ $SHARED_HOME == "true" ]]; then [[ ! $(mount | grep "on /home") ]] && mount -v /home fi } precheck_conf_ceph() { if [[ $SYS_ARCH == "x86_64" ]]; then prnt I "Installing ceph client package..." CEPH_STATUS=ceph else prnt W "System incompatible with ceph, falling back to samba..." CEPH_STATUS=smb fi } export -f conf_ceph export -f precheck_conf_ceph