Systemd: Difference between revisions

From Leo's Notes
This page was last edited on 23 March 2015, at 01:27.
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..."
 
No edit summary
Line 26: Line 26:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
#!/bin/sh
#!/bin/sh
StartupDir="/usr/local/boot/startup"


#
# Run all scripts starting with 'S'
# 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
for i in `ls $StartupDir/S*` ; do
         ScriptName=`basename $i`
         ScriptName=`basename $i`
         sh $StartupDir/$ScriptName
         sh $StartupDir/$ScriptName
        ClearPlymouth
done
done


# Success exit code.
exit 0
</syntaxhighlight>


# OK
Make the directory:
exit 0
mkdir -p /usr/local/boot/startup/


</syntaxhighlight>
Then place your scripts in the startup directory starting with the letter 'S'.


[[Category:Linux]]
[[Category:Linux]]

Revision as of 01:27, 23 March 2015

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
StartupDir="/usr/local/boot/startup"

# Run all scripts starting with 'S'
for i in `ls $StartupDir/S*` ; do
        ScriptName=`basename $i`
        sh $StartupDir/$ScriptName
done

# Success exit code.
exit 0

Make the directory:

mkdir -p /usr/local/boot/startup/

Then place your scripts in the startup directory starting with the letter 'S'.