Difference between revisions of "Systemd/Services"

From ArchWiki
Jump to: navigation, search
(removed user question which should be on the discussion page)
(redirect empty page marked for deletion, see also talk page)
 
(170 intermediate revisions by 49 users not shown)
Line 1: Line 1:
{{Lowercase title}}
+
#REDIRECT [[Systemd]]
[[Category:Daemons and system services]]
+
[[Category:Boot process]]
+
{{Article summary start}}
+
{{Article summary heading|Related}}
+
{{Article summary wiki|systemd}}
+
{{Article summary end}}
+
 
+
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 ==
+
{{hc|/etc/systemd/system/adsuck.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{Note|1=Script based on the comment on the {{AUR|adsuck}} [[AUR]] package page.}}
+
 
+
== BOINC Daemon ==
+
{{hc|/etc/systemd/system/boinc.service|<nowiki>
+
[Unit]
+
Description=BOINC Daemon
+
 
+
[Service]
+
User=boinc
+
Nice=19
+
ExecStart=/usr/bin/boinc_client --dir /var/lib/boinc --redirectio
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== Courier-IMAP ==
+
{{hc|/etc/systemd/system/authdaemond.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/courier-imapd.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/courier-imapd-ssl.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{hc|/usr/lib/tmpfiles.d/authdaemond.conf|<nowiki>
+
D /run/authdaemon 0755 courier courier
+
</nowiki>}}
+
 
+
{{hc|/usr/lib/tmpfiles.d/courier-imapd.conf|<nowiki>
+
D /run/courier 0755 courier courier
+
</nowiki>}}
+
 
+
{{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|1=Beware that you may need to add Requires=network.target to certain units like mythtv or chrony if you use this unit }}
+
 
+
== dropbear ==
+
{{hc|/etc/systemd/system/dropbear.service|
+
<nowiki>
+
[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
+
 
+
</nowiki>}}
+
 
+
== IPv6 (Hurricane Electric) ==
+
{{hc|/etc/systemd/system/he-ipv6.service|<nowiki>
+
 
+
[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
+
 
+
</nowiki>}}
+
 
+
== Logmein Hamachi ==
+
{{hc|/etc/systemd/system/hamachi.service|<nowiki>
+
[Unit]
+
Description=Hamachi Daemon
+
After=network.target
+
 
+
[Service]
+
Type=forking
+
ExecStart=/opt/logmein-hamachi/bin/hamachid
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== pcscd ==
+
{{hc|/etc/systemd/system/pcscd.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/pcscd.socket|<nowiki>
+
[Unit]
+
Description=PC/SC Smart Card Daemon Activation Socket
+
 
+
[Socket]
+
ListenStream=/var/run/pcscd/pcscd.comm
+
 
+
[Install]
+
WantedBy=sockets.target
+
</nowiki>}}
+
Reference:
+
* http://ludovicrousseau.blogspot.de/2011/11/pcscd-auto-start-using-systemd.html
+
 
+
== Filesystem mounts ==
+
''See: [[Systemd#Filesystem_mounts]]''
+
 
+
== screen ==
+
Autostarts screen for the specified user. (e.g. `systemctl enable screen@florian.service`)
+
{{hc|/etc/systemd/system/screen@.service|<nowiki>
+
[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</nowiki>}}
+
 
+
== Static Ethernet network ==
+
 
+
This is a custom service file for static Ethernet configurations. For other configurations, see [[Systemd#Network]]
+
{{Warning |1=Beware, you may have to add 'Requires=network.target' for certain services like chrony or mythtv when using this.}}
+
{{hc|/etc/conf.d/network|<nowiki>
+
interface=eth0
+
address=192.168.0.1
+
netmask=24
+
broadcast=192.168.0.255
+
gateway=192.168.0.254</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/network.service|<nowiki>
+
[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</nowiki>}}
+
 
+
== Set network interface in promiscuous mode ==
+
{{hc|/etc/systemd/system/promiscuous@.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
If you want to enable promiscuous mode on interface {{ic|1=eth0}} run:
+
 
+
  # systemctl enable promiscuous@eth0.service
+
 
+
==tmux==
+
Starts screen for specified user (eg. tmux@main-user.service)
+
{{hc|/etc/systemd/system/tmux@.service|<nowiki>
+
[Unit]
+
Description=Start tmux in detached session
+
 
+
[Service]
+
Type=forking
+
ExecStart=/usr/bin/tmux new-session -s %u -d
+
ExecStop=/usr/bin/tmux kill-session -t %u
+
User=%I
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== tpfand ==
+
{{hc|/etc/systemd/system/tpfand.service|<nowiki>
+
[Unit]
+
Description=ThinkPad Fan Control
+
 
+
[Service]
+
Type=forking
+
PIDFile=/var/run/tpfand.pid
+
ExecStart=/usr/sbin/tpfand
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== 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:
+
{{hc|/etc/fstab|<nowiki>
+
/dev/mapper/truecrypt1  /home/          ext4 defaults        0      2</nowiki>}}
+
 
+
The {{ic|2}} means your fs will be fscked regularly.
+
 
+
{{hc|/usr/lib/systemd/system/truecrypt@.service|<nowiki>
+
[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</nowiki>}}
+
 
+
If your encrypted volume is {{ic|1=/dev/sda2}}, you would enable the service with this command:
+
# systemctl enable truecrypt@dev-sda2.service
+
 
+
{{Note|1=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 {{ic|1=Before=}}. Cheers to dgbaley27 for basically writing this! Improvements welcome!}}
+
 
+
{{Note|This way of doing it (specifically the use of tty-force) is not recommended according to [http://lists.freedesktop.org/archives/systemd-devel/2012-October/006905.html this thread], which suggests an alternative approach similar to that taken for LUKS.}}
+
 
+
== truecrypt (mount encrypted fs) ==
+
{{hc|/etc/systemd/system/multi-user.target/truecrypt-mount.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{Note|1=Gleaned  from [https://bbs.archlinux.org/viewtopic.php?pid=1163760#p1163760 bpont on the forums]. If you use mpd and have your music dir in ~, uncomment {{ic|1=Before=mpd.service}}, which takes care that mpd is started after this script. If you also use {{ic|1=truecrypt-unmount.service}} (see next service) uncomment the {{ic|1=Requires=truecrypt-unmount.service}} and {{ic|1=Also=truecrypt-unmount.service}} so it gets installed and activated by systemd automatically when using this script.}}
+
 
+
== truecrypt (unmount encrypted fs) ==
+
{{hc|/etc/systemd/system/multi-user/truecrypt-unmount.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
{{Note|1=I don't know if this works yet. It may be necessary to replace {{ic|1=TimeoutSec=5}} with {{ic|1=ExecStart=sleep 5}}. If you use {{ic|mpd}}, make sure to uncomment {{ic|1=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 [https://bbs.archlinux.org/viewtopic.php?pid=1163334#p1163334 tladuke on the forums].}}
+
 
+
== verynice ==
+
{{hc|/etc/systemd/system/verynice.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
== MPD Socket Activation ==
+
If the following mpd.socket file is enabled while mpd.service (provided by {{Pkg|mpd}}) is disabled, systemd will not start mpd immediately, but it will listen on the appropriate sockets.  When an mpd client attempts to connect on one of those sockets, systemd will start mpd.service and transparently hand over control of those ports to the mpd process.
+
 
+
If you prefer to listen on different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen on network ports at all, you should add/edit/remove the appropriate "ListenStream=" lines in the [Socket] section of mpd.socket ''AND'' modify the appropriate lines /etc/mpd.conf (see "man 5 mpd.conf" for more details).
+
 
+
If you use different (even multiple) network or local sockets, or prefer not to use network sockets at all, simply add, change, or remove lines beginning with "ListenStream=" in the [Socket] section.
+
{{hc|/usr/lib/systemd/system/mpd.socket|<nowiki>
+
[Unit]
+
Description=Music Player Daemon Sockets
+
 
+
[Socket]
+
ListenStream=/var/run/mpd/socket
+
ListenStream=6600
+
 
+
[Install]
+
WantedBy=sockets.target
+
</nowiki>}}
+
 
+
== VideoLAN 2.0 ==
+
Change the '''User''' parameter.
+
 
+
{{hc|/etc/systemd/system/vlc.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
== Xvfb ==
+
Change the '''User'''/'''Group''' parameters.
+
{{hc|/etc/systemd/system/xinit.service|<nowiki>
+
[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
+
</nowiki>}}
+
 
+
== ZNC ==
+
Assuming znc was set up to be run by znc user from {{ic|/var/lib/znc}} as explained in the [[Znc]] wiki page.
+
 
+
{{hc|/etc/systemd/system/znc.service|<nowiki>
+
[Unit]
+
Description=ZNC Daemon
+
After=network.target
+
 
+
[Service]
+
ExecStart=/usr/bin/znc -f -d /var/lib/znc
+
User=znc
+
 
+
[Install]
+
WantedBy=multi-user.target
+
 
+
</nowiki>}}
+
 
+
== Nexus ==
+
This is for Sonatype's Nexus OSS Artifact Repository.
+
{{AUR|nexus2}} is in the [[AUR]].
+
 
+
{{hc|/etc/systemd/system/nexus.service|<nowiki>
+
[Unit]
+
Description=Nexus OSS Artifact Repository
+
 
+
[Service]
+
Type=forking
+
EnvironmentFile=-/etc/conf.d/nexus
+
ExecStart=/opt/nexus/bin/nexus start
+
ExecStop=/opt/nexus/bin/nexus stop
+
ExecReload=/opt/nexus/bin/nexus restart
+
PIDFile=/opt/nexus/run/nexus.pid
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== Gitlab ==
+
 
+
{{hc|/etc/systemd/system/gitlab.service|<nowiki>
+
[Unit]
+
Description=Self Hosted Git Management
+
Requires=postgresql.service redis.service
+
After=postgresql.service redis.service
+
Wants=postfix.service gitlab-worker.service
+
 
+
[Service]
+
Type=forking
+
User=gitlab
+
WorkingDirectory=/home/gitlab/gitlab
+
ExecStart=/home/gitlab/gitlab/script/rails server -d -e production
+
PIDFile=/home/gitlab/gitlab/tmp/pids/server.pid
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/gitlab-worker.service|<nowiki>
+
[Unit]
+
Description=Gitlab Resque Worker
+
Requires=redis.service
+
After=redis.service
+
Wants=postfix.service postgresql.service
+
 
+
[Service]
+
Type=forking
+
User=gitlab
+
WorkingDirectory=/home/gitlab/gitlab
+
ExecStart=/bin/bash -c '. ~/.bashrc; . ./resque.sh'
+
ExecStopPost=/usr/bin/rm /home/gitlab/gitlab/tmp/pids/resque_worker.pid
+
PIDFile=/home/gitlab/gitlab/tmp/pids/resque_worker.pid
+
</nowiki>}}
+
 
+
== Cisco AnyConnect VPN ==
+
 
+
{{hc|/etc/systemd/system/ciscovpn.service|<nowiki>
+
[Unit]
+
Description=Cisco AnyConnect Secure Mobility Client Agent
+
Requires=network.target remote-fs.target
+
After=network.target remote-fs.target
+
 
+
[Service]
+
Type=forking
+
PIDFile=/var/run/vpnagentd.pid
+
ExecStart=/opt/cisco/anyconnect/bin/vpnagentd
+
ExecStop=/usr/bin/killall /opt/cisco/anyconnect/bin/vpnagentd
+
Restart=on-abort
+
 
+
[Install]
+
# one may want to use multi-user.target instead
+
WantedBy=graphical.target
+
</nowiki>}}
+
 
+
== Emacs Daemon ==
+
{{hc|/etc/systemd/system/emacs@.service|<nowiki>
+
[Unit]
+
Description=Emacs: the extensible, self-documenting text editor
+
 
+
[Service]
+
Type=forking
+
ExecStart=/usr/bin/emacs --daemon
+
ExecStop=/usr/bin/emacsclient --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
+
Restart=always
+
User=%i
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
{{Note|1= Enable the unit for your user
+
systemctl enable emacs@<username>
+
systemctl start emacs@<username>}}
+
{{Note|1=Source: [http://www.emacswiki.org/emacs/EmacsAsDaemon#toc8 EmacsWiki].}}
+
 
+
== Monkey http server deamon ==
+
{{hc|/etc/systemd/system/monkey.service|<nowiki>
+
[Unit]
+
Description=Monkey http server deamon
+
After=network.target
+
 
+
[Service]
+
Type=forking
+
ExecStart=/YOUR/PATH/TO/monkey/bin/monkey -D
+
ExecStop=/bin/kill $MAINPID
+
ExecReload=/bin/kill $MAINPID ; /YOUR/PATH/TO/monkey/bin/monkey -D
+
PIDFile=/YOUR/PATH/TO/monkey/monkey.pid.80
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
{{Note|1= Replace /YOUR/PATH/TO entries with the path to monkey on your system}}
+
{{Note|1= PIDFile= entry should point to pidfile location specified in your monkey config file. The configured port number should be appended to the filename}}
+
{{Note|1=Gist available at: [git://gist.github.com/4238052.git github].}}
+
 
+
== See also ==
+
 
+
* [[systemd]]
+
* [http://en.gentoo-wiki.com/wiki/Systemd systemd at gentoo wiki]
+

Latest revision as of 14:34, 15 May 2015

Redirect to: