Systemd: Difference between revisions
From Leo's Notes
This page was last edited on 23 March 2015, at 06:58.
No edit summary |
No edit summary |
||
| Line 4: | Line 4: | ||
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. | 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 <code>/ | In <code>/usr/lib/systemd/system/startup.service</code> | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
[Unit] | [Unit] | ||
Description= | Description=Custom SystemV-like Startup | ||
ConditionFileIsExecutable=/usr/local/sbin/ | After=network.target | ||
ConditionFileIsExecutable=/usr/local/sbin/custom-startup-initd | |||
[Service] | [Service] | ||
Type=oneshot | Type=oneshot | ||
ExecStart=/usr/local/sbin/ | ExecStart=/usr/local/sbin/custom-startup-initd | ||
TimeoutSec=0 | TimeoutSec=0 | ||
StandardOutput=tty | StandardOutput=tty | ||
| Line 23: | Line 24: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
In <code>/usr/local/sbin/ | A few things of interest. | ||
* The <code>ConditionFileIsExecutable</code> will only run the script if it's executable. It basically does a <code>test -x</code> on the file before this continues. | |||
* <code>RemainAfterExit</code> will cause systemd to show the service as active even after the script has finished execution. | |||
In <code>/usr/local/sbin/custom-startup-initd</code>: | |||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
#!/bin/sh | #!/bin/sh | ||
Revision as of 06:58, 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 /usr/lib/systemd/system/startup.service
[Unit]
Description=Custom SystemV-like Startup
After=network.target
ConditionFileIsExecutable=/usr/local/sbin/custom-startup-initd
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/custom-startup-initd
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
A few things of interest.
- The
ConditionFileIsExecutablewill only run the script if it's executable. It basically does atest -xon the file before this continues. RemainAfterExitwill cause systemd to show the service as active even after the script has finished execution.
In /usr/local/sbin/custom-startup-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'.