User Tools

Site Tools


Action disabled: revisions
linux:systemd

How to systemd

Set systemd log level to error. I don't like my log flooded by nonsense.

/etc/systemd/system.conf

LogLevel=crit

(emerg, alert, crit, err, warning, notice, info, debug)

Limit systemd journal by editing /etc/systemd/journald.conf

SystemMaxUse=10M

Commands

# systemctl <enable|disable|start|stop|restart|reload|status> service
# systemctl reset-failed service

nginx systemd sample script

Save this file as /lib/systemd/system/nginx.service

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
LimitNOFILE=60000

[Install]
WantedBy=multi-user.target

RC-local Service

touch /etc/systemd/system/rc-local.service
systemctl enable rc-local

[Unit]
 Description=/etc/rc.local Compatibility
 ConditionPathExists=/etc/rc.local

[Service]
 Type=forking
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
 RemainAfterExit=yes

[Install]
 WantedBy=multi-user.target

Check service security

systemd-analyze security nginx.service
linux/systemd.txt · Last modified: 2022/02/14 13:14 by Jan Forman