{"id":15477,"date":"2020-10-22T03:55:33","date_gmt":"2020-10-22T01:55:33","guid":{"rendered":"http:\/\/blog.wenzlaff.de\/?p=15477"},"modified":"2020-10-21T18:10:45","modified_gmt":"2020-10-21T16:10:45","slug":"autostart-systemd-zum-script-starten-als-service-mit-systemctl-am-beispiel-der-co2ampel","status":"publish","type":"post","link":"http:\/\/blog.wenzlaff.de\/?p=15477","title":{"rendered":"Autostart: systemd zum script starten als service mit systemctl am Beispiel der co2ampel"},"content":{"rendered":"<p>Wie k\u00f6nnen bash Scripte auf dem Raspberry Pi automatisch nach dem reboot gestartet werden?<br \/>\n<a href=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel.jpg\" alt=\"\" width=\"2048\" height=\"2048\" class=\"aligncenter size-full wp-image-15483\" srcset=\"http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel.jpg 2048w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel-300x300.jpg 300w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel-1024x1024.jpg 1024w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel-150x150.jpg 150w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel-768x768.jpg 768w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel-1536x1536.jpg 1536w, http:\/\/blog.wenzlaff.de\/wp-content\/uploads\/2020\/10\/CO2-Ampel-100x100.jpg 100w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/a><br \/>\nMit einem Service systemctl. Was ist n\u00f6tig? Nicht viel &#8230;<\/p>\n<p>1. Erstellen einer Datei: <!--more--><\/p>\n<p><strong>\/lib\/systemd\/system\/co2ampel.service <\/strong><\/p>\n<p>mit Inhalt<\/p>\n<pre class=\"lang:default decode:true \" >\r\n\r\n[Unit]\r\nDescription=CO2Ampel Service\r\nAfter=multi-user.target\r\n\r\n[Service]\r\nExecStart=\/home\/pi\/twco2ampel\/src\/main\/scripts\/send-co2-per-mqtt.sh &\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n\r\n<\/pre>\n<p>2. Dann ausf\u00fchrbar machen:<\/p>\n<p><strong>sudo chmod 644 \/lib\/systemd\/system\/co2ampel.service<\/strong><\/p>\n<p>Service kann nun gestartet werden mit:<\/p>\n<p><strong>sudo systemctl start co2ampel<\/strong><\/p>\n<p>Status abfragen:<\/p>\n<p><strong>sudo systemctl status co2ampel<\/strong><\/p>\n<p>Stoppen:<\/p>\n<p><strong>sudo systemctl stop co2ampel<\/strong><\/p>\n<p>Oder restart:<\/p>\n<p><strong>sudo systemctl restart co2ampel<\/strong><\/p>\n<p>3. Damit der Service beim <strong>rebooten<\/strong> gestartet wird ein<\/p>\n<p><strong>sudo systemctl enable co2ampel<\/strong><\/p>\n<p>4. Das system reloaden:<\/p>\n<p><strong>sudo systemctl daemon-reload<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>systemctl<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[220,4084,2173,808,1023,2752,3388],"tags":[527,4057,1397,1267,1067,4094,4093],"class_list":["post-15477","post","type-post","status-publish","format-standard","hentry","category-anleitung","category-co2","category-debian","category-linux-2","category-raspberry-pi","category-raspberry-pi-zero-w","category-script","tag-co2","tag-co2ampel","tag-script","tag-service","tag-starten","tag-systemctl","tag-systemd"],"_links":{"self":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/15477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=15477"}],"version-history":[{"count":0,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=\/wp\/v2\/posts\/15477\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=15477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=15477"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.wenzlaff.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=15477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}