Systemd

From Leo's Notes
Revision as of 01:21, 23 March 2015 by 10.1.1.3 (talk) (Created page with " == SystemV-like Init Scripts == If you have custom packages that make use of the old SystemV startup scripts, you can use the following files to make use of such scripts. I...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 23 March 2015, at 01:21.

SystemV-like Init Scripts

If you have custom packages that make use of the old SystemV startup scripts, you can use the following files to make use of such scripts.

In /etc/systemd/system/cpsc-initd.service

[Unit]
Description=CPSC SystemV-like startup scripts
ConditionFileIsExecutable=/usr/local/sbin/cpsc-initd

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/cpsc-initd
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

In /usr/local/sbin/cpsc-initd:

#!/bin/sh

#
# This script will execute all scripts that are placed under
#    /usr/cpsc/boot/startup/
# on runlevels 345
#
# On the first initial boot (after install), scripts under
#    /usr/cpsc/boot/firstrun/
# will execute before the startup scripts.
#
# This script runs after network has been brought up, but
# before any services starts. (S29)
#
# This script will also create a file at
#     /usr/cpsc/boot/initialized
# if it doesn't already exist and will run the firstrun scripts.
#
# Why: Simplifies how scripts are added to the startup process.
#   Also makes it easier to run certain scripts one time.
#
InitializedFile="/usr/cpsc/boot/initialized"
FirstRunDir="/usr/cpsc/boot/firstrun/"
StartupDir="/usr/cpsc/boot/startup/"

ClearPlymouth() {
    plymouth display-message --text=""
}

Uptime=$(</proc/uptime)
Uptime=${Uptime%%.*}

if [ ! -e $InitializedFile ] ; then
        # Do not run X before we finish initialization.
        systemctl isolate multi-user.target &

    # Run every script in the firstrun directory starting with S.
    # Every script that gets executed will be renamed to start with a K.
    # Thus, it's possible for your firstrun scripts to reboot the machine
    # without having it loop infinitely.
    echo "!! Initialization started on `date`" >>  $InitializedFile.log
    echo "----------------------------------" >> $InitializedFile.log

    for i in `ls $FirstRunDir/S*` ; do
                ScriptName=`basename $i`
                KScriptName=`echo $ScriptName|sed 's/^S/K/'`
                mv $FirstRunDir/$ScriptName $FirstRunDir/$KScriptName

                echo ":: Running $ScriptName on `date`" >>  $InitializedFile.log
                sh $FirstRunDir/$KScriptName >> $InitializedFile.log

                ClearPlymouth
    done

        echo `date` > $InitializedFile

        reboot
        exit
fi


for i in `ls $StartupDir/S*` ; do
        ScriptName=`basename $i`
        sh $StartupDir/$ScriptName
        ClearPlymouth
done


# OK
exit 0