You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lab8-solution.org 4.9 KiB

11 kuukautta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #+title: Lab8 Solution
  2. #+title: Amirlan Sharipov (BS21-CS-01)
  3. #+author: Amirlan Sharipov (BS21-CS-01)
  4. #+PROPERTY: header-args :results verbatim :exports both
  5. #+OPTIONS: ^:nil
  6. * Question 1
  7. #+begin_src bash
  8. systemd-analyze
  9. systemd-analyze plot > systemd.svg
  10. #+end_src
  11. #+RESULTS:
  12. : Startup finished in 5.093s (firmware) + 122ms (loader) + 7.459s (kernel) + 4.545s (userspace) = 17.221s
  13. : graphical.target reached after 4.544s in userspace.
  14. #+ATTR_HTML: :width 1000px
  15. [[./systemd.svg]]
  16. * Question 2
  17. graphical.target -> multi-user.target -> basic.target -> sysinit.target
  18. #+begin_src bash
  19. cat /usr/lib/systemd/system/graphical.target
  20. cat /usr/lib/systemd/system/multi-user.target
  21. cat /usr/lib/systemd/system/basic.target
  22. cat /usr/lib/systemd/system/sysinit.target
  23. #+end_src
  24. #+RESULTS:
  25. #+begin_example
  26. # SPDX-License-Identifier: LGPL-2.1-or-later
  27. #
  28. # This file is part of systemd.
  29. #
  30. # systemd is free software; you can redistribute it and/or modify it
  31. # under the terms of the GNU Lesser General Public License as published by
  32. # the Free Software Foundation; either version 2.1 of the License, or
  33. # (at your option) any later version.
  34. [Unit]
  35. Description=Graphical Interface
  36. Documentation=man:systemd.special(7)
  37. Requires=multi-user.target
  38. Wants=display-manager.service
  39. Conflicts=rescue.service rescue.target
  40. After=multi-user.target rescue.service rescue.target display-manager.service
  41. AllowIsolate=yes
  42. # SPDX-License-Identifier: LGPL-2.1-or-later
  43. #
  44. # This file is part of systemd.
  45. #
  46. # systemd is free software; you can redistribute it and/or modify it
  47. # under the terms of the GNU Lesser General Public License as published by
  48. # the Free Software Foundation; either version 2.1 of the License, or
  49. # (at your option) any later version.
  50. [Unit]
  51. Description=Multi-User System
  52. Documentation=man:systemd.special(7)
  53. Requires=basic.target
  54. Conflicts=rescue.service rescue.target
  55. After=basic.target rescue.service rescue.target
  56. AllowIsolate=yes
  57. # SPDX-License-Identifier: LGPL-2.1-or-later
  58. #
  59. # This file is part of systemd.
  60. #
  61. # systemd is free software; you can redistribute it and/or modify it
  62. # under the terms of the GNU Lesser General Public License as published by
  63. # the Free Software Foundation; either version 2.1 of the License, or
  64. # (at your option) any later version.
  65. [Unit]
  66. Description=Basic System
  67. Documentation=man:systemd.special(7)
  68. Requires=sysinit.target
  69. Wants=sockets.target timers.target paths.target slices.target
  70. After=sysinit.target sockets.target paths.target slices.target tmp.mount
  71. # We support /var, /tmp, /var/tmp, being on NFS, but we don't pull in
  72. # remote-fs.target by default, hence pull them in explicitly here. Note that we
  73. # require /var and /var/tmp, but only add a Wants= type dependency on /tmp, as
  74. # we support that unit being masked, and this should not be considered an error.
  75. RequiresMountsFor=/var /var/tmp
  76. Wants=tmp.mount
  77. # SPDX-License-Identifier: LGPL-2.1-or-later
  78. #
  79. # This file is part of systemd.
  80. #
  81. # systemd is free software; you can redistribute it and/or modify it
  82. # under the terms of the GNU Lesser General Public License as published by
  83. # the Free Software Foundation; either version 2.1 of the License, or
  84. # (at your option) any later version.
  85. [Unit]
  86. Description=System Initialization
  87. Documentation=man:systemd.special(7)
  88. Wants=local-fs.target swap.target
  89. After=local-fs.target swap.target
  90. Conflicts=emergency.service emergency.target
  91. Before=emergency.service emergency.target
  92. #+end_example
  93. ** Information taken from man pages:
  94. *** basic.target
  95. A special target unit covering basic boot-up.
  96. *** graphical.target
  97. A special target unit for setting up a graphical login screen. This pulls in multi-user.target.
  98. *** multi-user.target
  99. A special target unit for setting up a multi-user system (non-graphical). This is pulled in by graphical.target.
  100. *** sysinit.target
  101. This target pulls in the services required for system initialization.
  102. ** Wants for sysinit.target
  103. Wants=local-fs.target swap.target
  104. Wants is used like Requires, but it's less strict, meaning that it can start if the "wanted" service doesn't exist or failed to start.
  105. In this case, it wants local filesystems and swap to start.
  106. * Question 3
  107. #+begin_src bash
  108. cat webserver.sh
  109. #+end_src
  110. #+RESULTS:
  111. : #!/bin/bash
  112. :
  113. : while true ; do
  114. : STATS="<h1>Uptime</h1>$(uptime)\n<h1>Inode and disk usage</h1>$(df -ih)\n<h1>Mem usage</h1>$(free -h)\n<h1>Syslog</h1>$(tail -n 15 /var/log/syslog)\r\n\r\n"
  115. : LEN=$(printf "%s" "$STATS" | wc -c)
  116. : RES="HTTP/1.1 200OK\r\nContent-Length: $LEN\r\n\r\n"
  117. : echo -e "$RES$STATS"| nc -l -p 1500;
  118. : done
  119. [Unit]
  120. Description=stats web server
  121. [Service]
  122. User=root
  123. ExecStart=/home/rinri/edu/sna/webserver.sh
  124. Restart=always
  125. CPUQuota=15%
  126. MemoryMax=256000000
  127. [Install]
  128. WantedBy=multi-user.target
  129. * Question 4
  130. #+begin_src bash
  131. cat update.sh
  132. #+end_src
  133. [Unit]
  134. Description=update package sources list
  135. [Service]
  136. User=root
  137. ExecStart=/home/rinri/edu/sna/update.sh
  138. [Install]
  139. WantedBy=multi-user.target