Difference between revisions of "Systemd/Services"

From ArchWiki
Jump to: navigation, search
m (it is one parameter, make sure it is clear)
m (/home/%i > %h)
Line 400: Line 400:
 
Type=forking
 
Type=forking
 
User=%i
 
User=%i
ExecStart=/usr/bin/btsync --config /home/%i/.config/btsync/btsync.config
+
ExecStart=/usr/bin/btsync --config %h/.config/btsync/btsync.config
PIDFile=/home/%i/.config/btsync/btsync.pid
+
PIDFile=%h/.config/btsync/btsync.pid
  
 
[Install]
 
[Install]
Line 454: Line 454:
 
== See also ==
 
== See also ==
  
* [[Pacman_Tips#Backing_up_Local_database_with_Systemd|Backing up Local Pacman database with Systemd]]
+
* [[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]
 
* [http://wiki.gentoo.org/wiki/Systemd systemd at gentoo wiki]

Revision as of 21:12, 29 August 2013

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template: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

/etc/systemd/system/darkhttpd.service
[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
/etc/systemd/system/darkhttpd.socket
[Unit]
Conflicts=darkhttpd.service

[Socket]
ListenStream=80
Accept=no

[Install]
WantedBy=sockets.target
/etc/conf.d/darkhttpd
DARKHTTPD_ROOT="/srv/http"
DARKHTTPD_OPTS="--uid nobody --gid nobody --chroot"

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
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

screen

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

/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

Set network interface in promiscuous mode

/etc/systemd/system/promiscuous@.service
[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

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

# systemctl enable promiscuous@eth0.service

tmux

Starts tmux for specified user (eg. tmux@main-user.service)

/etc/systemd/system/tmux@.service
[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

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

MPD socket activation

If the following mpd.socket file is enabled while mpd.service (provided by 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.

/usr/lib/systemd/system/mpd.socket
[Unit]
Description=Music Player Daemon Sockets

[Socket]
ListenStream=/var/run/mpd/socket
ListenStream=6600

[Install]
WantedBy=sockets.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= and 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

Gitlab

/etc/systemd/system/gitlab.service
[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
/etc/systemd/system/gitlab-worker.service
[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

Cisco AnyConnect VPN

/etc/systemd/system/ciscovpn.service
[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

Emacs daemon

/etc/systemd/system/emacs@.service
[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

Then, to enable the unit for your user:

# systemctl enable emacs@username
# systemctl start emacs@username

Source: EmacsWiki.

VirtualBox virtual machines

/etc/systemd/system/vboxvmservice@.service
[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
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

redmine

/etc/systemd/system/redmine.service
[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

Turn off the automatic screensaver

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: Very hackish solution, you'd better use something like this (needs to be modified to work with XBMC). (Discuss in Talk:Systemd/Services#)

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 CuBox.

/etc/systemd/system/screensaveroff.service
[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

slock

Locks the system with the help of slock. Very handy when closing the laptop lid for example.

/etc/systemd/system/screenlock.service
[Unit]
Description=Lock X session using slock
Before=sleep.target
 
[Service]
User=<username>
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock
 
[Install]
WantedBy=sleep.target

VDE2 interface

Create and activate an vde2 tap interface for use in the kvm user group.

/etc/systemd/system/vde2@.service
[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

BitTorrent Sync

Run BitTorrent Sync as user username:

# systemctl start btsync@''username''
/etc/systemd/system/btsync@.service
[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

This assumes existence of the following files:

  • /usr/bin/btsync - the btsync executable or a symlink pointing to it.
  • /home/username/.config/btsync/btsync.config - the user's config file. Consult the official instructions for creating one.
  • /home/username/.config/btsync/btsync.pid - BitTorrent Sync creates $SYNC_HOME/sync.pid automatically, where $SYNC_HOME is specified by "storage_path" in the config file. Either point PIDFile to it, or symlink this file to it.

Crashplan PROe server

/etc/systemd/system/proserver.service
[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

RXVT-Unicode daemon

/etc/systemd/system/urxvtd@.service

[Unit]
Description=RXVT-Unicode Daemon

[Service]
Type=oneshot
RemainAfterExit=yes
User=%i
ExecStart=/usr/bin/urxvtd -f -o

[Install]
WantedBy=multi-user.target

Pass the username when starting the service:

# systemctl enable urxvtd@username.service

See also