Systemd is a suite of basic building blocks for a Linux system that provides a system and service manager that runs as PID 1 and starts the rest of the system. It works as a replacement for sysvinit.
$ ps 1
$ stat /sbin/init
$ readlink /sbin/init
Linux is for everybody. Lets enjoy it.
Systemd is a suite of basic building blocks for a Linux system that provides a system and service manager that runs as PID 1 and starts the rest of the system. It works as a replacement for sysvinit.
$ ps 1
$ stat /sbin/init
$ readlink /sbin/init
Systemd is using journalctl as the log keeper for its services. The log location is at /var/log/journal.
$ sudo journalctl --disk-usage
$ sudo journalctl
$ sudo journalctl --flush
$ sudo journalctl --vacuum-size=1G
$ sudo journalctl --vacuum-time=1month
$ sudo journalctl --rotate
Podman is an excellent alternative to docker, but it would not survive host reboot since it does not have any daemon running. Is all hope lost? Nope, podman has one trick up its sleeve that can save the day.
$ podman generate systemd --new --name mycontainer -f
$ sudo mv container-mycontainer.service /etc/systemd/system/mycontainer.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now mycontainer.service
$ sudo systemctl status mycontainer.service
[Unit]Description="Hello app"[Service]ExecStart=/usr/local/bin/hello.sh
[Unit]Description="Run hello.service 5min after boot, every 24 hours relative to activation time, and everyday at 10:00 am"[Timer]OnBootSec=5minOnUnitActiveSec=24hOnCalendar=Mon..Fri *-*-* 10:00:*Unit=helloworld.service[Install]WantedBy=multi-user.target
Day of Week = Sun to SatDate = in yyyy-mm-dd formatTime = in hour:minute:seconds format
OnCalendar=Mon,Fri *-*-* 15:00:00
OnCalendar=2023-02-20 16:00:00
# man 7 systemd.time
# systemd-analyze verify /etc/systemd/system/hello.*
# systemctl start hello.timer
# systemctl enable hello.timer
# systemctl status hello.timer
# systemctl list-timers
# systemctl list-timers --all
# systemctl stop hello.timer
The old /etc/resolve is now being managed by systemd-resolve service, which is part of systemd. In order to add new nameserver, please follow below steps
1. Create a directory named /etc/systemd/resolved.conf.d/
# mkdir /etc/systemd/resolved.conf.d
2. Add a new configuration file for your new dns server. Let's say we want to add google's dns ip address, which are 8.8.8.8 and 8.8.4.4
# cat >> /etc/systemd/resolved.conf.d/mynameserver.conf <<EOF
[Resolve]
DNS=8.8.8.8 8.8.4.4
EOF
3. Restart the service
# systemctl restart systemd-resolved
4. Verify that your dns is now being used by the system
# systemd-resolve --status
Global
LLMNR setting: no
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 8.8.8.8
8.8.4.4
...
For more information about what option can be included in the configuration file, please refer to resolved.conf man page.
I got this error in one of our server, when trying to restart nginx
# systemctl status nginx
Failed to get properties: Access denied
Does not make sense, I am a root user. After some searching, a few suggestions came.
The first suggestion was to restart systemctl daemon:
# systemctl daemon-reexec
That did not work for me. Another solution is to disable selinux temporarily, but this also did not work for me:
# setenforce 0
The last thing that I tried (that actually worked) was to sending sigterm to systemd, and it will restart by itself:
# kill -TERM 1
If you guys happened to encounter this sort of error, you can try all the above. Some might suit you better than the other.
To set a bitnami wordpress application to start on boot, you just need to make sure that systemctl can use the ctlscript. To do that:
1. Locate the installation directory of your bitnami wordpress. If you are following the default setting, the location should be in /opt
2. Locate the ctlscript.sh file, which is the script to start, stop and restart bitnami-application.
$ sudo find / -iname "ctlscript.sh" -type f
/opt/bitnami-wordpress-5.6-0/ctlscript.sh
3. Copy the script to /etc/init.d, and rename it to bitnami-wordpress
$ sudo cp /opt/bitnami-wordpress-5.6-0/ctlscript.sh /etc/init.t/bitnami-wordpress
4. Edit the script, and add "INIT INFO" settings below #!/bin/sh to ensure systemd can understand the script
#!/bin/sh
### BEGIN INIT INFO
# Provides: bitnami-wordpress
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable services provided by daemon.
### END INIT INFO
To suspend a linux machine using command (useful if you want to suspend a machine that is connected via ssh), the command is pretty simple
$ sudo systemctl suspend
That's all.