If you need to autostart a jar after your operative system has been rebooted using Centos 7/8, then you need to create a service, to do that go to /etc/systemd/system and create in there the name of the service you want to start your app, I gave in this example the service name as springboot.service
I am working with screen for the purpose of this example
before starting you need having screen installed, if you don't have it run yum install screen
so vim springboot.service and paste the next instructions in order to set up your service, replace the jar name and the WorkingDirectory by yours, the WorkingDirectory is usually where the jar is so that in most common cases in that directory is where your application.properties and other settings you've got
after you have created and save the service run:
systemctl daemon-reload with that command services are being updated and if there is a new one, it will automatically loaded by systemd
systemctl enable springboot.service this command is the one is going to create teh symlink in order to autostart it
systemctl start springboot.service it starts the service
systemctl status springboot.service it gives you the service status
now if you run screen -r -d you are going to be able to be reattached to the launched jar
you can run chance the user root by any other user and it is the best thing to do.
so now let's suppose you need to start a service only after the first jar has entered Active, let's name that service as springboot2.service
so the second service will be activated after the first service springboot.service
has started giving it 15 delay seconds, I am explaining this thing so that in my case the second jar needs from the first jar so that the first one is a service which provides some special data to the second jar, and if both of them started at the same time, the second jar could not start so that it depends from the first one to be up and running, and if you've got a kind of need like that just take this solution.
I am working with screen for the purpose of this example
before starting you need having screen installed, if you don't have it run yum install screen
so vim springboot.service and paste the next instructions in order to set up your service, replace the jar name and the WorkingDirectory by yours, the WorkingDirectory is usually where the jar is so that in most common cases in that directory is where your application.properties and other settings you've got
after you have created and save the service run:
systemctl daemon-reload with that command services are being updated and if there is a new one, it will automatically loaded by systemd
systemctl enable springboot.service this command is the one is going to create teh symlink in order to autostart it
systemctl start springboot.service it starts the service
systemctl status springboot.service it gives you the service status
now if you run screen -r -d you are going to be able to be reattached to the launched jar
you can run chance the user root by any other user and it is the best thing to do.
so now let's suppose you need to start a service only after the first jar has entered Active, let's name that service as springboot2.service
so the second service will be activated after the first service springboot.service
has started giving it 15 delay seconds, I am explaining this thing so that in my case the second jar needs from the first jar so that the first one is a service which provides some special data to the second jar, and if both of them started at the same time, the second jar could not start so that it depends from the first one to be up and running, and if you've got a kind of need like that just take this solution.
Comments
Post a Comment