Ravindra Bagale · AWSसर्व coursesया course चे lessonsशोधाEnglish

AWS · मराठी आवृत्ती

4.6 Services: service, systemctl आणि journalctl

रवींद्र बागले यांच्या course वर आधारित · सहज मराठीत explanation

या page मध्ये

Nginx आत्ता सुरू आहे, पण reboot नंतर नाही? Start आणि enable या दोन वेगळ्या गोष्टी आहेत. Modern Linux मध्ये systemd background services — daemons — हाताळतो. त्याचं native tool systemctl. काही distros मध्ये जुना service wrapper सामान्य actions systemctl कडे पाठवतो.

रोजचे controls

CommandकामNative equivalent
sudo service nginx startआत्ता सुरूsystemctl start nginx
sudo service nginx stopआत्ता बंदsystemctl stop nginx
sudo service nginx restartबंद करून पुन्हा सुरूsystemctl restart nginx
sudo service nginx reloadSupported असेल तर config पुन्हा वाचाsystemctl reload nginx
sudo service nginx statusस्थिती आणि logs; q exitsystemctl status nginx
service --status-allWrapper services list; distro नुसार—

systemctl चे इतर उपयोग

Commandकाम
sudo systemctl enable nginxBoot वेळी सुरू व्हावं
sudo systemctl disable nginxBoot वेळी auto-start नको
systemctl is-active nginx / systemctl is-enabled nginxस्थिती पटकन तपासा
systemctl list-units --type=service --state=runningचालू services
sudo systemctl daemon-reloadUnit file बदलल्यावर systemd config reload

Start म्हणजे आत्ता; enable म्हणजे पुढच्या boot वेळी. फक्त enable केल्याने आत्ता सुरू होईलच असं नाही. दोन्ही एकत्र हवे असल्यास systemctl enable --now वापरता येतो.

Minimal image मध्ये service wrapper नसेल तर थेट systemctl वापरू शकता. Source course मध्ये AL2023 साठी sudo yum install -y initscripts, CentOS Stream 9 साठी sudo yum install -y initscripts-service हे wrapper package examples आहेत; उपलब्ध package repository वर तपासा.

Logs: journalctl

journalctl -u nginx                 # all logs of the nginx service
journalctl -u nginx -f              # follow live (Ctrl+C to stop)
journalctl -u nginx --since "1 hour ago"
journalctl -p err -b                # only errors since last boot
journalctl -u sshd -n 30 --no-pager # last 30 lines (service is 'ssh' on Ubuntu)
sudo journalctl --disk-usage

-u ने service, -f live, --since वेळ, -p err errors, -b current boot, -n 30 शेवटच्या lines. Ubuntu वर SSH unit अनेकदा ssh, इतरत्र sshd.

AL2023 मध्ये rsyslog default नसल्याने /var/log/messages किंवा /var/log/secure नसू शकतात. journalctl वापरा; गरज असल्यास logging setup ठरवून rsyslog install करा.

Lab

Lab instance वर Nginx install करा. sudo service nginx start, sudo systemctl enable nginx, systemctl is-enabled nginx. Reboot योग्य आहे याची खात्री करून sudo reboot; पुन्हा login करून status active आहे का पाहा. शेवटी journalctl -u nginx -n 20 --no-pager.