Ravindra BagaleCourses & study guides English

Linux systemd आणि systemctl: Services manage करा आणि Unit Files लिहा step by step

systemd हा Linux सुरू करणारा पहिला program (PID 1). तो प्रत्येक service सुरू करतो, चालू ठेवतो, crash झाली तर restart करतो आणि योग्य क्रमाने थांबवतो. systemctl हा त्याच्याशी बोलायचा remote control. या chapter मधे प्रत्येक systemctl command एक-एक करून शिकाल, मग स्वतःची unit file लिहाल म्हणजे तुमचं app खऱ्या service सारखं चालेल.

या chapter मध्ये तुम्ही काय शिकाल

  • status, is-active आणि is-enabled ने service तपासा
  • Services start, stop, restart आणि reload
  • Boot ला services enable, disable आणि mask
  • Units list आणि failed शोधा
  • .service unit file लिहा आणि daemon-reload
  • systemctl edit, cat, show, targets आणि systemd-analyze

1. रोजचं उदाहरण: society चा watchman

हे का लागतं?

पुण्याच्या housing society मधे watchman कडे register आहे. रोज सकाळी तो gate उघडतो, पाण्याचा pump चालू करतो, मग lift. Pump trip झाला तर परत चालू करतो. रात्री उलट्या क्रमाने बंद करतो. Secretary त्याला प्रत्येक machine साठी लिहिलेलं card देतो: कधी सुरू करायचं, थांबलं तर काय करायचं, आणि ते कशावर अवलंबून आहे.

हे काय आहे?

Watchman = systemd. प्रत्येक machine = service. लिहिलेलं card = unit file. चालू करायचा क्रम = dependencies (After=, Wants=). Trip नंतर परत चालू = Restart=on-failure. तुम्ही watchman शी बोलणं = systemctl.

कसं करायचं (step by step)

Boot ला service कशी सुरू होतेKernel systemd ला PID 1 म्हणून सुरू करतोsystemd /etc/systemd/system आणि /usr/lib/systemd/system मधून unit files वाचतोDefault target शोधतो (multi-user किंवा graphical)त्या target ला हव्या असलेल्या सगळ्या units dependency क्रमाने सुरूप्रत्येक service स्वतःच्या cgroup मधे; systemd लक्ष ठेवतोCrash झाली आणि Restart= सांगत असेल तर परत सुरू
/etc/systemd/system मधल्या files package च्या /usr/lib/systemd/system copies पेक्षा जिंकतात.

2. systemctl status: माझी service ठीक आहे का?

हे का लागतं?

Website बंद असली की पहिला प्रश्न: service चालू आहे का? status उत्तर देतो आणि शेवटच्या log lines दाखवतो.

हे काय आहे?

systemctl status NAME दाखवतो Loaded (unit file कुठे आणि enabled आहे का), Active (running, failed, inactive), main PID, memory, process tree आणि शेवटच्या 10 log lines. --no-pager less शिवाय print. -l पूर्ण lines. -n 30 म्हणजे 30 log lines.

Active stateअर्थ
active (running)आत्ता चालू
active (exited)One-shot job ठीक संपला
inactive (dead)थांबलेली
failedCrash किंवा error ने exit
activatingसुरू होतेय, अजून तयार नाही

कसं करायचं (step by step)

  1. nginx तपासा.
systemctl status nginx --no-pager

Output:

● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
     Active: active (running) since Sun 2026-10-25 09:10:02 IST; 3h ago
   Main PID: 1012 (nginx)
     Memory: 6.1M

याचा अर्थ: 3 तास चालू, boot ला enabled.

  1. Failed service.
systemctl status shop-api --no-pager -n 5

Output:

     Active: failed (Result: exit-code) since Sun 2026-10-25 12:01:44 IST
    Process: 4410 ExecStart=/opt/shop/bin/api (code=exited, status=1/FAILURE)
Oct 25 12:01:44 web1 api[4410]: Error: cannot connect to DB at 10.0.0.9:5432

याचा अर्थ: शेवटची line का ते सांगते.

  1. पूर्ण लांब lines.
systemctl status shop-api -l --no-pager

Output:

(lines are not cut with ...)

याचा अर्थ: Error लांब असेल तर -l.

3. is-active, is-enabled, is-failed: scripts साठी उत्तरं

हे का लागतं?

Scripts आणि health checks ना एक साधं हो किंवा नाही हवं, पानभर text नाही.

हे काय आहे?

systemctl is-active NAME active किंवा inactive print करतो आणि active असेल तरच exit 0. is-enabled enabled, disabled, masked किंवा static. is-failed failed असेल तर exit 0. --quiet (-q) ने काही print नाही, फक्त exit code.

कसं करायचं (step by step)

  1. चालू आहे का?
systemctl is-active nginx

Output:

active

याचा अर्थ: Exit code 0.

  1. Boot ला सुरू होते का?
systemctl is-enabled nginx

Output:

enabled

याचा अर्थ: disabled म्हणजे हाताने सुरू करायची.

  1. Script मधे.
systemctl is-active --quiet nginx || sudo systemctl restart nginx

Output:

(no output)

याचा अर्थ: बंद असेल तेव्हाच restart.

4. start, stop आणि restart

हे का लागतं?

Maintenance साठी service थांबवता, परत सुरू करता, किंवा code किंवा config बदलल्यावर restart.

हे काय आहे?

sudo systemctl start NAME आत्ता सुरू. stop SIGTERM पाठवतो, थांबतो (TimeoutStopSec, बहुतेक 90 s), मग SIGKILL. restart = stop मग start, म्हणून थोडा downtime. try-restart आधीच चालू असेल तरच restart. यांनी boot behaviour बदलत नाही. एकदम अनेक नावं देऊ शकता.

कसं करायचं (step by step)

  1. Maintenance साठी stop.
sudo systemctl stop shop-api && systemctl is-active shop-api

Output:

inactive

याचा अर्थ: Clients ना आता errors; plan करा.

  1. परत start.
sudo systemctl start shop-api && systemctl is-active shop-api

Output:

active

याचा अर्थ: परत चालू.

  1. Code deploy नंतर restart.
sudo systemctl restart shop-api

Output:

(no output)

याचा अर्थ: Output नाही म्हणजे success.

  1. एकदम दोन.
sudo systemctl restart php-fpm nginx

Output:

(no output)

याचा अर्थ: क्रम: डावीकडून उजवीकडे.

5. reload आणि reload-or-restart

हे का लागतं?

Restart ने live connections तुटतात. Reload ने service न थांबता नवी config वाचते.

हे काय आहे?

sudo systemctl reload NAME unit चा ExecReload चालवतो (बहुतेक SIGHUP). प्रत्येक service support करत नाही; मग 'Job type reload is not applicable' दिसतं. reload-or-restart शक्य असेल तर reload, नाहीतर restart. आधी नेहमी config test, उदा. nginx -t किंवा sshd -t.

कसं करायचं (step by step)

  1. Test, मग nginx reload.
sudo nginx -t && sudo systemctl reload nginx

Output:

nginx: configuration file /etc/nginx/nginx.conf test is successful

याचा अर्थ: एकही connection तुटत नाही.

  1. Reload नसलेली service.
sudo systemctl reload shop-api

Output:

Failed to reload shop-api.service: Job type reload is not applicable for unit shop-api.service.

याचा अर्थ: restart वापरा किंवा ExecReload= जोडा.

  1. Safe पर्याय.
sudo systemctl reload-or-restart shop-api

Output:

(no output)

याचा अर्थ: दोन्ही प्रकारांना चालतो.

6. enable, disable आणि --now

हे का लागतं?

Reboot नंतर फक्त enabled services परत येतात. कोणीतरी service start केली पण enable केली नाही म्हणून अनेक outages होतात.

हे काय आहे?

sudo systemctl enable NAME target च्या .wants folder मधे link बनवतो म्हणजे boot ला सुरू. disable तो काढतो. enable --now सुरू पण करतो; disable --now थांबवतो पण. static unit enable होत नाही; दुसरी unit तिला ओढते.

कसं करायचं (step by step)

  1. एकदम enable आणि start.
sudo systemctl enable --now nginx

Output:

Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

याचा अर्थ: Symlink हीच सगळी जादू.

  1. नको असलेली service stop आणि disable.
sudo systemctl disable --now cups

Output:

Removed "/etc/systemd/system/multi-user.target.wants/cups.service".

याचा अर्थ: कमी attack surface.

  1. बदलानंतर तपासा.
systemctl is-enabled nginx cups

Output:

enabled
disabled

याचा अर्थ: प्रत्येक unit ची एक line.

7. mask आणि unmask: service पूर्ण बंद

हे का लागतं?

disable नंतरही कोणी किंवा दुसरी unit हाताने service सुरू करू शकते. mask ने सुरू करणंच अशक्य, firewalld आणि iptables सारख्या conflicting services साठी उपयोगी.

हे काय आहे?

sudo systemctl mask NAME unit ला /dev/null शी link करतो. कोणताही start 'Unit is masked' ने fail. unmask link काढतो. mask सोबत --now ने थांबवतो पण.

कसं करायचं (step by step)

  1. iptables block.
sudo systemctl mask --now iptables

Output:

Created symlink /etc/systemd/system/iptables.service → /dev/null.

याचा अर्थ: आता firewalld शी भांडण नाही.

  1. Start करून बघा.
sudo systemctl start iptables

Output:

Failed to start iptables.service: Unit iptables.service is masked.

याचा अर्थ: नेमकं हेच हवं होतं.

  1. Undo.
sudo systemctl unmask iptables

Output:

Removed "/etc/systemd/system/iptables.service".

याचा अर्थ: परत normal.

8. list-units, list-unit-files आणि --failed

हे का लागतं?

Reboot किंवा alert नंतर काय चालू आणि काय failed ते पटकन बघायचं असतं.

हे काय आहे?

systemctl list-units --type=service loaded services आणि state. --state=running filter. --failed (किंवा systemctl --failed) फक्त failed units. list-unit-files प्रत्येक installed unit आणि enabled आहे का. reset-failed failed list साफ.

कसं करायचं (step by step)

  1. चालू services.
systemctl list-units --type=service --state=running --no-pager | head -4

Output:

  UNIT              LOAD   ACTIVE SUB     DESCRIPTION
  chronyd.service   loaded active running NTP client/server
  crond.service     loaded active running Command Scheduler
  nginx.service     loaded active running The nginx HTTP and reverse proxy server

याचा अर्थ: काय live आहे त्याची list.

  1. Failed units.
systemctl --failed --no-pager

Output:

  UNIT             LOAD   ACTIVE SUB    DESCRIPTION
● shop-api.service loaded failed failed Shop API

1 loaded units listed.

याचा अर्थ: प्रत्येक reboot नंतर हे तपासा.

  1. Boot ला enabled.
systemctl list-unit-files --type=service --state=enabled --no-pager | head -3

Output:

UNIT FILE          STATE   PRESET
atd.service        enabled enabled
chronyd.service    enabled enabled

याचा अर्थ: Boot ला काय सुरू होतं त्याचा audit.

9. एक .service unit file, line by line

हे का लागतं?

App nohup ने किंवा tmux मधे चालवलं तर crash ला restart नाही आणि boot ला start नाही. Unit file दोन्ही सोडवते.

हे काय आहे?

Unit file चे तीन भाग. [Unit]: Description, After= (क्रम) आणि Wants=/Requires= (dependency). [Service]: ExecStart (full path), User, WorkingDirectory, Environment किंवा EnvironmentFile, Restart=on-failure, RestartSec. [Install]: WantedBy=multi-user.target, enable वापरतो. स्वतःच्या files /etc/systemd/system/NAME.service मधे.

Keyकाय करतो
ExecStart=चालवायचा command, full path
User=या user म्हणून, root नाही
Restart=on-failureCrash नंतर परत सुरू
After=network-online.targetNetwork आल्यावर सुरू
EnvironmentFile=File मधून KEY=value lines
WantedBy=multi-user.targetEnabled असेल तर normal boot ला

कसं करायचं (step by step)

  1. File लिहा.
sudo tee /etc/systemd/system/shop-api.service <<'X'
[Unit]
Description=Shop API
After=network-online.target
Wants=network-online.target

[Service]
User=shop
WorkingDirectory=/opt/shop
EnvironmentFile=/etc/shop/api.env
ExecStart=/usr/bin/node /opt/shop/server.js
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
X

Output:

(the file text is echoed)

याचा अर्थ: 15 lines मधे खरी, safe service.

  1. चुका तपासा.
systemd-analyze verify /etc/systemd/system/shop-api.service

Output:

(no output)

याचा अर्थ: Output नाही म्हणजे errors नाहीत.

  1. Load, enable आणि start.
sudo systemctl daemon-reload && sudo systemctl enable --now shop-api

Output:

Created symlink /etc/systemd/system/multi-user.target.wants/shop-api.service → /etc/systemd/system/shop-api.service.

याचा अर्थ: आता crashes आणि reboots टिकते.

10. daemon-reload: file बदल systemd ला सांगा

हे का लागतं?

systemd unit files memory मधे ठेवतो. File edit करून reload केलं नाही तर जुनीच वापरतो.

हे काय आहे?

sudo systemctl daemon-reload सगळ्या unit files परत वाचतो. Services restart करत नाही; ते नंतर करा. विसरलात तर systemctl status 'unit file changed on disk' warning देतो.

कसं करायचं (step by step)

  1. मिळणारी warning.
systemctl status shop-api --no-pager | head -2

Output:

Warning: The unit file, source configuration file or drop-ins of shop-api.service changed on disk. Run 'systemctl daemon-reload' to reload units.

याचा अर्थ: systemd नेमकं काय करायचं ते सांगतो.

  1. Reload आणि restart.
sudo systemctl daemon-reload && sudo systemctl restart shop-api

Output:

(no output)

याचा अर्थ: नवे settings live.

11. systemctl cat, edit आणि drop-in overrides

हे का लागतं?

/usr/lib मधली package ची unit file edit केली तर पुढचा update बदल पुसतो. Overrides updates टिकतात.

हे काय आहे?

systemctl cat NAME unit आणि सगळे drop-ins दाखवतो. sudo systemctl edit NAME editor उघडतो आणि /etc/systemd/system/NAME.service.d/override.conf save करतो, मग reload करतो. फक्त बदलणाऱ्या lines, योग्य [Section] खाली. ExecStart बदलायचा असेल तर आधी रिकाम्या ExecStart= ने clear. edit --full पूर्ण file copy करतो. systemctl revert NAME overrides काढतो.

कसं करायचं (step by step)

  1. खरं काय वापरलं जातं.
systemctl cat nginx --no-pager | head -3

Output:

# /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server

याचा अर्थ: पहिली line file path.

  1. Open-file limit वाढवा.
sudo systemctl edit nginx
# add:
[Service]
LimitNOFILE=65535

Output:

(editor closes; systemd reloads)

याचा अर्थ: Drop-in म्हणून save.

  1. Confirm करा आणि लागू.
systemctl show nginx -p LimitNOFILE && sudo systemctl restart nginx

Output:

LimitNOFILE=65535

याचा अर्थ: show एक property print करतो.

  1. सगळे overrides undo.
sudo systemctl revert nginx

Output:

Removed "/etc/systemd/system/nginx.service.d/override.conf".

याचा अर्थ: परत package default.

12. systemctl show: नेमके properties

हे का लागतं?

status माणसांसाठी; show scripts आणि debugging साठी नेमकी values देतो, जसं restart count आणि main PID.

हे काय आहे?

systemctl show NAME प्रत्येक property KEY=value. -p काही निवडतो (comma list). --value फक्त value. उपयोगी: MainPID, ActiveState, NRestarts, ExecMainStatus, FragmentPath.

कसं करायचं (step by step)

  1. किती वेळा crash?
systemctl show shop-api -p NRestarts,ActiveState

Output:

NRestarts=4
ActiveState=active

याचा अर्थ: 4 restarts: logs बघा.

  1. फक्त PID.
systemctl show -p MainPID --value nginx

Output:

1012

याचा अर्थ: Scripts साठी छान.

13. Targets: systemd मधले runlevels

हे का लागतं?

Servers ना desktop नको. Targets कोणत्या प्रकारची system boot होईल ते ठरवतात, आणि बिघडलं की rescue mode मदत करतो.

हे काय आहे?

Target म्हणजे units चा group. multi-user.target = network सह normal server, GUI नाही. graphical.target = desktop सह. rescue.target = दुरुस्तीसाठी single user. get-default सध्याचा default; set-default बदलतो; isolate आत्ता switch.

कसं करायचं (step by step)

  1. सध्याचा default.
systemctl get-default

Output:

multi-user.target

याचा अर्थ: Servers साठी normal.

  1. आतापासून GUI शिवाय boot.
sudo systemctl set-default multi-user.target

Output:

Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target.

याचा अर्थ: Servers वर RAM वाचते.

  1. Service कशावर अवलंबून.
systemctl list-dependencies shop-api --no-pager | head -4

Output:

shop-api.service
● ├─system.slice
● ├─network-online.target
● └─sysinit.target

याचा अर्थ: क्रमाची साखळी.

14. systemd-analyze: boot slow का?

हे का लागतं?

Slow boots auto-scaling आणि recovery उशिरा करतात. कोणती unit जबाबदार ते systemd-analyze दाखवतो.

हे काय आहे?

systemd-analyze एकूण boot time. blame units start time ने. critical-chain slow मार्ग. verify FILE unit file errors तपासतो. calendar timer expressions test (पुढचा chapter).

कसं करायचं (step by step)

  1. एकूण वेळ.
systemd-analyze

Output:

Startup finished in 1.9s (kernel) + 14.2s (userspace) = 16.1s

याचा अर्थ: Userspace मधे 14 s: खोलात जा.

  1. कोण slow.
systemd-analyze blame --no-pager | head -3

Output:

9.8s NetworkManager-wait-online.service
2.1s cloud-init.service
1.0s dnf-makecache.service

याचा अर्थ: Network ची वाट सर्वात जास्त वेळ.

  1. Slow साखळी.
systemd-analyze critical-chain shop-api.service

Output:

shop-api.service +410ms
└─network-online.target @12.1s

याचा अर्थ: Network ची वाट बघितली.

15. अनेक industries मधली खरी उदाहरणं

हे का लागतं?

तेच Linux skill प्रत्येक प्रकारच्या company मध्ये लागतं. वेगवेगळ्या ठिकाणी पाहिलं की लक्षात राहतं.

हे काय आहे?

प्रत्येक row म्हणजे एक काल्पनिक team. कोण हे वापरतं आणि कसं ते दाखवते.

कसं करायचं (step by step)

Team आणि शहरते कसं वापरतातCommand
Sneha, food delivery app, PuneOrder API auto restart सह systemd servicesystemctl enable --now orders-api
Tom, bank, LondonVendor files न बदलता overrides ने limitssystemctl edit postgresql
Aisha, hospital IT, Dubaiप्रत्येक patch reboot नंतर failed unitssystemctl --failed
Kenji, game servers, OsakaZero downtime config reloadsystemctl reload haproxy
Maria, e-commerce, Mexico CityConflicting firewall service masksystemctl mask iptables
Ravi, college lab, NashikLab PCs वर slow boot unitssystemd-analyze blame

16. नेहमीच्या errors आणि त्यांचे fixes

हे का लागतं?

हे errors सगळ्यांना येतात. कारण माहीत असलं की तास वाचतात.

हे काय आहे?

आधी नेमका message वाचा. मग खालच्या row शी जुळवा.

कसं करायचं (step by step)

दिसणारा errorका होतंFix कसा करायचा
Failed to start shop-api.service: Unit shop-api.service not found.त्या नावाची unit file नाही, किंवा daemon-reload नाहीFile नाव तपासा आणि reload.
sudo systemctl daemon-reload
Warning: The unit file ... changed on disk. Run 'systemctl daemon-reload'Unit file edit केलीReload, मग restart.
sudo systemctl daemon-reload && sudo systemctl restart shop-api
Job for shop-api.service failed because the control process exited with error code.Program स्वतः start ला crashत्याचे logs वाचा.
journalctl -u shop-api -n 50 --no-pager
status=203/EXECExecStart path चुकीचा किंवा executable नाहीFull path आणि chmod +x.
ls -l /opt/shop/bin/api
status=217/USERUser= अस्तित्वात नाहीUser बनवा किंवा नाव fix.
id shop
status=200/CHDIRWorkingDirectory नाहीFolder बनवा किंवा path fix.
ls -ld /opt/shop
Start request repeated too quickly.खूप वेळा crash; StartLimitBurstCrash fix, मग reset-failed.
sudo systemctl reset-failed shop-api
Failed to start iptables.service: Unit iptables.service is masked.Unit masked आहेखरंच हवी असेल तर unmask.
sudo systemctl unmask iptables
Failed to reload ...: Job type reload is not applicableUnit मधे ExecReload नाहीrestart किंवा reload-or-restart.
sudo systemctl reload-or-restart shop-api
Service works by hand but not after rebootStart केली पण enable नाहीEnable करा.
sudo systemctl enable shop-api

17. Troubleshooting step by step

हे का लागतं?

Service बंद असेल तर state, मग logs, मग unit file, मग program स्वतः.

हे काय आहे?

वरून खाली जा. ज्या step ला problem दिसतो तिथे थांबा.

कसं करायचं (step by step)

  1. State बघा.
systemctl status shop-api --no-pager -l
  1. अलीकडचे logs.
journalctl -u shop-api -n 50 --no-pager
  1. खरी unit file.
systemctl cat shop-api
  1. File verify.
systemd-analyze verify /etc/systemd/system/shop-api.service
  1. ExecStart command हाताने त्या user म्हणून.
sudo -u shop /usr/bin/node /opt/shop/server.js
  1. Reload, reset आणि start.
sudo systemctl daemon-reload && sudo systemctl reset-failed shop-api && sudo systemctl start shop-api

18. Lab 1: Script ला खरी service बनवा

हे का लागतं?

छोटी web server script, systemd service म्हणून चालवा, crash नंतर auto restart बघा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. App बनवा.
sudo mkdir -p /opt/hello && echo 'hello from systemd' | sudo tee /opt/hello/index.html

Output:

hello from systemd
  1. Unit लिहा.
sudo tee /etc/systemd/system/hello.service <<'X'
[Unit]
Description=Hello web
After=network.target
[Service]
WorkingDirectory=/opt/hello
ExecStart=/usr/bin/python3 -m http.server 8088
Restart=on-failure
RestartSec=2
[Install]
WantedBy=multi-user.target
X

Output:

(file text)
  1. Load आणि start.
sudo systemctl daemon-reload && sudo systemctl enable --now hello && curl -s localhost:8088

Output:

hello from systemd
  1. Crash करा.
sudo kill -9 $(systemctl show -p MainPID --value hello); sleep 3; systemctl show -p NRestarts hello

Output:

NRestarts=1
  1. साफ.
sudo systemctl disable --now hello && sudo rm /etc/systemd/system/hello.service && sudo systemctl daemon-reload

Output:

Removed "/etc/systemd/system/multi-user.target.wants/hello.service".

19. Lab 2: Override, mask आणि boot analysis

हे का लागतं?

Override ने package service safely बदला, mask ने service block, आणि slow boot units शोधा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. Override जोडा.
sudo mkdir -p /etc/systemd/system/crond.service.d && printf '[Service]\nNice=5\n' | sudo tee /etc/systemd/system/crond.service.d/nice.conf && sudo systemctl daemon-reload

Output:

[Service]
Nice=5
  1. तपासा.
sudo systemctl restart crond && systemctl show -p Nice crond

Output:

Nice=5
  1. Revert.
sudo systemctl revert crond

Output:

Removed "/etc/systemd/system/crond.service.d/nice.conf".
  1. Mask आणि unmask.
sudo systemctl mask atd; sudo systemctl start atd; sudo systemctl unmask atd

Output:

Failed to start atd.service: Unit atd.service is masked.
  1. Boot report.
systemd-analyze blame --no-pager | head -3

Output:

9.8s NetworkManager-wait-online.service

Ravindra Bagale's Tip

Every time you change a unit file, say three words: daemon-reload, restart, status. And never edit files in /usr/lib/systemd/system; use systemctl edit so updates do not erase your change.

20. नेहमी विचारले जाणारे प्रश्न

प्र. start vs enable?

start आत्ता चालवतो; enable boot ला सुरू करतो. दोन्हीसाठी enable --now.

प्र. restart vs reload?

restart थांबवून सुरू (थोडा downtime); reload न थांबता config वाचतो, support असेल तर.

प्र. स्वतःच्या unit files कुठे?

/etc/systemd/system/NAME.service.

प्र. systemctl edit नंतर daemon-reload लागतो का?

नाही, edit स्वतः करतो. हाताने files edit केल्या तर हो.

प्र. disable vs mask?

disable boot start थांबवतो; mask प्रत्येक start block.

प्र. Service root म्हणून का चालते?

User= line नाही. User= आणि Group= जोडा.

प्र. service nginx restart अजून चालतं का?

हो, systemd systems वर systemctl च call करतं, पण systemctl शिका.

प्र. साधा user services चालवू शकतो का?

हो, ~/.config/systemd/user मधे systemctl --user ने user services.

21. मुलाखत प्रश्न आणि उत्तरं

Beginner level

प्र. systemd म्हणजे?

Init system, PID 1, services सुरू आणि manage करतो.

प्र. nginx चालू आहे का कसं?

systemctl status nginx किंवा systemctl is-active nginx.

प्र. Boot ला service कशी सुरू?

systemctl enable NAME.

प्र. Service चे logs कुठे?

journalctl -u NAME.

Mid level level

प्र. Minimal unit file मधे काय?

[Unit] Description, [Service] ExecStart, [Install] WantedBy.

प्र. daemon-reload का?

systemd unit files cache करतो; reload बदल वाचायला लावतो.

प्र. Vendor unit safely कशी बदलायची?

systemctl edit ने drop-in override.

प्र. After= vs Requires=?

After= फक्त क्रम; Requires= पक्की dependency.

Senior level

प्र. Service ला सतत 'Start request repeated too quickly'. Approach?

journalctl -u वाचा, crash कारण fix, RestartSec आणि StartLimitIntervalSec/Burst tune, मग reset-failed.

प्र. Child processes असलेली service systemd कशी थांबवतो?

KillMode प्रमाणे cgroup ला KillSignal, TimeoutStopSec थांबतो, मग SIGKILL.

प्र. Unit harden कशी?

User=, NoNewPrivileges=yes, ProtectSystem=strict, PrivateTmp=yes, ReadWritePaths=; systemd-analyze security ने तपासा.

प्र. Type=simple vs forking vs notify?

simple: ExecStart हाच main process; forking: fork करून parent exit; notify: app ready असल्याचं systemd ला सांगतो.

घरी करून बघा

  1. तुमच्या कोणत्याही छोट्या script साठी (किंवा python3 -m http.server) unit file लिहा. Enable करा, machine reboot करा, आणि ती परत आली हे सिद्ध करा.
  2. crond सारखी service घ्या. Nice=10 set करणारा override जोडा, systemctl show ने तपासा, मग revert.

सराव Tasks

या scenario बद्दल

Maple Leaf Books हा टोरांटो मधला पुस्तक विक्री व्यवसाय आहे. Emily Tremblay त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे CAD मध्ये मोजले जातात आणि AWS resources ca-central-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 16

सोपं Service status

का: Services BIZ चालू ठेवतात.

काय करायचं: Emily Tremblay Maple Leaf Books मधे nginx service ची state तपासतो.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Service start

का: Services BIZ चालू ठेवतात.

काय करायचं: nginx service आत्ता start.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Service stop

का: Services BIZ चालू ठेवतात.

काय करायचं: httpd service stop.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Restart

का: Services BIZ चालू ठेवतात.

काय करायचं: Config बदलानंतर sshd restart.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Boot ला start

का: Services BIZ चालू ठेवतात.

काय करायचं: प्रत्येक boot ला nginx start.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Boot मधून काढा

का: Services BIZ चालू ठेवतात.

काय करायचं: cups boot ला start होऊ नये.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Downtime शिवाय reload

का: Services BIZ चालू ठेवतात.

काय करायचं: Connections न तोडता nginx config परत वाचू दे.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Enable आणि start

का: Services BIZ चालू ठेवतात.

काय करायचं: redis boot ला enable आणि एका command मधे start.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Script check

का: Services BIZ चालू ठेवतात.

काय करायचं: Script मधे docker चालू आहे का test.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Failed units

का: Services BIZ चालू ठेवतात.

काय करायचं: Fail झालेले सगळे units list.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Unit edit नंतर

का: Services BIZ चालू ठेवतात.

काय करायचं: Unit file edit केली. systemd ला unit files परत वाचायला सांगा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Unit file दाखवा

का: Services BIZ चालू ठेवतात.

काय करायचं: Overrides सह sshd ची unit file print.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Service पूर्ण block

का: Services BIZ चालू ठेवतात.

काय करायचं: bluetooth कधीच start होऊ नये, हाताने पण.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Safely override

का: Services BIZ चालू ठेवतात.

काय करायचं: shop-api साठी drop-in override.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Dependencies

का: Services BIZ चालू ठेवतात.

काय करायचं: multi-user.target कशावर अवलंबून ते दाखवा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Default target

का: Services BIZ चालू ठेवतात.

काय करायचं: Default boot target दाखवा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

थोडक्यात सांगायचं तर

  1. status, is-active आणि is-enabled state सांगतात.
  2. start, stop, restart आत्ता; enable, disable boot ला.
  3. reload connections ठेवतो; mask प्रत्येक start block.
  4. --failed आणि list-units मोठं चित्र.
  5. Unit files: [Unit], [Service], [Install]; मग daemon-reload.
  6. Overrides साठी systemctl edit; boot time साठी systemd-analyze.

उजळणी, तुलना आणि मुलाखत cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

रोजचे 4 systemctl. Services तुमचे apps चालवतात. status, start, stop, restart. enable = boot ला start. Enable आणि आत्ता start.
उजळणी card: रोजचे 4 systemctl · PNG download करा · Card page उघडा
4 steps मधे unit file. तुमचं app service म्हणून. [Unit] [Service] [Install]. Restart=on-failure चालू ठेवतो. Edit नंतर reload.
उजळणी card: 4 steps मधे unit file · PNG download करा · Card page उघडा
start vs enable. Service आत्ता चालवतो. / प्रत्येक boot ला.
तुलना: start vs enable · PNG download करा · Card page उघडा
restart vs reload. Process stop आणि start. / जागीच config परत वाचतो.
तुलना: restart vs reload · PNG download करा · Card page उघडा
restart vs reload?. restart stop आणि start. reload config परत वाचतो, drop नाही. nginx reload.
मुलाखत card: restart vs reload? · PNG download करा · Card page उघडा
enable vs start?. start = आत्ता. enable = boot ला. दोन्ही एकदम.
मुलाखत card: enable vs start? · PNG download करा · Card page उघडा
mask काय करतो?. Unit /dev/null ला link. कोणीच start करू शकत नाही. Service block.
मुलाखत card: mask काय करतो? · PNG download करा · Card page उघडा
Service start होत नाही?. Status आणि logs वाचा. ExecStart path, user तपासा. शेवटचे logs.
मुलाखत card: Service start होत नाही? · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.