# 4.6 Services: service, systemctl आणि journalctl

Source: https://ravindrabagale.com/mr/aws/ch04-linux-advanced-commands/4-6-services-service-systemctl-and-journalctl.html
Language: mr (Marathi with English technical terms)

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 reload | Supported असेल तर config पुन्हा वाचा | systemctl reload nginx

 | sudo service nginx status | स्थिती आणि logs; q exit | systemctl status nginx

 | service --status-all | Wrapper services list; distro नुसार | —

systemctl चे इतर उपयोग

 | Command | काम

 | sudo systemctl enable nginx | Boot वेळी सुरू व्हावं

 | sudo systemctl disable nginx | Boot वेळी auto-start नको

 | systemctl is-active nginx / systemctl is-enabled nginx | स्थिती पटकन तपासा

 | systemctl list-units --type=service --state=running | चालू services

 | sudo systemctl daemon-reload | Unit 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.

रवींद्र बागले यांची tip

Config बदलल्यावर आधी test, मग reload: sudo nginx -t && sudo service nginx reload. Test fail झाला तर && मुळे reload होत नाही.
