:: Re: [DNG] Runit service depend anot…
Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: viverna
Ημερομηνία:  
Προς: dng
Αντικείμενο: Re: [DNG] Runit service depend another script not daemon
il devuanizzato Steve Litt <slitt@???> il 06-07-19 07:24:37 ha scritto:
>> Instead it's possible
>> inject in all daemon's install a piece of posix shell?
>> Workaround script on event "DPkg::Post-Invoke" as I said in the
>> previous email?
>
>You know much more than I do about packaging. Given something like
>event "DPkg::Post-Invoke", all it would need to do is call a
>shellscript, with the argument of the daemon name, and the shellscript
>could make the necessary symlinks or whatever. All the heavy lifting
>would still be done in the runit-runscripts package.

Put my code here.

Work for epoch init system but it is adaptable to any other such as
runit, s6 and so on...

Run script on event Pre-Invoke and Post-Invoke:

====================================
#/etc/apt/apt.conf.d/99_dpkg_init_script
DPkg::Pre-Invoke { "/usr/local/bin/dpkg_init_script 1"; };
DPkg::Post-Invoke { "/usr/local/bin/dpkg_init_script 2"; };
====================================


The script (it should run for apt, apt-get, aptitude invoke and so on...):

====================================
#!/bin/sh
#/usr/local/bin/dpkg_init_script

HIGH_EVID="\033[31m"
HIGH_NORM="\033[0m"

MOD_INSTALL=1
MOD_REMOVE=2
MOD_PURGE=3

# Scan command line and find command
command()
{
    if [ "$#" -eq "1" ]; then
        CMD=$1
        if [ "$CMD" = "install" ]; then
            return $MOD_INSTALL
        elif [ "$CMD" = "remove" ]; then
            return $MOD_REMOVE
        elif [ "$CMD" = "purge" ]; then
            return $MOD_PURGE
        else
            return 0
        fi
        return 0
    else
        return 0
    fi


}


# Epoch init system install/remove
epoch()
{
    if [ "$#" -eq "2" ]; then
        ACTION=$1
        PACKAGE=$2

        
        INIT_EPOCH_BIN="/usr/local/sbin/epoch"
        INIT_EPOCH_ETC="/etc/epoch/epoch.conf"
        INIT_EPOCH_PKG_DIR="/etc/epoch/object/"
        INIT_EPOCH_PKG_DIRESC="\/etc\/epoch\/object\/"
        INIT_EPOCH_PKG_REP="/etc/epoch/repo/"

        
        # If not present epoch do not do nothing
        if [ -x "$INIT_EPOCH_BIN" -a -f "$INIT_EPOCH_ETC" -a -d "$INIT_EPOCH_PKG_DIR" -a -d "$INIT_EPOCH_PKG_REP" -a -f "$INIT_EPOCH_PKG_REP$PACKAGE.conf" ]; then
            if [ "$ACTION" -eq "$MOD_INSTALL" ]; then
                echo cp $INIT_EPOCH_PKG_REP$PACKAGE.conf $INIT_EPOCH_PKG_DIR$PACKAGE.conf
                cp $INIT_EPOCH_PKG_REP$PACKAGE.conf $INIT_EPOCH_PKG_DIR$PACKAGE.conf
                echo sed -i "\$aImport $INIT_EPOCH_PKG_DIR$PACKAGE.conf" $INIT_EPOCH_ETC
                sed -i "\$aImport $INIT_EPOCH_PKG_DIR$PACKAGE.conf" $INIT_EPOCH_ETC
            elif [ "$ACTION" -eq "$MOD_REMOVE" -o "$ACTION" -eq "$MOD_PURGE" ]; then
                echo rm $INIT_EPOCH_PKG_DIR$PACKAGE.conf
                rm $INIT_EPOCH_PKG_DIR$PACKAGE.conf
                echo sed -i "/Import $INIT_EPOCH_PKG_DIRESC$PACKAGE.conf/d" $INIT_EPOCH_ETC
                sed -i "/Import $INIT_EPOCH_PKG_DIRESC$PACKAGE.conf/d" $INIT_EPOCH_ETC
            fi
        fi
    fi
}




if [ "$#" -eq "1" ]; then
    DPKG_PHASE=$1
else
    echo "arg err"
    exit
fi



APTPID=$( ps -ho ppid "${PPID}" | sed 's/^ *//' | sed 's/ *$//' )
APTCMD=$( ps -ho args "${APTPID}" | sed 's/^ *//' | sed 's/ *$//' )


VAR=$APTCMD
while test -n "$VAR" ; do
    IFS=' ' read -r VAR ALL <<- XXX
    $VAR
    XXX

    
    command $VAR
    ACTION=$?


    if [ "$ACTION" -ne "0" ]; then
        VAR=$ALL
        break;
    fi

    
    VAR=$ALL
done


EXDPKG=`dpkg-query -W -f='${binary:Package}\t${db:Status-Abbrev}\n' $ALL 2>/dev/null`
echo exdpkg: $EXDPKG



if [ "$DPKG_PHASE" -eq "1" ]; then
    printf "${HIGH_EVID}Pre-invoke${HIGH_NORM}\n"
    #printf "%s\n" $EXDPKG |
    dpkg-query -W -f='${binary:Package}\t${db:Status-Abbrev}\n' $ALL 2>/dev/null |
    while read PACKAGE STATUS
    do
        printf "${HIGH_EVID}Package %s Status %s${HIGH_NORM}\n" $PACKAGE $STATUS
        if [ "$ACTION" -eq "$MOD_REMOVE" -o "$ACTION" -eq "$MOD_PURGE" ]; then
            if [ "$STATUS" = "ii" -o "$STATUS" = "ri" -o "$STATUS" = "pi" ]; then
                # If exists package, is remove command and package is installed, remove script
                # aptitude return "pi" instead of "ii", remove alike
                printf "${HIGH_EVID}Remove script${HIGH_NORM}\n" $PACKAGE $STATUS

                
                # Epoch init system
                epoch $ACTION $PACKAGE
                # Runit
                #runit $ACTION $PACKAGE
                # Other init
                #otherinit $ACTION $PACKAGE
            fi
        fi
    done
elif [ "$DPKG_PHASE" -eq "2" ]; then
    printf "${HIGH_EVID}Post-invoke${HIGH_NORM}\n"
    #printf "%s\n" $EXDPKG |
    dpkg-query -W -f='${binary:Package}\t${db:Status-Abbrev}\n' $ALL 2>/dev/null |
    while read PACKAGE STATUS
    do
        echo Package $PACKAGE Status $STATUS
        if [ "$ACTION" -eq "$MOD_INSTALL" ]; then
            if [ "$STATUS" = "ii" ]; then
                # If exist package, is install command and package it was just installed, install script
                printf "${HIGH_EVID}Install script${HIGH_NORM}\n" $PACKAGE $STATUS

                
                # Epoch init system
                epoch $ACTION $PACKAGE
                # Runit
                #runit $ACTION $PACKAGE
                # Other init
                #otherinit $ACTION $PACKAGE
            fi
        fi
    done
else
    echo "nothing"
fi
====================================


For epoch init system it run epoch function.
In /etc/epoch/ there are 2 dir, "repo" and "object".
repo is an "object repository" (objects collection).

When user install a package, if exist in repo/package.conf
copy it in object directory. I don't use symbolic links
because in "repo" there are object distro but in "object"
there are object which can be modified and customized by the user.
Then use the "Import" attribute to generate a row that import object.

When user remove a package, just before remove package, delete object.
Then remove the "Import" attribute generate previously.

For runit simply create a function and copy/remove your files.
For all init system that we intend to support create a function and do
stuff.

Below my epoch.conf:

====================================
#/etc/epoch/epoch.conf
#Epoch Init System Configuration for Devuan

BootBannerText=Hello world!
BootBannerColor=CYAN

Hostname=FILE /etc/hostname
DefaultRunlevel=boot
EnableLogging=true
DisableCAD=true
BlankLogOnBoot=true

# DEFINE PRIORITY CONSTANTS
DefinePriority=Start_Sysclock 1
DefinePriority=Start_Fs_H 4
DefinePriority=Start_Fs_M 5
DefinePriority=Start_Fs_L 6
DefinePriority=Start_Daemon_First 9
DefinePriority=Start_Log 10
DefinePriority=Start_Daemon_H 11
DefinePriority=Start_Daemon_M 14
DefinePriority=Start_Daemon_L 18
DefinePriority=Start_Network 19
DefinePriority=Start_Network_Daemon_H 20
DefinePriority=Start_Network_Daemon_M 24
DefinePriority=Start_Network_Daemon_L 28
DefinePriority=Start_Other_Daemon_H 31
DefinePriority=Start_Other_Daemon_M 34
DefinePriority=Start_Other_Daemon_L 37
DefinePriority=Start_Early_Getty 40
DefinePriority=Start_Getty 45
DefinePriority=Start_Display_Manager 49

DefinePriority=Stop_Display_Manager 51
DefinePriority=Stop_Daemon_H 51
DefinePriority=Stop_Daemon_M 55
DefinePriority=Stop_Daemon_L 59
DefinePriority=Stop_Log 65
DefinePriority=Stop_Network 70
DefinePriority=Stop_Sysclock 80
DefinePriority=Stop_Kill_Soft 95
DefinePriority=Stop_Kill 96
DefinePriority=Stop_Fs_H 97
DefinePriority=Stop_Fs_M 98
DefinePriority=Stop_Fs_L 99

Import /etc/epoch/object/acpid.conf
Import /etc/epoch/object/anacron.conf
Import /etc/epoch/object/at.conf
Import /etc/epoch/object/clamav-freshclam.conf
Import /etc/epoch/object/console-setup.conf
Import /etc/epoch/object/coreutils.conf
Import /etc/epoch/object/cron.conf
Import /etc/epoch/object/dbus.conf
Import /etc/epoch/object/gpm.conf
Import /etc/epoch/object/ifupdown.conf
Import /etc/epoch/object/irqbalance.conf
Import /etc/epoch/object/openssh-server.conf
Import /etc/epoch/object/pcscd.conf
Import /etc/epoch/object/rsyslog.conf
Import /etc/epoch/object/smartmontools.conf
Import /etc/epoch/object/util-linux.conf
Import /etc/epoch/object/xinetd.conf
Import /etc/epoch/object/xorg.conf


====================================

I tested above scripts in my computers but they should be well tested.
I consider them a workaround more than a "clean" solution.

--
viverna