Systemd: Difference between revisions
From Leo's Notes
This page was last edited on 9 December 2015, at 21:58.
journal |
m fix highlighting |
||
| Line 6: | Line 6: | ||
Clear all the entries by running: | Clear all the entries by running: | ||
{{highlight|lang= | {{highlight|lang=terminal|code= | ||
journalctl --vacuum-time=1seconds | # journalctl --vacuum-time=1seconds | ||
}} | }} | ||
== SystemV-like Init Scripts == | == SystemV-like Init Scripts == | ||
| Line 17: | Line 14: | ||
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 | In {{code|/usr/lib/systemd/system/startup.service}} | ||
{{highlight|lang=text|code= | |||
[Unit] | [Unit] | ||
Description=Custom SystemV-like Startup | Description=Custom SystemV-like Startup | ||
| Line 34: | Line 32: | ||
[Install] | [Install] | ||
WantedBy=multi-user.target | WantedBy=multi-user.target | ||
}} | |||
A few things of interest. | A few things of interest. | ||
* The | * The {{code|ConditionFileIsExecutable}} will only run the script if it's executable. It basically does a {{code|test -x}} on the file before this continues. | ||
* | * {{code|RemainAfterExit}} will cause systemd to show the service as active even after the script has finished execution. | ||
In | In {{code|/usr/local/sbin/custom-startup-initd}}: | ||
{{highlight|lang=bash|code= | |||
#!/bin/sh | #!/bin/sh | ||
StartupDir="/usr/local/boot/startup" | StartupDir="/usr/local/boot/startup" | ||
| Line 55: | Line 53: | ||
# Success exit code. | # Success exit code. | ||
exit 0 | exit 0 | ||
}} | |||
Make the directory: | Make the directory: | ||
{{highlight|lang=terminal|code= | |||
# mkdir -p /usr/local/boot/startup/ | |||
}} | |||
Then place your scripts in the startup directory starting with the letter 'S'. | Then place your scripts in the startup directory starting with the letter 'S'. | ||
Enable the new service by running: | Enable the new service by running: | ||
{{highlight|lang=terminal|code= | |||
# systemctl enable startup | |||
# systemctl start startup | |||
}} | |||
Verify this: | Verify this: | ||
{{highlight|lang=terminal|code= | |||
# systemctl status startup.service | |||
}} | |||
[[Category:Linux]] | [[Category:Linux]] | ||
{{Navbox Linux}} | {{Navbox Linux}} | ||
Revision as of 21:58, 9 December 2015
Journal
Systemd keeps tracks of service logs.
Clearing Journal
Clear all the entries by running:
# journalctl --vacuum-time=1seconds
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'.
Enable the new service by running:
# systemctl enable startup
# systemctl start startup
Verify this:
# systemctl status startup.service