1

We’re looking to run an application as a Service/Deamon on a Linux box without manually logging in and starting it. The application is a Java one that we start with a shell (.sh).

Do you know how to run a process on a Linux distribution as a service/deamon without logging in, manually start and stopping ?

ic3
  • 7,917
  • 14
  • 67
  • 115

3 Answers3

2

Run a command on boot

You'd need to add the command that you would run, on /etc/rc.local.

Note: That path may be dependent on your distribution or init system, so check with the distributions documentation to make sure (ie it could be /etc/init.d/local or such).

One would typically

  • make that file executable -- chmod +x /etc/rc.local
  • and append/add in the contents the command that would run to start the application

    $ echo "sh myscript.sh &" >> /etc/rc.local # or just edit with your prefered editor
    

Again, depending on your distribution and init system, you may need to add the file as a service on the default runlevel (or the appropriate runlevel)

sudo update-rc.d local defaults 80  # ie for ubuntu

Look at this howto for Ubuntu, or look here for Archlinux, or here for Gentoo


Remote part ?

The remote part has lots of trouble. What do you mean by remote ? Is the machine that runs the daemon in a Lan ? do you trust your lan ? does it communicate to the Internet ? etc

I would probably set up ssh on that machine, and whenever needed, I would log in and start/stop the daemon. You'd only need to set up sshd (typically /etc/ssh/sshd_config) and add ssh to run on boot.
If the machine is on a local Lan, and you believe that logging in and manually starting/stopping the daemon is too boring and want something more automated, I would probably write up a bot that would parse the mailbox for a specific user and upon receival of "special" mail, it would start or stop or toggle the status of the daemon (note it must have the appropriate permissions). That sounds easy, but you need to trust your lan or be careful on how you parse the mail (mail spoofing etc).

c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48
  • Thanks a lot for all this info, the application has also a small web server so we can listen to a web/soap message (the app has authentication/authorization). How can an application restart itself is another question :-). – ic3 Jan 13 '12 at 14:13
  • By the way, why people are putting down the question and trying to close it ? – ic3 Jan 13 '12 at 14:14
1

Assumption I assume you mean how you would get a Java service to start and stop at different run levels.

Take a look at the Java Service Wrapper it is an application which has evolved out of a desire to solve a number of problems common to many Java applications. The features of Wrapper are as follows:

  • Run a Java application as a Windows Service or UNIX Daemon
  • Java Application Reliability
  • Standard, Out of the Box Scripting
  • On Demand Restarts
  • Flexible Configuration
  • Ease Application Installations
  • Logging

The above spiel is from the website but I have used it extensively and its excellent. I can't recommend it enough.

Paul Whelan
  • 16,574
  • 12
  • 50
  • 83
1

In addition to other answers, you might use a @reboot crontab(5) entry

On Debian or Ubuntu, you could create your own service script by copying /etc/init.d/skeleton into your /etc/init.d/iccubedaemon (and edit that file appropriately) then symlinking it as /etc/rc2.d/S99iccubedaemon etc...

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547