Systemd: Difference between revisions

From miki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
<source lang=bash>
<source lang=bash>
sudo systemctl enable courier-authdaemon
sudo systemctl enable courier-authdaemon
</source>

=== Create a new service ===
From [https://unix.stackexchange.com/questions/15348/writing-basic-systemd-service-files SE]:

* Create a file {{file|/etc/systemd/system/foo.service}}
<source lang="text">
[Unit]
Description=foo

[Service]
ExecStart=/bin/bash -c "while true; do /bin/inotifywait -qq --event close_write /sys/class/backlight/acpi_video0/brightness; su myusername -c '/bin/xbacklight -display :0 -set $(cat /sys/class/backlight/acpi_video0/brightness)'; done"

[Install]
WantedBy=multi-user.target
</source>

Reload systemd:
<source lang="bash">
systemctl daemon-reload
</source>

Enable the new service:
<source lang="bash">
systemctl enable foo
</source>

The service will start automatically at boot. To start it immediately:
<source lang="bash">
systemctl start foo
systemctl status foo # optional, just to verify
</source>
</source>

Revision as of 07:33, 18 September 2017

Usage

  • systemd:0 means first systemd socket defined in the .socket file (FD 3), systemd:1 is the second (FD 4) and so on.

Configure a service to start at boot

sudo systemctl enable courier-authdaemon

Create a new service

From SE:

  • Create a file /etc/systemd/system/foo.service
[Unit]
Description=foo

[Service]
ExecStart=/bin/bash -c "while true; do /bin/inotifywait -qq --event close_write /sys/class/backlight/acpi_video0/brightness; su myusername -c '/bin/xbacklight -display :0 -set $(cat /sys/class/backlight/acpi_video0/brightness)'; done"

[Install]
WantedBy=multi-user.target

Reload systemd:

systemctl daemon-reload

Enable the new service:

systemctl enable foo

The service will start automatically at boot. To start it immediately:

systemctl start foo
systemctl status foo # optional, just to verify