{"id":5056,"date":"2023-04-28T20:11:54","date_gmt":"2023-04-29T01:11:54","guid":{"rendered":"https:\/\/www.incredigeek.com\/home\/?p=5056"},"modified":"2023-04-28T20:11:54","modified_gmt":"2023-04-29T01:11:54","slug":"creating-a-simple-systemd-service-to-launch-shell-script-on-system-boot","status":"publish","type":"post","link":"https:\/\/www.incredigeek.com\/home\/creating-a-simple-systemd-service-to-launch-shell-script-on-system-boot\/","title":{"rendered":"Creating a Simple systemd Service to Launch Shell Script on System Boot"},"content":{"rendered":"\n<p>We will setup a simple systemd service to automatically run a bash script on system boot.  <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create systemd file<\/h2>\n\n\n\n<p>Create the service file with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">vi \/etc\/systemd\/system\/multi-user.target.wants\/bashscript.service<\/pre>\n\n\n\n<p>Now fill out the file.  Change the Description and ExecStart.  After= means only start this unit after the other units have finished.  This is needed if we need to make a network connection.  If our script runs before the network is up, the connection will fail.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\nDescription=systemd Unit File to Launch Bash Script on System Boot\nAfter=network.target\nAfter=syslog.target\n\n[Install]\nWantedBy=multi-user.target\n\n[Service]\nExecStart=\/home\/user\/script.sh\n<\/pre>\n\n\n\n<p>Change the ExecStart to your bash script and save the file<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enable systemd file<\/h2>\n\n\n\n<p>Now that the file is created, we need to enable the service so it starts on system boot <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl enable bashscript.service<\/pre>\n\n\n\n<p>You should get the following output.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Created symlink \/etc\/systemd\/system\/multi-user.target.wants\/bash.service \u2192 \/etc\/systemd\/system\/bash.service.<\/pre>\n\n\n\n<p>Now to test, reboot your system, or start the service with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">systemctl start bashscript.service<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We will setup a simple systemd service to automatically run a bash script on system boot. Create systemd file Create the service file with vi \/etc\/systemd\/system\/multi-user.target.wants\/bashscript.service Now fill out the file. Change the Description and ExecStart. After= means only start &hellip; <a href=\"https:\/\/www.incredigeek.com\/home\/creating-a-simple-systemd-service-to-launch-shell-script-on-system-boot\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[244,7,1485,1484,49],"class_list":["post-5056","post","type-post","status-publish","format-standard","hentry","category-linux","tag-automation","tag-linux-2","tag-start-on-system-boot","tag-syslogd","tag-ubuntu-2"],"_links":{"self":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/comments?post=5056"}],"version-history":[{"count":2,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5056\/revisions"}],"predecessor-version":[{"id":5058,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/posts\/5056\/revisions\/5058"}],"wp:attachment":[{"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/media?parent=5056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/categories?post=5056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.incredigeek.com\/home\/wp-json\/wp\/v2\/tags?post=5056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}