Difference between revisions of "Systemd/Services"

From ArchWiki
Jump to: navigation, search
m (/home/%i > %h)
(redirect empty page marked for deletion, see also talk page)
 
(74 intermediate revisions by 22 users not shown)
Line 1: Line 1:
{{Lowercase title}}
+
#REDIRECT [[Systemd]]
[[Category:Daemons and system services]]
+
[[Category:Boot process]]
+
{{Article summary start}}
+
{{Article summary text|Examples of [[systemd]] service files that are missing in the appropriate package from [[official repositories]] or [[AUR]].}}
+
{{Article summary heading|Related}}
+
{{Article summary wiki|systemd}}
+
{{Article summary wiki|systemd/User}}
+
{{Article summary wiki|systemd FAQ}}
+
{{Article summary wiki|Daemons List}}
+
{{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.
+
 
+
== darkhttpd ==
+
 
+
{{hc|/etc/systemd/system/darkhttpd.service|<nowiki>
+
[Unit]
+
Description=Darkhttpd Webserver
+
 
+
[Service]
+
EnvironmentFile=/etc/conf.d/darkhttpd
+
ExecStart=/usr/sbin/darkhttpd $DARKHTTPD_ROOT --daemon $DARKHTTPD_OPTS
+
Type=forking
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/darkhttpd.socket|<nowiki>
+
[Unit]
+
Conflicts=darkhttpd.service
+
 
+
[Socket]
+
ListenStream=80
+
Accept=no
+
 
+
[Install]
+
WantedBy=sockets.target
+
</nowiki>}}
+
 
+
{{hc|/etc/conf.d/darkhttpd|<nowiki>
+
DARKHTTPD_ROOT="/srv/http"
+
DARKHTTPD_OPTS="--uid nobody --gid nobody --chroot"
+
</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
+
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>}}
+
 
+
== screen ==
+
 
+
Autostarts screen for the specified user (e.g. {{ic|systemctl enable screen@florian}}).
+
 
+
{{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>}}
+
 
+
== Set network interface in promiscuous mode ==
+
 
+
{{hc|/etc/systemd/system/promiscuous@.service|<nowiki>
+
[Unit]
+
Description=Set %i interface in promiscuous mode
+
After=network.target
+
 
+
[Service]
+
Type=oneshot
+
ExecStart=/usr/bin/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|eth0}} run:
+
 
+
# systemctl enable promiscuous@eth0.service
+
 
+
== tmux ==
+
 
+
Starts [[tmux]] for specified user (eg. {{ic|tmux@main-user.service}})
+
 
+
{{hc|/etc/systemd/system/tmux@.service|<nowiki>
+
[Unit]
+
Description=Start tmux in detached session
+
 
+
[Service]
+
Type=oneshot
+
RemainAfterExit=yes
+
KillMode=none
+
User=%I
+
ExecStart=/usr/bin/tmux new-session -s %u -d
+
ExecStop=/usr/bin/tmux kill-session -t %u
+
 
+
[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>}}
+
 
+
== MPD socket activation ==
+
 
+
If the following {{ic|mpd.socket}} file is enabled while {{ic|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 {{ic|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 {{ic|1="ListenStream="}} lines in the {{ic|[Socket]}} section of {{ic|mpd.socket}} ''AND'' modify the appropriate lines {{ic|/etc/mpd.conf}} (see {{ic|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 {{ic|1="ListenStream="}} in the {{ic|[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 {{ic|1=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 {{ic|1=User=}} and {{ic|1=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>}}
+
 
+
== 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 --chdir %h
+
ExecStop=/usr/bin/emacsclient --eval "(progn (setq kill-emacs-hook 'nil) (kill-emacs))"
+
Restart=always
+
User=%i
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
Then, to enable the unit for your user:
+
 
+
# systemctl enable emacs@''username''
+
# systemctl start emacs@''username''
+
 
+
Source: [http://www.emacswiki.org/emacs/EmacsAsDaemon#toc8 EmacsWiki].
+
 
+
== VirtualBox virtual machines ==
+
 
+
{{hc|/etc/systemd/system/vboxvmservice@.service|<nowiki>
+
[Unit]
+
Description=VBox Virtual Machine %i Service
+
Requires=systemd-modules-load.service
+
After=systemd-modules-load.service
+
 
+
[Service]
+
User=''user''
+
Group=vboxusers
+
ExecStart=/usr/bin/VBoxHeadless -s %i
+
ExecStop=/usr/bin/VBoxManage controlvm %i savestate
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
{{Note|
+
* Each virtual machine has its own service. Replace ''user'' with a user that is a member of the ''vboxusers'' group:
+
# systemctl enable vboxvmservice@''vm_name''
+
# systemctl start vboxvmservice@''vm_name''
+
* Make sure that the ''user'' field is filled in with the same user you're creating/importing virtual machines, else the user won't see them.
+
* As of VirtualBox 4.2 there is another way to get virtual machines going: http://lifeofageekadmin.com/how-to-set-your-virtualbox-vm-to-automatically-startup/. Please edit the [[VirtualBox]] page if you figure it out.
+
}}
+
 
+
== redmine ==
+
 
+
{{hc|/etc/systemd/system/redmine.service|<nowiki>
+
[Unit]
+
Description=Redmine server
+
After=syslog.target
+
After=network.target
+
 
+
[Service]
+
Type=simple
+
User=redmine2
+
Group=redmine2
+
Environment=GEM_HOME=/home/redmine2/.gem/
+
ExecStart=/usr/bin/ruby /usr/share/webapps/redmine/script/rails server webrick -e production
+
 
+
# Give a reasonable amount of time for the server to start up/shut down
+
TimeoutSec=300
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== Turn off the automatic screensaver ==
+
 
+
{{Stub|1=Very hackish solution, you'd better use something like [https://bbs.archlinux.org/viewtopic.php?id=130447 this] (needs to be modified to work with XBMC).}}
+
 
+
Arch Linux has a 10 minute screensaver set as standard. XBMC for CuBox does not disable this when watching movies, and this is a rather hackish workaround. Tested on the [http://archlinuxarm.org/platforms/armv7/cubox CuBox].
+
 
+
{{hc|/etc/systemd/system/screensaveroff.service|<nowiki>
+
[Unit]
+
Description=Disables the screensaver in X
+
After=graphical.target
+
 
+
[Service]
+
Type=oneshot
+
RemainAfterExit=yes
+
ExecStart=/usr/bin/xset s off -d :0
+
 
+
[Install]
+
WantedBy=graphical.target
+
</nowiki>}}
+
 
+
== slock ==
+
 
+
Locks the system with the help of {{Pkg|slock}}. Very handy when closing the laptop lid for example.
+
 
+
{{hc|/etc/systemd/system/screenlock.service|<nowiki>
+
[Unit]
+
Description=Lock X session using slock
+
Before=sleep.target
+
+
[Service]
+
User=<username>
+
Environment=DISPLAY=:0
+
ExecStart=/usr/bin/slock
+
+
[Install]
+
WantedBy=sleep.target
+
</nowiki>}}
+
 
+
== VDE2 interface ==
+
 
+
Create and activate an vde2 tap interface for use in the kvm user group.
+
 
+
{{hc|/etc/systemd/system/vde2@.service|<nowiki>
+
[Unit]
+
Description=Network Connectivity for %i
+
Wants=network.target
+
Before=network.target
+
 
+
[Service]
+
Type=oneshot
+
RemainAfterExit=yes
+
ExecStart=/usr/bin/vde_switch -tap %i -daemon -mod 660 -group kvm
+
ExecStart=/sbin/ip link set dev %i up
+
ExecStop=/sbin/ip addr flush dev %i
+
ExecStop=/sbin/ip link set dev %i down
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== BitTorrent Sync ==
+
 
+
Run BitTorrent Sync as user ''username'':
+
 
+
{{bc|<nowiki>
+
# systemctl start btsync@''username''
+
</nowiki>}}
+
 
+
{{hc|/etc/systemd/system/btsync@.service|<nowiki>
+
[Unit]
+
Description=BitTorrent Sync application
+
 
+
[Service]
+
Type=forking
+
User=%i
+
ExecStart=/usr/bin/btsync --config %h/.config/btsync/btsync.config
+
PIDFile=%h/.config/btsync/btsync.pid
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
This assumes existence of the following files:
+
 
+
* {{ic|/usr/bin/btsync}} - the {{ic|btsync}} executable or a symlink pointing to it.
+
* {{ic|/home/username/.config/btsync/btsync.config}} - the user's config file. Consult the [http://labs.bittorrent.com/experiments/sync/get-started.html#config-file official instructions] for creating one.
+
* {{ic|/home/username/.config/btsync/btsync.pid}} - BitTorrent Sync creates {{ic|$SYNC_HOME/sync.pid}} automatically, where {{ic|$SYNC_HOME}} is specified by {{ic|"storage_path"}} in the config file. Either point {{ic|PIDFile}} to it, or symlink this file to it.
+
 
+
== Crashplan PROe server ==
+
 
+
{{hc|/etc/systemd/system/proserver.service|<nowiki>
+
[Unit]
+
Description=CrashPlanPROe Backup Server
+
After=network.target
+
 
+
[Service]
+
 
+
Type=forking
+
 
+
ExecStart=/opt/proserver/bin/proserver start
+
ExecStop=/opt/proserver/bin/proserver stop
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
== RXVT-Unicode daemon ==
+
 
+
{{hc|/etc/systemd/system/urxvtd@.service|<nowiki>
+
 
+
[Unit]
+
Description=RXVT-Unicode Daemon
+
 
+
[Service]
+
Type=oneshot
+
RemainAfterExit=yes
+
User=%i
+
ExecStart=/usr/bin/urxvtd -f -o
+
 
+
[Install]
+
WantedBy=multi-user.target
+
</nowiki>}}
+
 
+
Pass the username when starting the service:
+
 
+
# systemctl enable urxvtd@''username''.service
+
 
+
== See also ==
+
 
+
* [[Pacman_Tips#Backing_up_Local_database_with_Systemd|Backing up local pacman database with systemd]]
+
* [http://wiki.gentoo.org/wiki/Systemd systemd at gentoo wiki]
+

Latest revision as of 14:34, 15 May 2015

Redirect to: