{"id":1261,"date":"2021-02-22T19:00:49","date_gmt":"2021-02-22T19:00:49","guid":{"rendered":"https:\/\/dft.wiki\/?p=1261"},"modified":"2021-02-22T19:00:49","modified_gmt":"2021-02-22T19:00:49","slug":"creating-a-service-for-rc-local-to-run-script-on-startup-boot","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=1261","title":{"rendered":"Creating a Service for &#8220;rc.local&#8221; to Run Script on Startup (Boot)"},"content":{"rendered":"<p>There are some ways to run a script, application, or command when the system loads.<\/p>\n<p>The easiest way is to add the following line to the crontab:<\/p>\n<pre>crontab -e\r\n\r\n   <strong>@reboot \/path\/script.sh<\/strong>\r\n\r\nOR\r\n\r\n   <strong>@reboot user \/path\/script.sh<\/strong><\/pre>\n<p>For some reason, it does not always work. It depends on the distribution and version of the system.<\/p>\n<p>On some systems you can create a script and place it at \/etc\/init.d\/ as executable. Give it a try!<\/p>\n<p>A popular way was to insert the execution commands in \/etc\/rc.local but it disappeared in some distributions. So, let&#8217;s recreate it!<\/p>\n<pre>printf '%s\\n' '#!\/bin\/bash' 'exit 0' | sudo tee -a \/etc\/rc.local\r\nsudo chmod +x \/etc\/rc.local\r\nsudo nano \/etc\/systemd\/system\/rc-local.service<\/pre>\n<p>Add this content:<\/p>\n<pre>[Unit]\r\n Description=\/etc\/rc.local Compatibility\r\n ConditionPathExists=\/etc\/rc.local\r\n\r\n[Service]\r\n Type=forking\r\n ExecStart=\/etc\/rc.local start\r\n TimeoutSec=0\r\n StandardOutput=tty\r\n RemainAfterExit=yes\r\n SysVStartPriority=99\r\n\r\n[Install]\r\n WantedBy=multi-user.target<\/pre>\n<p>Now enable the service to run when the system loads:<\/p>\n<pre>sudo systemctl enable rc-local<\/pre>\n<p>Done!<\/p>\n<p>Edit the file \/etc\/rc.local and insert the commands you want to be executed between the lines as shown:<\/p>\n<pre>#!\/bin\/bash\r\n   <strong>...write the commands here...<\/strong>\r\nexit 0<\/pre>\n<p>Reload the system to verify.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are some ways to run a script, application, or command when the system loads. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,6],"tags":[],"class_list":["post-1261","post","type-post","status-publish","format-standard","hentry","category-linux","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1261"}],"version-history":[{"count":3,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1261\/revisions"}],"predecessor-version":[{"id":1266,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/1261\/revisions\/1266"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}