How to set a binary to init on boot like Apache does (run as a service)

pthurmond asked:

I am trying to setup PhantomJS to run as a service. I found the skeleton file in /etc/init.d and I am running on Ubuntu 12.10. In trying to figure this out I found the symlinks in the /etc/rc*.d directories and found that Apache runs at run levels 2 through 5.

My question is do I just created a symlink called S02phantomjs in the 2 through 5 folders and point it to the script I put in /etc/init.d? Or should I use some application to configure this?

My concern is that I am missing something. And that the order in the number portion of that has a significant importance that I don’t want to mess with.

Also I am not sure if there is anything else I have to do to not only make sure this runs on every boot. But get it to start running now.

One last question. My script, based on skeleton, when I run it in terminal it just sits and waits like when I run PhantomJS normally. I would like to get it to just run in the background like Apache does. What do I have to do differently to accomplish this?

Thanks everybody!

My answer:

If the init script is already there and properly written, it should suffice to enable it normally like any other init script:

update-rc.d phantomjs defaults

or (12.04+)

update-rc.d phantomjs enable

(This is usually done by default when you install packages with apt-get and its cousins…)

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.