Systemd/Services

From ArchWiki
Revision as of 21:09, 7 April 2012 by Unikum (Talk | contribs) (Created page with "On this page will be useful to publish systemd service files that are missing in the systemd-arch-units package. This can be files from other distributions, or that you create...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

On this page will be useful to publish systemd service files that are missing in the systemd-arch-units package. This can be files from other distributions, or that you created yourself.

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
ExecStart=/usr/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID 
ExecStop=kill $MAINPID

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

mysqld

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

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

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

Static network

/etc/conf.d/network
address=
netmask=
broadcast=
gateway=
/etc/systemd/system/etwork@.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 %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

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

If you have NFS mounts listed in /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 on rpc.statd. To do this, create a file under /etc/systemd/system named <mount-unit-name>.mount with contents as follows.

[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

In the above

  • mount-unit-name is the full path to the mountpoint in an escaped format. For example, a mount unit for /usr/local must be named usr-local.mount.
  • mountpoint is the local mountpoint
  • server:share specify the remote filesystem in the same manner as for /etc/fstab

See systemd.unit(5) and 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 /etc/fstab with the option comment=systemd.automount. Make sure that if you also include 'defaults' as a mount option, that you override the implicit 'auto' with 'noauto'. This will cause the device to be mounted on first access, similar to Autofs.

distccd

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

[Service]
ExecStart=/usr/bin/distccd --user distcc --daemon --no-detach --port 3632 --log-level info --allow 192.168.1.0/24 --listen 192.168.1.111 -N 15 

[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
ExecStart=/usr/sbin/verynice -d /var/run/verynice.pid
PIDFile=/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
# This use of EnvironmentFile requires $RESPONSIVENESS, 
# $REPEAT_TYPE and $APPEND to be added to $params in the conf.d/gpm file.
ExecStart=/usr/sbin/gpm -D -m $MOUSEDEV -t $MOUSE $params
Restart=always

[Install]
WantedBy=multi-user.target

cpufreq

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

[Service]
EnvironmentFile=/etc/conf.d/cpufreq
ExecStart=/usr/bin/cpufreq-set -r -g $governor

[Install]
WantedBy=multi-user.target

It set governor from /etc/conf.d/cpufreq for all cores.

See also

Systemd