Difference between revisions of "Systemd/Services"

From ArchWiki
Jump to: navigation, search
m (Remote filesystem mounts)
m (Remote filesystem mounts)
(2 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
== xinit ==
 
== xinit ==
  
If you are only looking for a simple way to start X directly without a display manager, you can create a service file similar to this:  
+
''See: [[Systemd#Using_service_file]]''
{{hc|/etc/systemd/system/xinit@.service|<nowiki>
 
[Unit]
 
Description=xinit for %I
 
 
 
[Service]
 
User=%I
 
ExecStart=/bin/bash --login -c xinit
 
Restart=always
 
RestartSec=3
 
 
 
[Install]
 
WantedBy=graphical.target
 
</nowiki>}}
 
 
 
Start service:
 
# systemctl start xinit@user.service
 
 
 
Add to start at boot:
 
# ln -sf /etc/systemd/system/xinit@.service /etc/systemd/system/graphical.target.wants/xinit@user.service
 
  
 
== rc.local ==
 
== rc.local ==
Line 145: Line 126:
 
== Static network ==
 
== Static network ==
  
{{hc|/etc/conf.d/network|<nowiki>
+
''See [[Systemd#Static_network]]''
address=
 
netmask=
 
broadcast=
 
gateway=
 
</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 %I up
 
ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev %I
 
ExecStart=/sbin/ip route add default via ${gateway}
 
ExecStop=/sbin/ip addr flush dev %I
 
ExecStop=/sbin/ip link set dev %I down
 
 
 
[Install]
 
Alias=multi-user.target.wants/network@%I.service
 
</nowiki>}}
 
 
 
Start service:
 
# systemctl start network@eth0.service
 
 
 
Add to start at boot:
 
# ln -sf /etc/systemd/system/network@.service /etc/systemd/system//multi-user.target.wants/network@eth0.service
 
 
 
Replace eth0 with other device name if needed.
 
  
 
== Remote filesystem mounts ==
 
== Remote filesystem mounts ==
  
If you have NFS mounts listed in {{ic|/etc/fstab}} then systemd will attempt to mount them but will typically do so too early (before networking has been configured). To get the timing correct we need to tell systemd explicitly that the mount depends on networking and {{ic|rpc.statd}}. To do this, create a file under {{ic|/etc/systemd/system/}} named {{ic|<mount-unit-name>.mount}} with contents as follows.
+
''See: [[Systemd#Remote_filesystem_mounts]]''
 
 
[Unit]
 
Description=<mountpoint>
 
Wants=network.target rpc-statd.service
 
After=network.target rpc-statd.service
 
 
[Mount]
 
What=<server>:<share>
 
Where=<mountpoint>
 
Type=nfs
 
StandardOutput=syslog
 
StandardError=syslog
 
 
[Install]
 
WantedBy=remote-fs.target
 
 
 
In the above
 
*{{ic|mount-unit-name}} is the full path to the mountpoint in an escaped format. For example, a mount unit for {{ic|/usr/local/}} must be named {{ic|usr-local.mount}}.
 
*{{ic|mountpoint}} is the local mountpoint
 
*s{{ic|erver:share}} specifies the remote filesystem in the same manner as for {{ic|/etc/fstab}}
 
 
 
See {{ic|systemd.unit(5)}} and {{ic|systemd.mount(5)}} for further details.
 
 
 
A similar approach will probably be required for other remote filesystem types such as nfs4 and cifs.
 
 
 
Alternatively, you can mark these entries in {{ic|/etc/fstab}} with the option {{ic|1=comment=systemd.automount}}. Make sure that if you also include {{ic|defaults}} as a mount option, that you override the implicit {{ic|auto}} with {{ic|noauto}}. This will cause the device to be mounted on first access, similar to [[Autofs]].
 
  
 
== distccd ==
 
== distccd ==

Revision as of 18:41, 15 April 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

This page will be useful to publish systemd service files that are missing in the systemd-arch-units package. These files can be copied from other distributions or created by yourself.

xinit

See: Systemd#Using_service_file

rc.local

/etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility

[Service]
Type=oneshot
ExecStart=/etc/rc.local
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

apache2

/etc/systemd/system/httpd.service
[Unit]
Description=Apache Webserver
After=network.target

[Service]
Type=forking
EnvironmentFile=/etc/conf.d/apache
ExecStart=/usr/sbin/httpd -k start $OPTIONS
ExecStop=/usr/sbin/httpd -k graceful-stop $OPTIONS
ExecReload=/usr/sbin/httpd -k graceful $OPTIONS
Restart=always

[Install]
WantedBy=multi-user.target
/etc/tmpfiles.d/httpd.conf
D /var/run/httpd 0755 http http -

postfix

/etc/systemd/system/postfix.service
[Unit]
Description=Mail Daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/postfix start
ExecStop=/usr/sbin/postfix stop
ExecReload=/usr/sbin/postfix reload

[Install]
WantedBy=multi-user.target

memcached

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

[Service]
EnvironmentFile=/etc/conf.d/memcached
PIDFile=/var/run/memcached.pid
ExecStart=/usr/bin/memcached -d -P /var/run/memcached.pid -u $MEMCACHED_USER $MEMCACHED_ARGS
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

php-fpm

/etc/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/var/run/php-fpm/php-fpm.pid
ExecStartPre=/usr/sbin/php-fpm -t
ExecStart=/usr/sbin/php-fpm --pid /var/run/php-fpm/php-fpm.pid
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=kill $MAINPID

[Install]
WantedBy=multi-user.target
/etc/tmpfiles.d/php-fpm.conf
d /var/run/php-fpm 0755 root root -

mysqld

/etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
After=network.target

[Service]
Type=simple
PIDFile=/var/run/mysqld/mysqld.pid
ExecStart=/usr/bin/mysqld --user=mysql --pid-file=/var/run/mysqld/mysqld.pid
ExecStop=/bin/kill -15 $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target
/etc/tmpfiles.d/mysqld.conf
d /var/run/mysqld 0755 mysql mysql -

Static network

See Systemd#Static_network

Remote filesystem mounts

See: Systemd#Remote_filesystem_mounts

distccd

/etc/systemd/system/distccd.service
[Unit]
Description=distcc

[Service]
Type=forking
EnvironmentFile=/etc/conf.d/distccd
ExecStart=/usr/bin/distccd --daemon $DISTCC_ARGS
ExecStop=/bin/kill -15 $MAINPID

[Install]
WantedBy=multi-user.target

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

gpm

/etc/systemd/system/gpm.service
[Unit]
Description=gpm
Requires=getty.target

[Service]
EnvironmentFile=/etc/conf.d/gpm
ExecStart=/usr/sbin/gpm $GPM_ARGS
Restart=always

[Install]
WantedBy=multi-user.target

cpufreq

/etc/systemd/system/cpufreq.service
[Unit]
Description=CPU frequency scaling daemon

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/cpufreq
ExecStart=/usr/bin/cpufreq-set -r -g $governor -d $min_freq -u $max_freq

[Install]
WantedBy=multi-user.target

This sets the governor of all cores to the one specified in /etc/conf.d/cpufreq.

If you use the 'freq' option, change the file to the following:

/etc/systemd/system/cpufreq.service
[Unit]
Description=CPU frequency scaling daemon

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/cpufreq
ExecStart=/usr/bin/cpufreq-set -r -f $freq

[Install]
WantedBy=multi-user.target

hddtemp

/etc/systemd/system/hddtemp.service
[Unit]
Description=Utility to monitor hard drive temperature

[Service]
EnvironmentFile=/etc/conf.d/hddtemp
ExecStart=/usr/sbin/hddtemp -F -d $PARAMS $DRIVES

[Install]
WantedBy=multi-user.target

See also

systemd