How to use systemd to just run some stuff on boot

January 11, 2012

Suppose that you have some things that you want to get run when your system boots, much like rc.local. They aren't necessarily daemons, you don't want to wire them up to the whole systemd magic infrastructure, you just want to run something. Let us assume that you have some shell scripts for simplicity (if you don't, it's easy to convert what you need into one or more shell scripts).

When I was converting my old init.d stuff to systemd, here is how I did this:

[Unit]
Description=Run my stuff
After=network.target
Requires=network.target

[Service]
Type=oneshot
RemainAfterExit=True
ExecStart=/some/script
ExecStart=/some/other/script

[Install]
WantedBy=multi-user.target

(The systemd service that actually runs /etc/rc.d/rc.local is a bit different; see /lib/systemd/system/rc-local.service, at least on Fedora.)

If you want your rc.local equivalent to be started just as gettys and any graphical login manager are being started, it appears that you want to be after systemd-user-sessions.service. Most of the startup stuff I do doesn't need to be run that late but it does depend on networking being fully up so that the machine has an IP address and all its interfaces and so on.

(One of my wishlist items for systemd is the ability for services to depend on and be triggered on various sorts of network state changes. I suspect that the systemd people see this as more the job of NetworkManager and dbus in general, but NM is not something that I can use and I'd rather avoid having a second dependency and state change management system to handle dbus events when we already have a perfectly good general one in systemd.)

Written on 11 January 2012.
« An insight on the purpose of comments: volume control
A Yum plugin I would like: using a local DVD as a repo source »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Jan 11 01:26:07 2012
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.