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.
 
 
 

459 lines
47 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <meta name="mobile-web-app-capable" content="yes">
  10. <title>
  11. Lab 8: Systemd - HackMD
  12. </title>
  13. <link rel="icon" type="image/png" href="https://hackmd.io/favicon.png">
  14. <link rel="apple-touch-icon" href="https://hackmd.io/apple-touch-icon.png">
  15. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
  16. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
  17. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" integrity="sha256-3iu9jgsy9TpTwXKb7bNQzqWekRX7pPK+2OLj3R922fo=" crossorigin="anonymous" />
  18. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/3.5.0/octicons.min.css" integrity="sha256-QiWfLIsCT02Sdwkogf6YMiQlj4NE84MKkzEMkZnMGdg=" crossorigin="anonymous" />
  19. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism.min.css" integrity="sha256-vtR0hSWRc3Tb26iuN2oZHt3KRUomwTufNIf5/4oeCyg=" crossorigin="anonymous" />
  20. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@hackmd/emojify.js@2.1.0/dist/css/basic/emojify.min.css" integrity="sha256-UOrvMOsSDSrW6szVLe8ZDZezBxh5IoIfgTwdNDgTjiU=" crossorigin="anonymous" />
  21. <style>
  22. @import url(https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i|Source+Code+Pro:300,400,500|Source+Sans+Pro:300,300i,400,400i,600,600i|Source+Serif+Pro&subset=latin-ext);.hljs{background:#fff;color:#333;display:block;overflow-x:auto;padding:.5em}.hljs-comment,.hljs-meta{color:#969896}.hljs-emphasis,.hljs-quote,.hljs-string,.hljs-strong,.hljs-template-variable,.hljs-variable{color:#df5000}.hljs-keyword,.hljs-selector-tag,.hljs-type{color:#a71d5d}.hljs-attribute,.hljs-bullet,.hljs-literal,.hljs-number,.hljs-symbol{color:#0086b3}.hljs-built_in,.hljs-builtin-name{color:#005cc5}.hljs-name,.hljs-section{color:#63a35c}.hljs-tag{color:#333}.hljs-attr,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-selector-pseudo,.hljs-title{color:#795da3}.hljs-addition{background-color:#eaffea;color:#55a532}.hljs-deletion{background-color:#ffecec;color:#bd2c00}.hljs-link{text-decoration:underline}.markdown-body{word-wrap:break-word;font-size:16px;line-height:1.5}.markdown-body:after,.markdown-body:before{content:"";display:table}.markdown-body:after{clear:both}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body .absent{color:#c00}.markdown-body .anchor{float:left;line-height:1;margin-left:-20px;padding-right:4px}.markdown-body .anchor:focus{outline:none}.markdown-body blockquote,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-bottom:16px;margin-top:0}.markdown-body hr{background-color:#e7e7e7;border:0;height:.25em;margin:24px 0;padding:0}.markdown-body blockquote{border-left:.25em solid #ddd;color:#777;font-size:16px;padding:0 1em}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body kbd,.popover kbd{background-color:#fcfcfc;border:1px solid;border-color:#ccc #ccc #bbb;border-radius:3px;box-shadow:inset 0 -1px 0 #bbb;color:#555;display:inline-block;font-size:11px;line-height:10px;padding:3px 5px;vertical-align:middle}.markdown-body .loweralpha{list-style-type:lower-alpha}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{font-weight:600;line-height:1.25;margin-bottom:16px;margin-top:24px}.markdown-body h1 .octicon-link,.markdown-body h2 .octicon-link,.markdown-body h3 .octicon-link,.markdown-body h4 .octicon-link,.markdown-body h5 .octicon-link,.markdown-body h6 .octicon-link{color:#000;vertical-align:middle;visibility:hidden}.markdown-body h1:hover .anchor,.markdown-body h2:hover .anchor,.markdown-body h3:hover .anchor,.markdown-body h4:hover .anchor,.markdown-body h5:hover .anchor,.markdown-body h6:hover .anchor{text-decoration:none}.markdown-body h1:hover .anchor .octicon-link,.markdown-body h2:hover .anchor .octicon-link,.markdown-body h3:hover .anchor .octicon-link,.markdown-body h4:hover .anchor .octicon-link,.markdown-body h5:hover .anchor .octicon-link,.markdown-body h6:hover .anchor .octicon-link{visibility:visible}.markdown-body h1 code,.markdown-body h1 tt,.markdown-body h2 code,.markdown-body h2 tt,.markdown-body h3 code,.markdown-body h3 tt,.markdown-body h4 code,.markdown-body h4 tt,.markdown-body h5 code,.markdown-body h5 tt,.markdown-body h6 code,.markdown-body h6 tt{font-size:inherit}.markdown-body h1{font-size:2em}.markdown-body h1,.markdown-body h2{border-bottom:1px solid #eee;padding-bottom:.3em}.markdown-body h2{font-size:1.5em}.markdown-body h3{font-size:1.25em}.markdown-body h4{font-size:1em}.markdown-body h5{font-size:.875em}.markdown-body h6{color:#777;font-size:.85em}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol.no-list,.markdown-body ul.no-list{list-style-type:none;padding:0}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-bottom:0;margin-top:0}.markdown-body li>p{margin-top:16px}.markdown-body li+li{padding-top:.25em}.markdown-body dl{padding:0}.markdown-body dl dt{font-size:1em;font-style:italic;font-weight:700;margin-top:16px;padding:0}.markdown-body dl dd{margin-bottom:16px;padding:0 16px}.markdown-body table{display:block;overflow:auto;width:100%;word-break:normal;word-break:keep-all}.markdown-body table th{font-weight:700}.markdown-body table td,.markdown-body table th{border:1px solid #ddd;padding:6px 13px}.markdown-body table tr{background-color:#fff;border-top:1px solid #ccc}.markdown-body table tr:nth-child(2n){background-color:#f8f8f8}.markdown-body img{background-color:#fff;box-sizing:initial;max-width:100%}.markdown-body img[align=right]{padding-left:20px}.markdown-body img[align=left]{padding-right:20px}.markdown-body .emoji{background-color:initial;max-width:none;vertical-align:text-top}.markdown-body span.frame{display:block;overflow:hidden}.markdown-body span.frame>span{border:1px solid #ddd;display:block;float:left;margin:13px 0 0;overflow:hidden;padding:7px;width:auto}.markdown-body span.frame span img{display:block;float:left}.markdown-body span.frame span span{clear:both;color:#333;display:block;padding:5px 0 0}.markdown-body span.align-center{clear:both;display:block;overflow:hidden}.markdown-body span.align-center>span{display:block;margin:13px auto 0;overflow:hidden;text-align:center}.markdown-body span.align-center span img{margin:0 auto;text-align:center}.markdown-body span.align-right{clear:both;display:block;overflow:hidden}.markdown-body span.align-right>span{display:block;margin:13px 0 0;overflow:hidden;text-align:right}.markdown-body span.align-right span img{margin:0;text-align:right}.markdown-body span.float-left{display:block;float:left;margin-right:13px;overflow:hidden}.markdown-body span.float-left span{margin:13px 0 0}.markdown-body span.float-right{display:block;float:right;margin-left:13px;overflow:hidden}.markdown-body span.float-right>span{display:block;margin:13px auto 0;overflow:hidden;text-align:right}.markdown-body code,.markdown-body tt{background-color:#0000000a;border-radius:3px;font-size:85%;margin:0;padding:.2em 0}.markdown-body code:after,.markdown-body code:before,.markdown-body tt:after,.markdown-body tt:before{content:"\00a0";letter-spacing:-.2em}.markdown-body code br,.markdown-body tt br{display:none}.markdown-body del code{text-decoration:inherit}.markdown-body pre{word-wrap:normal}.markdown-body pre>code{background:#0000;border:0;font-size:100%;margin:0;padding:0;white-space:pre;word-break:normal}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{background-color:#f7f7f7;border-radius:3px;font-size:85%;line-height:1.45;overflow:auto;padding:16px}.markdown-body pre code,.markdown-body pre tt{word-wrap:normal;background-color:initial;border:0;display:inline;line-height:inherit;margin:0;max-width:auto;overflow:visible;padding:0}.markdown-body pre code:after,.markdown-body pre code:before,.markdown-body pre tt:after,.markdown-body pre tt:before{content:normal}.markdown-body .csv-data td,.markdown-body .csv-data th{font-size:12px;line-height:1;overflow:hidden;padding:5px;text-align:left;white-space:nowrap}.markdown-body .csv-data .blob-line-num{background:#fff;border:0;padding:10px 8px 9px;text-align:right}.markdown-body .csv-data tr{border-top:0}.markdown-body .csv-data th{background:#f8f8f8;border-top:0;font-weight:700}.news .alert .markdown-body blockquote{border:0;padding:0 0 0 40px}.activity-tab .news .alert .commits,.activity-tab .news .markdown-body blockquote{padding-left:0}.task-list-item{list-style-type:none}.task-list-item label{font-weight:400}.task-list-item.enabled label{cursor:pointer}.task-list-item+.task-list-item{margin-top:3px}.task-list-item-checkbox{cursor:default!important;float:left;margin:.31em 0 .2em -1.3em!important;vertical-align:middle}.markdown-body{max-width:758px;overflow:visible!important;padding-bottom:40px;padding-top:40px;position:relative}.markdown-body .emoji{vertical-align:top}.markdown-body pre{border:inherit!important}.markdown-body code{color:inherit!important}.markdown-body pre code .wrapper{display:-moz-inline-flex;display:-ms-inline-flex;display:-o-inline-flex;display:inline-flex}.markdown-body pre code .gutter{float:left;overflow:hidden;-webkit-user-select:none;user-select:none}.markdown-body pre code .gutter.linenumber{border-right:3px solid #6ce26c!important;box-sizing:initial;color:#afafaf!important;cursor:default;display:inline-block;min-width:20px;padding:0 8px 0 0;position:relative;text-align:right;z-index:4}.markdown-body pre code .gutter.linenumber>span:before{content:attr(data-linenumber)}.markdown-body pre code .code{float:left;margin:0 0 0 16px}.markdown-body .gist .line-numbers{border-bottom:none;border-left:none;border-top:none}.markdown-body .gist .line-data{border:none}.markdown-body .gist table{border-collapse:inherit!important;border-spacing:0}.markdown-body code[data-gist-id]{background:none;padding:0}.markdown-body code[data-gist-id]:after,.markdown-body code[data-gist-id]:before{content:""}.markdown-body code[data-gist-id] .blob-num{border:unset}.markdown-body code[data-gist-id] table{margin-bottom:unset;overflow:unset}.markdown-body code[data-gist-id] table tr{background:unset}.markdown-body[dir=rtl] pre{direction:ltr}.markdown-body[dir=rtl] code{direction:ltr;unicode-bidi:embed}.markdown-body .alert>p:last-child{margin-bottom:0}.markdown-body pre.abc,.markdown-body pre.flow-chart,.markdown-body pre.graphviz,.markdown-body pre.mermaid,.markdown-body pre.sequence-diagram,.markdown-body pre.vega{background-color:inherit;border-radius:0;overflow:visible;text-align:center;white-space:inherit}.markdown-body pre.abc>code,.markdown-body pre.flow-chart>code,.markdown-body pre.graphviz>code,.markdown-body pre.mermaid>code,.markdown-body pre.sequence-diagram>code,.markdown-body pre.vega>code{text-align:left}.markdown-body pre.abc>svg,.markdown-body pre.flow-chart>svg,.markdown-body pre.graphviz>svg,.markdown-body pre.mermaid>svg,.markdown-body pre.sequence-diagram>svg,.markdown-body pre.vega>svg{height:100%;max-width:100%}.markdown-body pre>code.wrap{word-wrap:break-word;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap}.markdown-body .alert>p:last-child,.markdown-body .alert>ul:last-child{margin-bottom:0}.markdown-body summary{display:list-item}.markdown-body summary:focus{outline:none}.markdown-body details summary{cursor:pointer}.markdown-body details:not([open])>:not(summary){display:none}.markdown-body figure{margin:1em 40px}.markdown-body .mark,.markdown-body mark{background-color:#fff1a7}.vimeo,.youtube{background-color:#000;background-position:50%;background-repeat:no-repeat;background-size:contain;cursor:pointer;display:table;overflow:hidden;text-align:center}.vimeo,.youtube{position:relative;width:100%}.youtube{padding-bottom:56.25%}.vimeo img{object-fit:contain;width:100%;z-index:0}.youtube img{object-fit:cover;z-index:0}.vimeo iframe,.youtube iframe,.youtube img{height:100%;left:0;position:absolute;top:0;width:100%}.vimeo iframe,.youtube iframe{vertical-align:middle;z-index:1}.vimeo .icon,.youtube .icon{color:#fff;height:auto;left:50%;opacity:.3;position:absolute;top:50%;transform:translate(-50%,-50%);transition:opacity .2s;width:auto;z-index:0}.vimeo:hover .icon,.youtube:hover .icon{opacity:.6;transition:opacity .2s}.slideshare .inner,.speakerdeck .inner{position:relative;width:100%}.slideshare .inner iframe,.speakerdeck .inner iframe{bottom:0;height:100%;left:0;position:absolute;right:0;top:0;width:100%}.figma{display:table;padding-bottom:56.25%;position:relative;width:100%}.figma iframe{border:1px solid #eee;bottom:0;height:100%;left:0;position:absolute;right:0;top:0;width:100%}.markmap-container{height:300px}.markmap-container>svg{height:100%;width:100%}.MJX_Assistive_MathML{display:none}#MathJax_Message{z-index:1000!important}.ui-infobar{color:#777;margin:25px auto -25px;max-width:760px;position:relative;z-index:2}.toc .invisable-node{list-style-type:none}.ui-toc{bottom:20px;position:fixed;z-index:998}.ui-toc.both-mode{margin-left:8px}.ui-toc.both-mode .ui-toc-label{border-bottom-left-radius:0;border-top-left-radius:0;height:40px;padding:10px 4px}.ui-toc-label{background-color:#e6e6e6;border:none;color:#868686;transition:opacity .2s}.ui-toc .open .ui-toc-label{color:#fff;opacity:1;transition:opacity .2s}.ui-toc-label:focus{background-color:#ccc;color:#000;opacity:.3}.ui-toc-label:hover{background-color:#ccc;opacity:1;transition:opacity .2s}.ui-toc-dropdown{margin-bottom:20px;margin-top:20px;max-height:70vh;max-width:45vw;overflow:auto;padding-left:10px;padding-right:10px;text-align:inherit;width:25vw}.ui-toc-dropdown>.toc{max-height:calc(70vh - 100px);overflow:auto}.ui-toc-dropdown[dir=rtl] .nav{letter-spacing:.0029em;padding-right:0}.ui-toc-dropdown a{overflow:hidden;text-overflow:ellipsis;white-space:pre}.ui-toc-dropdown .nav>li>a{color:#767676;display:block;font-size:13px;font-weight:500;padding:4px 20px}.ui-toc-dropdown .nav>li:first-child:last-child>ul,.ui-toc-dropdown .toc.expand ul{display:block}.ui-toc-dropdown .nav>li>a:focus,.ui-toc-dropdown .nav>li>a:hover{background-color:initial;border-left:1px solid #000;color:#000;padding-left:19px;text-decoration:none}.ui-toc-dropdown[dir=rtl] .nav>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav>li>a:hover{border-left:none;border-right:1px solid #000;padding-right:19px}.ui-toc-dropdown .nav>.active:focus>a,.ui-toc-dropdown .nav>.active:hover>a,.ui-toc-dropdown .nav>.active>a{background-color:initial;border-left:2px solid #000;color:#000;font-weight:700;padding-left:18px}.ui-toc-dropdown[dir=rtl] .nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav>.active>a{border-left:none;border-right:2px solid #000;padding-right:18px}.ui-toc-dropdown .nav .nav{display:none;padding-bottom:10px}.ui-toc-dropdown .nav>.active>ul{display:block}.ui-toc-dropdown .nav .nav>li>a{font-size:12px;font-weight:400;padding-bottom:1px;padding-left:30px;padding-top:1px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>a{padding-right:30px}.ui-toc-dropdown .nav .nav>li>ul>li>a{font-size:12px;font-weight:400;padding-bottom:1px;padding-left:40px;padding-top:1px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a{padding-right:40px}.ui-toc-dropdown .nav .nav>li>a:focus,.ui-toc-dropdown .nav .nav>li>a:hover{padding-left:29px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav .nav>li>a:hover{padding-right:29px}.ui-toc-dropdown .nav .nav>li>ul>li>a:focus,.ui-toc-dropdown .nav .nav>li>ul>li>a:hover{padding-left:39px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a:hover{padding-right:39px}.ui-toc-dropdown .nav .nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>a{font-weight:500;padding-left:28px}.ui-toc-dropdown[dir=rtl] .nav .nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>a{padding-right:28px}.ui-toc-dropdown .nav .nav>.active>.nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>a{font-weight:500;padding-left:38px}.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active>a{padding-right:38px}.markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html[lang^=ja] .markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS ゴシック,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html[lang=zh-tw] .markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html[lang=zh-cn] .markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html .markdown-body[lang^=ja]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS ゴシック,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html .markdown-body[lang=zh-tw]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html .markdown-body[lang=zh-cn]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica Neue,Helvetica,Roboto,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol}html[lang^=ja] .ui-toc-dropdown{font-family:Source Sans Pro,Helvetica,Arial,Meiryo UI,MS PGothic,MS Pゴシック,sans-serif}html[lang=zh-tw] .ui-toc-dropdown{font-family:Source Sans Pro,Helvetica,Arial,Microsoft JhengHei UI,微軟正黑UI,sans-serif}html[lang=zh-cn] .ui-toc-dropdown{font-family:Source Sans Pro,Helvetica,Arial,Microsoft YaHei UI,微软雅黑UI,sans-serif}html .ui-toc-dropdown[lang^=ja]{font-family:Source Sans Pro,Helvetica,Arial,Meiryo UI,MS PGothic,MS Pゴシック,sans-serif}html .ui-toc-dropdown[lang=zh-tw]{font-family:Source Sans Pro,Helvetica,Arial,Microsoft JhengHei UI,微軟正黑UI,sans-serif}html .ui-toc-dropdown[lang=zh-cn]{font-family:Source Sans Pro,Helvetica,Arial,Microsoft YaHei UI,微软雅黑UI,sans-serif}.ui-affix-toc{max-height:70vh;max-width:15vw;overflow:auto;position:fixed;top:0}.back-to-top,.expand-toggle,.go-to-bottom{color:#999;display:block;font-size:12px;font-weight:500;margin-left:10px;margin-top:10px;padding:4px 10px}.back-to-top:focus,.back-to-top:hover,.expand-toggle:focus,.expand-toggle:hover,.go-to-bottom:focus,.go-to-bottom:hover{color:#563d7c;text-decoration:none}.back-to-top,.go-to-bottom{margin-top:0}.ui-user-icon{background-position:50%;background-repeat:no-repeat;background-size:cover;border-radius:50%;display:block;height:20px;margin-bottom:2px;margin-right:5px;margin-top:2px;width:20px}.ui-user-icon.small{display:inline-block;height:18px;margin:0 0 .2em;vertical-align:middle;width:18px}.ui-infobar>small>span{line-height:22px}.ui-infobar>small .dropdown{display:inline-block}.ui-infobar>small .dropdown a:focus,.ui-infobar>small .dropdown a:hover{text-decoration:none}.ui-more-info{color:#888;cursor:pointer;vertical-align:middle}.ui-more-info .fa{font-size:16px}.ui-connectedGithub,.ui-published-note{color:#888}.ui-connectedGithub{line-height:23px;white-space:nowrap}.ui-connectedGithub a.file-path{color:#888;padding-left:22px;text-decoration:none}.ui-connectedGithub a.file-path:active,.ui-connectedGithub a.file-path:hover{color:#888;text-decoration:underline}.ui-connectedGithub .fa{font-size:20px}.ui-published-note .fa{font-size:20px;vertical-align:top}.unselectable{-webkit-user-select:none;-o-user-select:none;user-select:none}.selectable{-webkit-user-select:text;-o-user-select:text;user-select:text}.inline-spoiler-section{cursor:pointer}.inline-spoiler-section .spoiler-text{background-color:#333;border-radius:2px}.inline-spoiler-section .spoiler-text>*{opacity:0}.inline-spoiler-section .spoiler-img{filter:blur(10px)}.inline-spoiler-section.raw{background-color:#333;border-radius:2px}.inline-spoiler-section.raw>*{opacity:0}.inline-spoiler-section.unveil{cursor:auto}.inline-spoiler-section.unveil .spoiler-text{background-color:#3333331a}.inline-spoiler-section.unveil .spoiler-text>*{opacity:1}.inline-spoiler-section.unveil .spoiler-img{filter:none}@media print{blockquote,div,img,pre,table{page-break-inside:avoid!important}a[href]:after{font-size:12px!important}}.markdown-body.slides{color:#222;position:relative;z-index:1}.markdown-body.slides:before{background-color:currentColor;bottom:0;box-shadow:0 0 0 50vw;content:"";display:block;left:0;position:absolute;right:0;top:0;z-index:-1}.markdown-body.slides section[data-markdown]{background-color:#fff;margin-bottom:1.5em;position:relative;text-align:center}.markdown-body.slides section[data-markdown] code{text-align:left}.markdown-body.slides section[data-markdown]:before{content:"";display:block;padding-bottom:56.23%}.markdown-body.slides section[data-markdown]>div:first-child{left:1em;max-height:100%;overflow:hidden;position:absolute;right:1em;top:50%;transform:translateY(-50%)}.markdown-body.slides section[data-markdown]>ul{display:inline-block}.markdown-body.slides>section>section+section:after{border:3px solid #777;content:"";height:1.5em;position:absolute;right:1em;top:-1.5em}.site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,sans-serif}html[lang^=ja] .site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS ゴシック,sans-serif}html[lang=zh-tw] .site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif}html[lang=zh-cn] .site-ui-font{font-family:Source Sans Pro,Helvetica,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif}body{font-smoothing:subpixel-antialiased!important;-webkit-font-smoothing:subpixel-antialiased!important;-moz-osx-font-smoothing:auto!important;-webkit-overflow-scrolling:touch;font-family:Source Sans Pro,Helvetica,Arial,sans-serif;letter-spacing:.025em}html[lang^=ja] body{font-family:Source Sans Pro,Helvetica,Arial,Hiragino Kaku Gothic Pro,ヒラギノ角ゴ Pro W3,Osaka,Meiryo,メイリオ,MS Gothic,MS ゴシック,sans-serif}html[lang=zh-tw] body{font-family:Source Sans Pro,Helvetica,Arial,PingFang TC,Microsoft JhengHei,微軟正黑,sans-serif}html[lang=zh-cn] body{font-family:Source Sans Pro,Helvetica,Arial,PingFang SC,Microsoft YaHei,微软雅黑,sans-serif}abbr[title]{border-bottom:none;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}abbr[data-original-title],abbr[title]{cursor:help}body.modal-open{overflow-y:auto;padding-right:0!important}svg{text-shadow:none}
  23. </style>
  24. <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  25. <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  26. <!--[if lt IE 9]>
  27. <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js" integrity="sha256-3Jy/GbSLrg0o9y5Z5n1uw0qxZECH7C6OQpVBgNFYa0g=" crossorigin="anonymous"></script>
  28. <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js" integrity="sha256-g6iAfvZp+nDQ2TdTR/VVKJf3bGro4ub5fvWSWVRi2NE=" crossorigin="anonymous"></script>
  29. <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js" integrity="sha256-8E4Is26QH0bD52WoQpcB+R/tcWQtpzlCojrybUd7Mxo=" crossorigin="anonymous"></script>
  30. <![endif]-->
  31. </head>
  32. <body>
  33. <div id="doc" class="markdown-body container-fluid comment-enabled" data-hard-breaks="true"><h1 id="Lab-8-Systemd" data-id="Lab-8-Systemd"><a class="anchor hidden-xs" href="#Lab-8-Systemd" title="Lab-8-Systemd"><span class="octicon octicon-link"></span></a><span>Lab 8: Systemd</span></h1><h2 id="Task-1-Create-a-shell-script" data-id="Task-1-Create-a-shell-script"><a class="anchor hidden-xs" href="#Task-1-Create-a-shell-script" title="Task-1-Create-a-shell-script"><span class="octicon octicon-link"></span></a><span>Task 1: Create a shell script</span></h2><ul data-original-title="" title="">
  34. <li><span>Create a custom web server with bash. The web server displays the processes running on the server by executing the </span><code>top</code><span> command.</span><pre><code>$ sudo vim /usr/bin/script.sh
  35. </code></pre>
  36. </li>
  37. <li><span>Add the following to the file.</span><pre><code class="bash hljs"><div class="wrapper"><div class="gutter linenumber"><span></span>
  38. <span></span>
  39. <span></span>
  40. <span></span>
  41. <span></span>
  42. <span></span>
  43. <span></span>
  44. <span></span>
  45. <span></span>
  46. <span></span></div><div class="code"><span class="hljs-meta">#!/bin/bash</span>
  47. <span class="hljs-keyword">while</span> <span class="hljs-literal">true</span>;
  48. <span class="hljs-keyword">do</span> <span class="hljs-built_in">dd</span> <span class="hljs-keyword">if</span>=/dev/zero of=/dev/null
  49. <span class="hljs-keyword">done</span> &amp;
  50. <span class="hljs-keyword">while</span> <span class="hljs-literal">true</span>;
  51. <span class="hljs-keyword">do</span> <span class="hljs-built_in">echo</span> -e <span class="hljs-string">"HTTP/1.1 200 OK\n\n<span class="hljs-subst">$(top -bn1)</span>"</span> \
  52. | nc -l -k -p 8080 -q 1;
  53. <span class="hljs-keyword">done</span>
  54. </div></div></code></pre>
  55. <blockquote>
  56. <p><code>dd</code><span> has been added for a purpose which you will see in further sections.</span><br>
  57. <span>Consider the web server as a means of remotely viewing the resource usage of </span><code>dd</code><span>.</span></p>
  58. </blockquote>
  59. </li>
  60. <li><span>Save the script and set execute permission.</span><pre><code>$ sudo chmod +x /usr/bin/script.sh
  61. </code></pre>
  62. </li>
  63. </ul><p><span>You have to manually run this script whenever the system is restarted. We can solve this by creating a systemd service for it. This will give us more options for managing the script’s execution.</span></p><h2 id="Task-2-Create-a-systemd-file" data-id="Task-2-Create-a-systemd-file"><a class="anchor hidden-xs" href="#Task-2-Create-a-systemd-file" title="Task-2-Create-a-systemd-file"><span class="octicon octicon-link"></span></a><span>Task 2: Create a systemd file</span></h2><p><span>Next, create a systemd service file for the script on your system. This file must have </span><code>.service</code><span> extension and saved under the </span><code>/lib/systemd/system/</code><span> directory</span></p><pre><code>$ sudo vim /lib/systemd/system/shellscript.service
  64. </code></pre><p><span>Now, add the following content and update the script filename and location. You can also change the description of the service. After that, save the file and close it.</span></p><pre><code class="hljs"><div class="wrapper"><div class="gutter linenumber"><span></span>
  65. <span></span>
  66. <span></span>
  67. <span></span>
  68. <span></span>
  69. <span></span>
  70. <span></span>
  71. <span></span></div><div class="code">[Unit]
  72. Description=My custom web service to show system processes
  73. [Service]
  74. ExecStart=/usr/bin/script.sh
  75. [Install]
  76. WantedBy=multi-user.target
  77. </div></div></code></pre><blockquote>
  78. <p><span>The [Unit] section describes the service, specifies the ordering dependencies, as well as conflicting units. In [Service], a sequence of custom scripts is specified to be executed during unit activation, on stop, and on reload. Finally, the [Install] section lists units that depend on the service.</span></p>
  79. </blockquote><h2 id="Task-3-Enable-the-service" data-id="Task-3-Enable-the-service"><a class="anchor hidden-xs" href="#Task-3-Enable-the-service" title="Task-3-Enable-the-service"><span class="octicon octicon-link"></span></a><span>Task 3: Enable the service</span></h2><ul>
  80. <li><span>Your systemd service has been added to your system. Let’s reload the systemctl daemon to read new files. You need to reload the configuration file of a unit each time after making changes in any </span><code>*.service</code><span> file.</span><pre><code>$ sudo systemctl daemon-reload
  81. </code></pre>
  82. </li>
  83. <li><span>Enable the service to start on system boot and also start the service using the following commands.</span><pre><code>$ sudo systemctl enable shellscript.service
  84. $ sudo systemctl start shellscript.service
  85. </code></pre>
  86. <blockquote>
  87. <p><span>When you enable a service, a symbolic link of that service is created in the </span><code>/etc/systemd/system/multi-user.target.wants</code><span> directory.</span></p>
  88. </blockquote>
  89. </li>
  90. <li><span>Finally, verify that the script is up and running as a systemd service.</span><pre><code>$ sudo systemctl status shellscript.service
  91. </code></pre>
  92. </li>
  93. <li><span>Example output when we access the web service via port 8080 is shown below.</span><br>
  94. <img src="https://i.imgur.com/GfB4DAB.jpg" alt="" loading="lazy"></li>
  95. <li><span>The </span><code>dd</code><span> process shown in the output was executed by the service we just created. This process is using 100% of the CPU. We can fix this problem by making use of systemd control groups.</span></li>
  96. </ul><h2 id="Task-4-Systemd-control-groups-cgroups" data-id="Task-4-Systemd-control-groups-cgroups"><a class="anchor hidden-xs" href="#Task-4-Systemd-control-groups-cgroups" title="Task-4-Systemd-control-groups-cgroups"><span class="octicon octicon-link"></span></a><span>Task 4: Systemd control groups (cgroups)</span></h2><p><span>Systemd control group is a mechanism that allows you to control the use of system resources by a group of processes.</span></p><ul>
  97. <li>
  98. <p><span>You can view the cgroup of a service with the </span><code>systemctl status &lt;service_name&gt;</code><span> command.</span><br>
  99. <span>Let’s view the status of our custom system service </span><code>shellscript.service</code><span> again.</span></p>
  100. <pre><code>$ systemctl status shellscript.service
  101. </code></pre>
  102. <p><span>You get an output similar to the following</span></p>
  103. <pre><code>● shellscript.service - My Shell Script
  104. Loaded: loaded (/lib/systemd/system/shellscript.service; enabled; vendor preset: enabled)
  105. Active: active (running) since Sun 2022-10-23 19:39:02 +04; 1s ago
  106. Main PID: 6821 (script.sh)
  107. Tasks: 4 (limit: 9415)
  108. Memory: 1.0M
  109. CPU: 1.945s
  110. CGroup: /system.slice/shellscript.service
  111. ├─6821 /bin/bash /usr/bin/script.sh
  112. ├─6822 /bin/bash /usr/bin/script.sh
  113. ├─6824 nc -l -k -p 8080 -q 1
  114. └─6825 dd if=/dev/zero of=/dev/null
  115. </code></pre>
  116. <p><span>The output shows that </span><code>shellscript.service</code><span> is under the </span><code>system.slice</code><span> control group.</span><br>
  117. <span>The second line </span><code>6821 /bin/bash /usr/bin/script.sh</code><span> shows the process ID and the command used to start </span><code>shellscript.service</code><span>.</span><br>
  118. <span>Subsequent lines under the </span><code>CGroup</code><span> are the other commands executed in the service.</span></p>
  119. </li>
  120. <li>
  121. <p><span>View your system’s cgroup hierarchy</span></p>
  122. <pre><code>$ systemctl status
  123. </code></pre>
  124. </li>
  125. <li>
  126. <p><span>You can view the system resource usage by each cgroup</span></p>
  127. <pre><code>$ systemd-cgtop
  128. </code></pre>
  129. </li>
  130. <li>
  131. <p><span>Slices allow one to create a hierarchical structure in which relative shares of resources are defined for the entities that belong to those slices.</span><br>
  132. <span>View a list of all systemd slices</span></p>
  133. <pre><code>$ systemctl -t slice --all
  134. </code></pre>
  135. </li>
  136. <li>
  137. <p><span>Create a systemd slice at </span><code>/etc/systemd/system/testslice.slice</code><span>. Add the following to the file.</span></p>
  138. <pre><code class="hljs"><div class="wrapper"><div class="gutter linenumber"><span></span>
  139. <span></span>
  140. <span></span>
  141. <span></span>
  142. <span></span>
  143. <span></span>
  144. <span></span>
  145. <span></span>
  146. <span></span></div><div class="code">[Unit]
  147. Description=Custom systemd slice for SNA lab on systemd.
  148. Before=slices.target
  149. [Slice]
  150. MemoryAccounting=true
  151. CPUAccounting=true
  152. MemoryMax=10%
  153. CPUQuota=10%
  154. </div></div></code></pre>
  155. <p><span>This slice will set CPU and memory usage limit to all processes running under it. As seen in the configuration, a maximum of 10% of memory and CPU resources can be used by the processes running under this control group </span><code>testslice.slice</code><span>.</span></p>
  156. </li>
  157. <li>
  158. <p><span>Let’s add our custom service </span><code>shellscript.service</code><span>to this new control group.</span><br>
  159. <span>Modify the service file </span><code>/lib/systemd/system/shellscript.service</code><span> to use this systemd slice by adding the line </span><code>Slice=testslice.slice</code><span> to the </span><code>[Service]</code><span> section as shown below:</span></p>
  160. <pre><code class="hljs"><div class="wrapper"><div class="gutter linenumber"><span></span>
  161. <span></span>
  162. <span></span>
  163. <span></span>
  164. <span></span>
  165. <span></span>
  166. <span></span>
  167. <span></span>
  168. <span></span></div><div class="code">[Unit]
  169. Description=My custom web service to show system processes
  170. [Service]
  171. ExecStart=/usr/bin/script.sh
  172. Slice=testslice.slice
  173. [Install]
  174. WantedBy=multi-user.target
  175. </div></div></code></pre>
  176. </li>
  177. <li>
  178. <p><span>Reload the daemon and restart the service to apply the changes</span></p>
  179. <pre><code>$ sudo systemctl daemon-reload
  180. $ sudo systemctl restart shellscript.service
  181. </code></pre>
  182. </li>
  183. <li>
  184. <p><span>Refresh the web page. The output shows that </span><code>dd</code><span> now uses less than 10% of the CPU.</span><br>
  185. <img src="https://i.imgur.com/SQ5xb0b.jpg" alt="" loading="lazy"></p>
  186. </li>
  187. <li>
  188. <p><span>Run </span><code>$ systemd-cgtop</code><span> to view resource usage by cgroups.</span></p>
  189. <pre><code>Control Group Tasks %CPU Memory Input/s Output/s
  190. / 774 13,9 1.7G - -
  191. testslice.slice 2 9,9 956.0K - -
  192. testslice.slice/shellscript.service 2 9,9 576.0K - -
  193. user.slice 489 3,1 1.5G - -
  194. user.slice/user-1000.slice 489 3,4 1.3G - -
  195. </code></pre>
  196. </li>
  197. <li>
  198. <p><span>View the hierarchy and other artifacts about the cgroup.</span></p>
  199. <pre><code>$ systemctl -t slice --all
  200. $ systemctl status
  201. </code></pre>
  202. </li>
  203. <li>
  204. <p><span>View systemd log for your service</span></p>
  205. <pre><code>$ journalctl -u shellscript.service
  206. </code></pre>
  207. </li>
  208. </ul><h2 id="Questions-to-answer" data-id="Questions-to-answer"><a class="anchor hidden-xs" href="#Questions-to-answer" title="Questions-to-answer"><span class="octicon octicon-link"></span></a><span>Questions to answer</span></h2><blockquote>
  209. <p><span>Upload the scripts you create to moodle.</span><br>
  210. <span>Show test results of your implementation in your report.</span></p>
  211. </blockquote><ol>
  212. <li>
  213. <p><span>Show the following boot-up performance statistics on your system:</span></p>
  214. <ul>
  215. <li><span>Time spent in the kernel space before the user space was reached.</span></li>
  216. <li><span>Show an SVG image that contains services that have been started, and how long it took for them to initialize.</span></li>
  217. </ul>
  218. </li>
  219. <li>
  220. <p><span>Take the systemd unit </span><code>graphical.target</code><span> as your starting point, start tracing backwards using only the </span><code>Requires</code><span> variable. At what systemd unit do you reach a dead end where there is no more </span><code>Requires</code><span> variable?</span></p>
  221. <ul>
  222. <li><span>Provide brief explanation for each of the systemd units you encounter while performing this trace.</span></li>
  223. <li><span>The unit at this dead end </span><code>Wants</code><span> some systemd units. Why does it want these units?</span></li>
  224. </ul>
  225. <blockquote>
  226. <p><span>Show screenshots of every step as you trace.</span></p>
  227. </blockquote>
  228. </li>
  229. <li>
  230. <p><span>Create a simple web server in bash that shows the following: system uptime, inode usage, current memory, disk space usage statistics, and the last 15 lines of </span><code>/var/log/syslog</code><span>.</span></p>
  231. <ul>
  232. <li><span>The required information should be queried from the server everytime a user opens or refreshes the page.</span></li>
  233. <li><span>You do not need to save the results anywhere. Users only need live updates when the server is visited.</span></li>
  234. <li><span>The results should be displayed on a single page in an orderly manner that is easy to read.</span></li>
  235. <li><span>Create a systemd service on your system to run this script (web server). Show how you can start your new service, and configure it to run after system reboot.</span></li>
  236. <li><span>Your systemd service should restart the web server if the web server crashes or is killed.</span></li>
  237. <li><span>This service is allowed to use a maximum of 15% of the CPU and 256MB memory.</span></li>
  238. </ul>
  239. <blockquote>
  240. <p><span>Show all steps taken, and all unit files created in your report.</span><br>
  241. <span>At the end of this task, you must have at least one bash script, one service file, and one slice file all working together to achieve the objectives.</span></p>
  242. </blockquote>
  243. </li>
  244. <li>
  245. <p><span>Create a systemd service that will update your package sources list from the repository.</span></p>
  246. <ul>
  247. <li><span>The service should update the package source list five minutes after booting, and then every day after that.</span></li>
  248. <li><span>The schedule of the execution should be done with only systemd.</span></li>
  249. </ul>
  250. </li>
  251. </ol><h3 id="Bonus" data-id="Bonus"><a class="anchor hidden-xs" href="#Bonus" title="Bonus"><span class="octicon octicon-link"></span></a><span>Bonus</span></h3><ol start="5">
  252. <li><span>Create a custom target in </span><code>/etc/systemd/system/&lt;your_target&gt;.target</code><span>.</span>
  253. <ul>
  254. <li><span>Add a description of the target file.</span></li>
  255. <li><span>Create a directory </span><code>/etc/systemd/system/&lt;your_target&gt;.wants/</code></li>
  256. <li><span>Create sylinks to additional services you wish to enable in this new directory. It should be a symlink to services from </span><code>/usr/lib/systemd/system/</code><span> that you wish to enable.</span></li>
  257. </ul>
  258. </li>
  259. </ol></div>
  260. <div class="ui-toc dropup unselectable hidden-print" style="display:none;">
  261. <div class="pull-right dropdown">
  262. <a id="tocLabel" class="ui-toc-label btn btn-default" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="Table of content">
  263. <i class="fa fa-bars"></i>
  264. </a>
  265. <ul id="ui-toc" class="ui-toc-dropdown dropdown-menu" aria-labelledby="tocLabel">
  266. <div class="toc"><ul class="nav">
  267. <li class=""><a href="#Lab-8-Systemd" title="Lab 8: Systemd">Lab 8: Systemd</a><ul class="nav">
  268. <li class=""><a href="#Task-1-Create-a-shell-script" title="Task 1: Create a shell script">Task 1: Create a shell script</a></li>
  269. <li class=""><a href="#Task-2-Create-a-systemd-file" title="Task 2: Create a systemd file">Task 2: Create a systemd file</a></li>
  270. <li class=""><a href="#Task-3-Enable-the-service" title="Task 3: Enable the service">Task 3: Enable the service</a></li>
  271. <li><a href="#Task-4-Systemd-control-groups-cgroups" title="Task 4: Systemd control groups (cgroups)">Task 4: Systemd control groups (cgroups)</a></li>
  272. <li><a href="#Questions-to-answer" title="Questions to answer">Questions to answer</a><ul class="nav">
  273. <li><a href="#Bonus" title="Bonus">Bonus</a></li>
  274. </ul>
  275. </li>
  276. </ul>
  277. </li>
  278. </ul>
  279. </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div>
  280. </ul>
  281. </div>
  282. </div>
  283. <div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:17px;display:none;" null null>
  284. <div class="toc"><ul class="nav">
  285. <li class=""><a href="#Lab-8-Systemd" title="Lab 8: Systemd">Lab 8: Systemd</a><ul class="nav">
  286. <li class=""><a href="#Task-1-Create-a-shell-script" title="Task 1: Create a shell script">Task 1: Create a shell script</a></li>
  287. <li class=""><a href="#Task-2-Create-a-systemd-file" title="Task 2: Create a systemd file">Task 2: Create a systemd file</a></li>
  288. <li class=""><a href="#Task-3-Enable-the-service" title="Task 3: Enable the service">Task 3: Enable the service</a></li>
  289. <li><a href="#Task-4-Systemd-control-groups-cgroups" title="Task 4: Systemd control groups (cgroups)">Task 4: Systemd control groups (cgroups)</a></li>
  290. <li><a href="#Questions-to-answer" title="Questions to answer">Questions to answer</a><ul class="nav">
  291. <li><a href="#Bonus" title="Bonus">Bonus</a></li>
  292. </ul>
  293. </li>
  294. </ul>
  295. </li>
  296. </ul>
  297. </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div>
  298. </div>
  299. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
  300. <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous" defer></script>
  301. <script src="https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.6.0/gist-embed.min.js" integrity="sha256-KyF2D6xPIJUW5sUDSs93vWyZm+1RzIpKCexxElmxl8g=" crossorigin="anonymous" defer></script>
  302. <script>
  303. var markdown = $(".markdown-body");
  304. //smooth all hash trigger scrolling
  305. function smoothHashScroll() {
  306. var hashElements = $("a[href^='#']").toArray();
  307. for (var i = 0; i < hashElements.length; i++) {
  308. var element = hashElements[i];
  309. var $element = $(element);
  310. var hash = element.hash;
  311. if (hash) {
  312. $element.on('click', function (e) {
  313. // store hash
  314. var hash = this.hash;
  315. if ($(hash).length <= 0) return;
  316. // prevent default anchor click behavior
  317. e.preventDefault();
  318. // animate
  319. $('body, html').stop(true, true).animate({
  320. scrollTop: $(hash).offset().top
  321. }, 100, "linear", function () {
  322. // when done, add hash to url
  323. // (default click behaviour)
  324. window.location.hash = hash;
  325. });
  326. });
  327. }
  328. }
  329. }
  330. smoothHashScroll();
  331. var toc = $('.ui-toc');
  332. var tocAffix = $('.ui-affix-toc');
  333. var tocDropdown = $('.ui-toc-dropdown');
  334. //toc
  335. tocDropdown.click(function (e) {
  336. e.stopPropagation();
  337. });
  338. var enoughForAffixToc = true;
  339. function generateScrollspy() {
  340. $(document.body).scrollspy({
  341. target: ''
  342. });
  343. $(document.body).scrollspy('refresh');
  344. if (enoughForAffixToc) {
  345. toc.hide();
  346. tocAffix.show();
  347. } else {
  348. tocAffix.hide();
  349. toc.show();
  350. }
  351. $(document.body).scroll();
  352. }
  353. function windowResize() {
  354. //toc right
  355. var paddingRight = parseFloat(markdown.css('padding-right'));
  356. var right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
  357. toc.css('right', right + 'px');
  358. //affix toc left
  359. var newbool;
  360. var rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
  361. //for ipad or wider device
  362. if (rightMargin >= 133) {
  363. newbool = true;
  364. var affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
  365. var left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
  366. tocAffix.css('left', left + 'px');
  367. } else {
  368. newbool = false;
  369. }
  370. if (newbool != enoughForAffixToc) {
  371. enoughForAffixToc = newbool;
  372. generateScrollspy();
  373. }
  374. }
  375. $(window).resize(function () {
  376. windowResize();
  377. });
  378. $(document).ready(function () {
  379. windowResize();
  380. generateScrollspy();
  381. });
  382. //remove hash
  383. function removeHash() {
  384. window.location.hash = '';
  385. }
  386. var backtotop = $('.back-to-top');
  387. var gotobottom = $('.go-to-bottom');
  388. backtotop.click(function (e) {
  389. e.preventDefault();
  390. e.stopPropagation();
  391. if (scrollToTop)
  392. scrollToTop();
  393. removeHash();
  394. });
  395. gotobottom.click(function (e) {
  396. e.preventDefault();
  397. e.stopPropagation();
  398. if (scrollToBottom)
  399. scrollToBottom();
  400. removeHash();
  401. });
  402. var toggle = $('.expand-toggle');
  403. var tocExpand = false;
  404. checkExpandToggle();
  405. toggle.click(function (e) {
  406. e.preventDefault();
  407. e.stopPropagation();
  408. tocExpand = !tocExpand;
  409. checkExpandToggle();
  410. })
  411. function checkExpandToggle () {
  412. var toc = $('.ui-toc-dropdown .toc');
  413. var toggle = $('.expand-toggle');
  414. if (!tocExpand) {
  415. toc.removeClass('expand');
  416. toggle.text('Expand all');
  417. } else {
  418. toc.addClass('expand');
  419. toggle.text('Collapse all');
  420. }
  421. }
  422. function scrollToTop() {
  423. $('body, html').stop(true, true).animate({
  424. scrollTop: 0
  425. }, 100, "linear");
  426. }
  427. function scrollToBottom() {
  428. $('body, html').stop(true, true).animate({
  429. scrollTop: $(document.body)[0].scrollHeight
  430. }, 100, "linear");
  431. }
  432. </script>
  433. </body>
  434. </html>