4

I need to put a startup script to my CentOS6 server.

I see that I need a script that contains start-stop cases. But I have a problem to make it and neither how to put this script to startup.

Anyone can say me how can I add it?

The script must run a simply command that run a jar file:

java -jar FileName.jar
Danny Beckett
  • 20,529
  • 24
  • 107
  • 134
Univers3
  • 935
  • 1
  • 13
  • 34

1 Answers1

12

The simplest way would be to add your command to the file

/etc/rc.d/rc.local

Commands in the above file are run at startup (as root). Note that if you do this, your command will NOT respond to the usual service start/ stop commands.

chue x
  • 18,573
  • 7
  • 56
  • 70
  • Perfect! this is what i need. But i have a question. The script is blocking (if i start it from console, this will be blocked until the END of the program, never) I must put a command with nohup? like: `nohup java -jar FileName.jar &` – Univers3 Feb 22 '13 at 22:34
  • @Univers3 - hmmm... I've never really used `nohup` so I can't comment on it. But if it is blocking, I would definitely try the `&` at the end. – chue x Feb 22 '13 at 22:49
  • How do you stop a command run like this? It doesn't seem to show up when running 'ps' – B T Feb 20 '14 at 01:30
  • 1
    @BT did you try `ps -A` ? – chue x Feb 20 '14 at 01:37
  • i did now, tho it can be a little hard to figure out which process it is. Thanks! – B T Feb 20 '14 at 02:23
  • I have program called 'icecast' and i have green file executable i guess, how do i add it to services to start with system without this old-fashion method you mentioned? – Luka Jan 07 '17 at 18:27