Difference between revisions of "Systemd/Services"

From ArchWiki
Jump to: navigation, search
(ddclient: ddclient.service included with the package)
Line 435: Line 435:
 
WantedBy=multi-user.target
 
WantedBy=multi-user.target
  
 +
</nowiki>}}
 +
 +
== vncserver (either tigervnc or tightvnc)
 +
{{hc|/etc/systemd/system/vncserver@1.service|
 +
<nowiki>
 +
# The vncserver service unit file
 +
#
 +
# Quick HowTo:
 +
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
 +
# 2. Edit <USER> and vncserver parameters appropriately
 +
#  ("runuser -l <USER> -c /usr/bin/vncserver -arg1 -arg2 -argn %i")
 +
# 3. Run `systemctl daemon-reload`
 +
# 4. Run `systemctl enable vncserver@:<display>.service`
 +
 +
[Unit]
 +
Description=Remote desktop service (VNC)
 +
After=syslog.target network.target
 +
 +
[Service]
 +
Type=forking
 +
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
 +
ExecStart=/bin/su <USER> -c "/usr/bin/vncserver  %i"
 +
ExecStop=/bin/su <USER> -c "/usr/bin/vncserver -kill %i"
 +
 +
[Install]
 +
WantedBy=multi-user.target
 
</nowiki>}}
 
</nowiki>}}
  

Revision as of 22:13, 31 October 2012

Summary help replacing me
Related
Systemd

This page is useful to publish systemd service files that are missing in the appropriate package in the repositories. These files can be copied from other distributions or created by yourself.

Adsuck

/etc/systemd/system/adsuck.service
[Unit]
Description=Adsuck daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/adsuck -l 127.0.0.1 -c /var/adsuck -f /resolv.conf /hosts -r /filter
ExecStartPost=/bin/sh -c "echo 'nameserver 127.0.0.1' > /etc/resolv.conf"
ExecStop=/bin/kill $MAINPID
ExecStopPost=/bin/sh -c "cp /var/adsuck/resolv.conf /etc/resolv.conf"
ExecReload=/bin/kill -HUP $MAINPID ; /bin/kill -USR1 $MAINPID

[Install]
WantedBy=multi-user.target
Note: Script based on the comment on the AUR package page.


BOINC Daemon

/etc/systemd/system/boinc.service
[Unit]
Description=BOINC Daemon

[Service]
User=boinc
Nice=19
ExecStart=/usr/bin/boinc_client --dir /var/lib/boinc --redirectio

[Install]
WantedBy=multi-user.target

Courier-IMAP

/etc/systemd/system/authdaemond.service
[Unit]
Description=Courier Authentification Daemon

[Service]
Type=forking
ExecStart=/usr/sbin/authdaemond start
ExecStop=/usr/sbin/authdaemon stop
PIDFile=/run/authdaemon/pid

[Install]
WantedBy=multi-user.target
/etc/systemd/system/courier-imapd.service
[Unit]
Description=Courier IMAP Daemon
Requires=authdaemond.service
After=authdaemond.service

[Service]
Type=forking
EnvironmentFile=/etc/courier-imap/imapd
ExecStart=/usr/lib/courier-imap/imapd.rc start
ExecStop=/usr/lib/courier-imap/imapd.rc stop
PIDFile=/var/run/courier/imapd.pid

[Install]
WantedBy=multi-user.target
/etc/systemd/system/courier-imapd-ssl.service
[Unit]
Description=Courier IMAP Daemon
Requires=authdaemond.service
After=authdaemond.service

[Service]
Type=forking
EnvironmentFile=/etc/courier-imap/imapd
ExecStart=/usr/lib/courier-imap/imapd-ssl.rc start
ExecStop=/usr/lib/courier-imap/imapd-ssl.rc stop
PIDFile=/var/run/courier/imapd-ssl.pid

[Install]
WantedBy=multi-user.target
/usr/lib/tmpfiles.d/authdaemond.conf
D /run/authdaemon 0755 courier courier
/usr/lib/tmpfiles.d/courier-imapd.conf
D /run/courier 0755 courier courier
Note: Taken from Gentoo and modified for Arch. You could replace the files in tmpfiles.d with appropriate ExecStartPre calls as well. Service files for pop3d and pop3d-ssl are still missing, but are probably very similar to the imapd files!
Warning: Beware that you may need to add Requires=network.target to certain units like mythtv or chrony if you use this unit

dropbear

/etc/systemd/system/dropbear.service

[Unit]
Description=Dropbear SSH server

[Service]
Type=oneshot
ExecStart=/usr/sbin/dropbear -p 22 -d /etc/dropbear/dropbear_dss_host_key -w -P /var/run/dropbear.pid
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Folding@home SMP

See the comment on the AUR package. The unit file is copied below for convenience.

/etc/systemd/system/foldingathome-smp.service

[Unit]
Description=Folding@home distributed computing client
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/fah-smp
ExecStart=/opt/fah-smp/fah6 -smp -verbosity 9 -forceasm

[Install]
WantedBy=multi-user.target

IPv6 (Hurricane Electric)

/etc/systemd/system/he-ipv6.service

[Unit]
Description=he.net IPv6 tunnel
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/ip tunnel add he-ipv6 mode sit remote 209.51.161.14 local <local IPv4> ttl 255
ExecStart=/sbin/ip link set he-ipv6 up mtu 1480
ExecStart=/sbin/ip addr add <local IPv6>/64 dev he-ipv6
ExecStart=/sbin/ip -6 route add ::/0 dev he-ipv6
ExecStart=/sbin/ip addr add <public IPv6>/64 dev he-ipv6
ExecStop=/sbin/ip -6 route del ::/0 dev he-ipv6
ExecStop=/sbin/ip link set he-ipv6 down
ExecStop=/sbin/ip tunnel del he-ipv6

[Install]
WantedBy=multi-user.target

Logmein Hamachi

/etc/systemd/system/hamachi.service
[Unit]
Description=Hamachi Daemon
After=network.target

[Service]
Type=forking
ExecStart=/opt/logmein-hamachi/bin/hamachid

[Install]
WantedBy=multi-user.target

Noip

/etc/systemd/system/noip2.service
[Unit]
Description=No-IP Dynamic DNS Update Client
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/noip2

[Install]
WantedBy=multi-user.target

pcscd

/etc/systemd/system/pcscd.service
[Unit]
Description=PC/SC Smart Card Daemon
Requires=pcscd.socket

[Service]
ExecStart=/usr/sbin/pcscd --foreground --auto-exit
ExecReload=/usr/sbin/pcscd --hotplug
StandardOutput=syslog

[Install]
Also=pcscd.socket
/etc/systemd/system/pcscd.socket
[Unit]
Description=PC/SC Smart Card Daemon Activation Socket

[Socket]
ListenStream=/var/run/pcscd/pcscd.comm

[Install]
WantedBy=sockets.target

Reference:

Remote filesystem mounts

See: Systemd#Remote_filesystem_mounts

screen

Autostarts screen for the specified user. (e.g. `systemctl enable screen@florian.service`)

/etc/systemd/system/screen@.service
[Unit]
Description=screen
After=network.target

[Service]
Type=forking
User=%i
ExecStart=/usr/bin/screen -dmS autoscreen
ExecStop=/usr/bin/screen -S autoscreen -X quit

[Install]
WantedBy=multi-user.target

Static Ethernet network

This is a custom service file for static Ethernet configurations. For other configurations, see Systemd#Network

Warning: Beware, you may have to add 'Requires=network.target' for certain services like chrony or mythtv when using this.
/etc/conf.d/network
interface=eth0
address=192.168.0.1
netmask=24
broadcast=192.168.0.255
gateway=192.168.0.254
/etc/systemd/system/network.service
[Unit]
Description=Network Connectivity
Wants=network.target
Before=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network
ExecStart=/sbin/ip link set dev ${interface} up
ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface}
ExecStart=/sbin/ip route add default via ${gateway}
ExecStop=/sbin/ip addr flush dev ${interface}
ExecStop=/sbin/ip link set dev ${interface} down

[Install]
WantedBy=multi-user.target

Set network interface in promiscuous mode

/etc/systemd/system/promiscuous@.service
[Unit]
Description=Set %i interface in promiscuous mode

[Service]
Type=oneshot
ExecStart=/usr/sbin/ip link set dev %i promisc on
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

If you want to enable promiscuous mode on interface eth0 run:

 # systemctl enable promiscuous@eth0.service

tpfand

/etc/systemd/system/tpfand.service
[Unit]
Description=ThinkPad Fan Control

[Service]
Type=forking
PIDFile=/var/run/tpfand.pid
ExecStart=/usr/sbin/tpfand

[Install]
WantedBy=multi-user.target

truecrypt volume setup

This service employ truecrypt as a mapper only and requires you to create an entry in fstab to mount the mapped & unencrypted device to your desired mountpoint like for instance so:

/etc/fstab
/dev/mapper/truecrypt1  /home/          ext4 defaults        0       2

The 2 means your fs will be fscked regularly.

/usr/lib/systemd/system/truecrypt@.service
[Unit]
Description=Truecrypt Setup for %I
DefaultDependencies=no
Conflicts=umount.target
Before=umount.target
After=systemd-readahead-collect.service systemd-readahead-replay.service

[Service]
RemainAfterExit=yes
StandardInput=tty-force
ExecStart=/usr/bin/truecrypt --filesystem=none %I
ExecStop=/usr/bin/truecrypt --filesystem=none -d %I

[Install]
WantedBy=cryptsetup.target

If your encrypted volume is /dev/sda2, you would enable the service with this command:

# systemctl enable truecrypt@dev-sda2.service
Note: Although it works, this service should stil be considered experimental, there might be better solutions to use truecrypt with systemd. If you use mpd or any other programme that needs to access the encrypted filesystem, put it into the line starting with Before=. Cheers to dgbaley27 for basically writing this! Improvements welcome!

truecrypt (mount encrypted fs)

/etc/systemd/system/multi-user.target/truecrypt-mount.service
[Unit]
Description=Mount Truecrypt-encrypted filesystems
ConditionFileIsExecutable=/usr/bin/truecrypt
#Requires=truecrypt-unmount.service
#Before=mpd.service
 
[Service]
Type=oneshot
ExecStart=/usr/bin/truecrypt -t /dev/sdXY /MOUNTPOINT
StandardInput=tty-force
RemainAfterExit=yes
 
[Install]
WantedBy=multi-user.target
#Also=truecrypt-unmount.service
Note: Gleaned from bpont on the forums. If you use mpd and have your music dir in ~, uncomment Before=mpd.service, which takes care that mpd is started after this script. If you also use truecrypt-unmount.service (see next service) uncomment the Requires=truecrypt-unmount.service and Also=truecrypt-unmount.service so it gets installed and activated by systemd automatically when using this script.

truecrypt (unmount encrypted fs)

/etc/systemd/system/multi-user/truecrypt-unmount.service
[Unit]
Description=Truecrypt unmount on shutdown, poweroff, reboot, system halt
Before=local-fs-pre.target
#Before=mpd.service
ConditionPathExistsGlob=/media/truecrypt*
DefaultDependencies=no

[Service]
Type=oneshot
ExecStart=/usr/bin/truecrypt -d
TimeoutSec=5
StandardInput=tty

[Install]
WantedBy=shutdown.target reboot.target halt.target poweroff.target
Note: I don't know if this works yet. It may be necessary to replace TimeoutSec=5 with ExecStart=sleep 5. If you use mpd, make sure to uncomment Before=mpd.service to make sure this service is executed after mpd is closed down (different order during the shutdown of processes than during start up!). Script gleaned from tladuke on the forums.

verynice

/etc/systemd/system/verynice.service
[Unit]
Description=A tool for dynamically adjusting the nice-level of processes

[Service]
Type=forking
PIDFile=/var/run/verynice.pid
ExecStart=/usr/sbin/verynice -d /var/run/verynice.pid
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

VideoLAN 2.0

Change the User parameter.

/etc/systemd/system/vlc.service
[Unit]
Description=VideoOnLAN Service
After=network.target

[Service]
Type=forking
User=nobody
ExecStart=/usr/bin/cvlc --intf=lua --lua-intf=http --daemon --http-port 8090
Restart=on-abort

[Install]
WantedBy=multi-user.target

Xvfb

Change the User/Group parameters.

/etc/systemd/system/xinit.service
[Unit]
Description=xinit with xvfb
After=network.target

[Service]
User=bitlbee
Group=bitlbee
ExecStart=/usr/bin/xvfb-run bash %h/.xinitrc

[Install]
WantedBy=multi-user.target

ZNC

Assuming znc was set up to be run by znc user from /var/lib/znc as explained in the Znc wiki page.

/etc/systemd/system/znc.service
[Unit]
Description=ZNC Daemon
After=network.target

[Service]
ExecStart=/usr/bin/znc -f
User=znc

[Install]
WantedBy=multi-user.target

== vncserver (either tigervnc or tightvnc)

/etc/systemd/system/vncserver@1.service

# The vncserver service unit file
#
# Quick HowTo:
# 1. Copy this file to /etc/systemd/system/vncserver@:<display>.service
# 2. Edit <USER> and vncserver parameters appropriately
#   ("runuser -l <USER> -c /usr/bin/vncserver -arg1 -arg2 -argn %i")
# 3. Run `systemctl daemon-reload`
# 4. Run `systemctl enable vncserver@:<display>.service`

[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target

[Service]
Type=forking
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/bin/su <USER> -c "/usr/bin/vncserver  %i"
ExecStop=/bin/su <USER> -c "/usr/bin/vncserver -kill %i"

[Install]
WantedBy=multi-user.target

See also