In the framework of the study of java (first jap) I wrote a simple echo server with the client.

A friend gave access to the server running centos6 (first acquaintance with the nix (?) System).

After installing jre8, I was able to launch .jar for execution.

How to add a file to startup at system startup?

  • add the necessary command to the end of the /etc/rc.local file - aleksandr barakin
  • I have access only through the console - acdprd
  • 2
    so this is more than enough for absolutely full control of a computer with a unix-like operating system. in fact, using gui to fully manage is simply impossible. - aleksandr barakin
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

If you need to execute a command at the end of the operating system gnu / linux loading, then the easiest way to do this is to add this command at the end of the /etc/rc.local file.

but be careful: in some distributions the last line in this file is a string

 exit 0 

in this case, your team should be added above this very line.


the command will be executed as root . if you want it to be executed on behalf of some other user, you can use this, for example, construction:

 su -c "ваша команда" пользователь 
  • I don’t know whether it is worth noting that the “your command” should be the name of the bash shell script, which sets up the necessary environment and starts java to execute the jar file, and not just the name of the jar file. - Igor Kudryashov
  1. Create the file /etc/init.d/"filename" .
  2. We write in it:

     #!/bin/sh #chkconfig: 345 99 01 #description: some code to load on boot case "$1" in start) cd /root/myjavaserver/ /usr/bin/java -jar java.jar & ;; stop) killall -v java ;; esac exit 0 
  3. Making the file executable: chmod +x "filename" .

  4. Add to the service chkconfig --add "filename" .
  5. Everything has to earn.