How would I go about running a command at startup in ArchLinux using Systemd like rc.local in Sysv?
- 137
1 Answers
Depends on the command. For the most common cases, you don't need a command.
If you want to adjust a sysctl (a file in
/proc/sys), those can be configured in/etc/sysctl.d/*.conf(generally99-sysctl.confor99-local.conf; manual page):kernel.sysrq = 1 kernel.pid_max = 4194304If it's a module parameter under
/sys/modules, it should be set when the module is first loaded, in/etc/modprobe.d/*.conf(generallymodprobe.conf; see manual page):options kafs rootcell=stacken.kth.seIf you want to write to a device parameter in
/sys, or if you want to run a program to change the device's settings, write an udev rule that would do this when the device is plugged in and put it in/etc/udev/rules.d/*.rules. The manual page isudev(7), and you'll findudevadm infouseful when trying to match the right device.ACTION=="add", SUBSYSTEM=="net", KERNEL=="eth*", \ RUN+="/usr/bin/ethtool -s %k wol d" # This rule checks if a device has an attribute in its /sys subdir: ACTION=="add", \ SUBSYSTEM=="scsi_host", \ TEST=="link_power_management_policy", \ ATTR{link_power_management_policy}="medium_power"If you want to write to a file anywhere else, or create a file or directory, use
/etc/tmpfiles.d(manual page).If you want to load a module, put its name in a file in
/etc/modules-load.d/*.conf(manual page).Finally, if you want to run a general command or start a daemon, write a
.serviceunit file (one of many manual pages). Put it in/etc/systemd/system/*.service, and use the many examples in/lib/systemd/system. It'll be managed throughsystemctl.A few things to note: the
Type=parameter has to be set right (simplevsforkingvsoneshot), and theExecStart=parameter requires a simple command line and does not accept shell-like syntax (no>, no&&, no$(...)and so on, only simple$ENVVARand%x.)It is possible to order services after a specific device appears, using
After=name.device(e.g.After=sys-subsystem-net-devices-%i.device).
Both #archlinux and #systemd have their IRC channels on the freenode network.
- 501,077