{"id":705,"date":"2014-01-26T19:29:23","date_gmt":"2014-01-27T02:29:23","guid":{"rendered":"http:\/\/somethingk.com\/main\/?p=705"},"modified":"2014-02-09T09:52:25","modified_gmt":"2014-02-09T16:52:25","slug":"init-d-scripts","status":"publish","type":"post","link":"https:\/\/somethingk.com\/main\/init-d-scripts\/","title":{"rendered":"Init.d Scripts"},"content":{"rendered":"<p>I decided to make my own init.d script for my <a title=\"My Ultimate Network Monitor\/Enumeration Tool \u2013 Putting It All Together\" href=\"http:\/\/somethingk.com\/main\/?p=580\">lilDevil<\/a> app (instead of using a <a title=\"Linux: Running Scripts on Startup\" href=\"http:\/\/somethingk.com\/main\/?p=683\">startup cronjob<\/a>). The &#8220;init&#8221; in init.d stands for initialization and the &#8220;.d&#8221; indicates the script is a daemon process. A daemon process is commonly defined as simply something that runs in the background. So an init.d script, is one that is called on startup and runs in the background without any user controls.<\/p>\n<figure style=\"width: 480px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.jeremyblum.com\/wp-content\/uploads\/2012\/01\/startup-fair.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"  \" alt=\"\" src=\"http:\/\/www.jeremyblum.com\/wp-content\/uploads\/2012\/01\/startup-fair.jpg\" width=\"480\" height=\"240\" \/><\/a><figcaption class=\"wp-caption-text\">And by startup I mean apps that run on Startup \ud83d\ude09<\/figcaption><\/figure>\n<p><strong>Setup<\/strong><\/p>\n<p>Making an init.d script is simple. First create the script in the init.d directory.<\/p>\n<pre>vim \/etc\/init.d\/&lt;NAME OF YOUR STARTUP SERVICE&gt;<\/pre>\n<p>Next, add executive privileges to the script.<\/p>\n<pre>chmod +x\u00a0\/etc\/init.d\/&lt;NAME OF YOUR STARTUP SERVICE&gt;<\/pre>\n<p>Now it&#8217;s time for the inner-workings.<\/p>\n<p><strong>Script Parts<\/strong><\/p>\n<p>This is ultimately a bash script so it requires this little sh-bang at the top.<\/p>\n<pre>#!\/bin\/bash<\/pre>\n<p>Next, a service requires a LSB header. This header is used to configure startup settings and describe the service. This <a title=\"LSBInitScripts\" href=\"https:\/\/wiki.debian.org\/LSBInitScripts\" target=\"_blank\">tutorial<\/a> goes into detail on the different available settings that can be included in the header. Below is a sample of a more basic header that will add a service to the end of the startup boot order sequence.<\/p>\n<pre>### BEGIN INIT INFO\r\n# Provides:\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;SERVICE NAME&gt;\r\n# Required-Start:\u00a0 \u00a0 $all\r\n# Required-Stop: \u00a0 \u00a0 $all\r\n# Default-Start: \u00a0 \u00a0 S\r\n# Default-Stop:\u00a0 \u00a0 \u00a0 0 1 6\r\n# Short-Description: &lt;LONG DESCRIPTION OF SERVICE&gt;\r\n# Description:<\/pre>\n<pre>&lt;SHORT DESCRIPTION OF SERVICE&gt;<\/pre>\n<pre>### END INIT INFO<\/pre>\n<p>The following code describes the different service actions. For instance, common actions are &#8220;start&#8221;, &#8220;stop&#8221;, &#8220;restart&#8221;, etc.<\/p>\n<pre>case \"$1\" in\r\n&lt;ACTION1&gt;)\r\n\r\n&lt;COMMANDS\/SCRIPTS TO RUN RELATING TO ACTION1&gt;\r\n;;\r\n&lt;ACTION2&gt;)<\/pre>\n<pre>&lt;COMMANDS\/SCRIPTS TO RUN RELATING TO ACTION2&gt;\r\n ;;\r\n\r\n&lt;REPEAT AS NECESSARY&gt;<\/pre>\n<p>Concluding, we exit and clean everything up.<\/p>\n<pre>exit 1\r\nesac\r\nexit 0<\/pre>\n<p><strong>Putting it All Together<\/strong><\/p>\n<p>To help you see the big picture, here is a copy of my init.d script.<\/p>\n<pre>#!\/bin\/bash\r\n#<\/pre>\n<pre>### BEGIN INIT INFO\r\n# Provides:\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 lilDevil\r\n# Required-Start:\u00a0 \u00a0 $all\r\n# Required-Stop: \u00a0 \u00a0 $all\r\n# Default-Start: \u00a0 \u00a0 S\r\n# Default-Stop:\u00a0 \u00a0 \u00a0 0 1 6\r\n# Short-Description: Unleash the lilDevil\r\n# Description: \u00a0 \u00a0 \u00a0 lilDevil is an awesome network enumeration tool\r\n### END INIT INFO\u00a0\r\n#<\/pre>\n<pre>case \"$1\" in\r\nstart)\r\necho \"Starting lilDevil \"\r\npython \/root\/Projects\/dirtBag.py&amp;\r\npython \/root\/Projects\/demon\/manage.py flush --noinput\r\npython \/root\/Projects\/demon\/manage.py runserver 192.168.1.6:3707&amp;\r\npython \/root\/Projects\/sensor.py&amp;\r\n;;\r\nstop)\r\necho \"Stopping lilDevil \"\r\nkillall -9 python\r\n;;\r\nrestart)\r\necho \"Restarting lilDevil \"\r\nkillall -9 python\r\npython \/root\/Projects\/dirtBag.py&amp;\r\npython \/root\/Projects\/demon\/manage.py flush --noinput\r\npython \/root\/Projects\/demon\/manage.py runserver 192.168.1.6:3707&amp;\r\npython \/root\/Projects\/sensor.py&amp;\r\n;;\r\n*)\r\necho \"Service\"\r\necho $\"Usage: $0 {start|stop|status}\"\r\nexit 1\r\nesac\r\nexit 0<\/pre>\n<p><strong>Configuring it to Run<\/strong><\/p>\n<p>With the script completed, we pass it to insserv to be added to the Linux service boot order.<\/p>\n<pre>insserv -d \/etc\/init.d\/lilDevil<\/pre>\n<p>Tah Dah! The service is added!<\/p>\n<p><strong>What about apps with GUIs?<\/strong><\/p>\n<p>Now, if your app has a GUI involved, it needs to be added to the desktop environment initialization. This is different from an init.d script. Init scripts run for the most part before the desktop has been initialized.<\/p>\n<p>In Kali, I simply used their tool to add the service to startup. The tool can be found under <strong>Application Menu-&gt;Settings-&gt;Session and Startup<\/strong>. Under the Application Autostart tab, you can add a new command to run when the desktop loads.<\/p>\n<p><a href=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-26-at-12.21.58-PM.png\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-710\" alt=\"Screen Shot 2014-01-26 at 12.21.58 PM\" src=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-26-at-12.21.58-PM-300x221.png\" width=\"300\" height=\"221\" srcset=\"https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-26-at-12.21.58-PM-300x221.png 300w, https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/Screen-Shot-2014-01-26-at-12.21.58-PM.png 1015w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>That&#8217;s it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided to make my own init.d script for my lilDevil app (instead of using a startup cronjob). The &#8220;init&#8221; in init.d stands for initialization and the &#8220;.d&#8221; indicates the script is a daemon process. A daemon process is commonly defined as simply something that runs in the background. So an init.d script, is one that is called on startup [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[174,173,176,172,175,165,171,164],"class_list":["post-705","post","type-post","status-publish","format-standard","hentry","category-linux","tag-boot","tag-create","tag-desktop-environment","tag-init-d","tag-run-on-startup","tag-scripts","tag-service","tag-startup"],"_links":{"self":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/comments?post=705"}],"version-history":[{"count":13,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/705\/revisions"}],"predecessor-version":[{"id":802,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/705\/revisions\/802"}],"wp:attachment":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/media?parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/categories?post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/tags?post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}