# Init Script Installer

**URL:** <https://www.ruby-forum.com/t/init-script-installer/54687>\
**Category:** Ruby\
**Created:** [March 13, 2006, 3:37am UTC](https://www.ruby-forum.com/t/init-script-installer/54687 "2006-03-13T03:37:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zdennis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d78d45/32.png) [@zdennis](https://www.ruby-forum.com/u/zdennis)\
**Post date:** [March 13, 2006, 3:37am UTC](https://www.ruby-forum.com/t/init-script-installer/54687/1 "2006-03-13T03:37:36Z")

</div>

I’ve got a few scripts which need to run as system daemons. For a while  
it worked to just manually start them, but it soon became annoying, so I  
wrote a little script to create and install the init scripts for me.

Here’s what it does… it takes a template init script (similar to  
/etc/init.d/skeleton) and updates it according to passed in arguments,  
and then installs the script into /etc/init.d/

That’s it… now, i just run /etc/init.d/myservice start|restart|stop

any/all feedback would be great! Thanks,

Zach

p.s. - this will only work on \*nix-like systems which use systemv style  
init scripts

---

<div class="post-metadata">

**Author:** ![zdennis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d78d45/32.png) [@zdennis](https://www.ruby-forum.com/u/zdennis)\
**Post date:** [March 13, 2006, 4:52pm UTC](https://www.ruby-forum.com/t/init-script-installer/54687/2 "2006-03-13T16:52:47Z")

</div>

Checking for feedback this morning on this thread I see that my post  
doesn’t make a whole lot sense. Perhaps a rephrase will help  
it out, as mentionend previously I wrote an init script installer.  
Currently you run it like:  
ruby install\_init\_script.rb myscriptname  
/path/to/where/script/should/be/run

This will create an /etc/init.d script which which utilizes the  
start-stop-daemon (i am on a debian system). It will handle  
forking your program for you and it will run it in the background as a  
system daemon.

Right now that is all it does. I would like to have it wrap the script  
itself in code that generates the pid file for the user and  
handles removing it etc… I am thinking of doing something like:

init\_script\_install( scriptname, path2scriptdir ) do |script,  
rootdir|  
ensure\_script\_exists rootdir + ‘/’ + script  
create\_and\_install :initscript, :script=\>script,  
:rootdir=\>rootdir, :to =\> ‘/etc/init.d/’  
create\_and\_install :scriptwrapper, :script=\>script  
end

Where the first ‘create\_and\_install :initscript’ creates the init  
script, and the second part creates a wrapper for it which  
handles the creation and removal of the pid file. For the wrapper I  
think I need to either rename the original script, and put my  
wrapper in it’s place, then have my wrapper require the renamed script,  
or I need to modify the contents of the script itself.

Anyone have any ideas or thoughts on this? I’m not looking for code,  
just input and opinions. I would like to get a decent base so  
I can expand this to handle other types of system init scripts ( I  
believe RH doesn’t use start-stop-daemon like debian does,  
etc… ) before I release on rubyforge. Thanks,

Zach

---

<div class="post-metadata">

**Author:** ![zdennis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d78d45/32.png) [@zdennis](https://www.ruby-forum.com/u/zdennis)\
**Post date:** [March 13, 2006, 6:16pm UTC](https://www.ruby-forum.com/t/init-script-installer/54687/3 "2006-03-13T18:16:08Z")

</div>

On Mar 13, 2006, at 7:51 AM, zdennis wrote:

> system daemon.  
> o =\> ‘/etc/init.d/’  
> Anyone have any ideas or thoughts on this? I’m not looking for  
> code, just input and opinions. I would like to get a decent base so  
> I can expand this to handle other types of system init scripts ( I  
> believe RH doesn’t use start-stop-daemon like debian does, etc… )  
> before I release on rubyforge. Thanks,
> 
> Zach

Zach-

```
I could use a script like this. i think its a good idea. Will you be

```

sharing the code? I can help test it for you if you want.

Cheers-  
-Ezra

---

<div class="post-metadata">

**Author:** ![zdennis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d78d45/32.png) [@zdennis](https://www.ruby-forum.com/u/zdennis)\
**Post date:** [March 13, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/init-script-installer/54687/4 "2006-03-13T19:51:05Z")

</div>

I’d also be happy to test this out.

---

<div class="post-metadata">

**Author:** ![zdennis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/d78d45/32.png) [@zdennis](https://www.ruby-forum.com/u/zdennis)\
**Post date:** [March 13, 2006, 7:17pm UTC](https://www.ruby-forum.com/t/init-script-installer/54687/5 "2006-03-13T19:17:29Z")

</div>

Ezra Z. wrote:

> Zach-
> 
> ```
> I could use a script like this. i think its a good idea. Will you be 
> 
> ```
> 
> sharing the code?

Absolutely. I just didn’t want to post anything _yet_ until I got some  
base capabilities put in.

> I can help test it for you if you want.

That would be great! After work I’ll get my code tested a little more  
and I’ll email you privately the code if that works for you.

Thanks Ezra,

Zach
