How to run a .jar application as a service (Start on boot of system)
Ok I'll make this quick. I'm developing a client-server app with an Ubuntu 17.04 server as the server. In that server is a jar containing all the server-side code.
The code just binds some sockets and continuously listen for client requests and makes threads for each request.
The problem is, that I can't get the .jar to startup on system boot. I check this by checking for open ports and none of the ports I coded in ever listen on boot up.
I've tried the following
Startup Applications - didn't work
Systemd - the .sh script works perfectly when I run it nornally, .jar runs and the ports open, but when booting up nothing happens. Using sudo service bla bla bla start
also runs the app perfectly. It just won't work on boot up
The target specified is graphical.target
and the unit starts AFTER mysql.service
Using init.d - jack shit happens
I'm at my wits end on what to do. Please help, thanks.
systemd
add a comment |
Ok I'll make this quick. I'm developing a client-server app with an Ubuntu 17.04 server as the server. In that server is a jar containing all the server-side code.
The code just binds some sockets and continuously listen for client requests and makes threads for each request.
The problem is, that I can't get the .jar to startup on system boot. I check this by checking for open ports and none of the ports I coded in ever listen on boot up.
I've tried the following
Startup Applications - didn't work
Systemd - the .sh script works perfectly when I run it nornally, .jar runs and the ports open, but when booting up nothing happens. Using sudo service bla bla bla start
also runs the app perfectly. It just won't work on boot up
The target specified is graphical.target
and the unit starts AFTER mysql.service
Using init.d - jack shit happens
I'm at my wits end on what to do. Please help, thanks.
systemd
Show us how your systemd service looked like.
– Ziazis
Aug 18 '17 at 6:18
add a comment |
Ok I'll make this quick. I'm developing a client-server app with an Ubuntu 17.04 server as the server. In that server is a jar containing all the server-side code.
The code just binds some sockets and continuously listen for client requests and makes threads for each request.
The problem is, that I can't get the .jar to startup on system boot. I check this by checking for open ports and none of the ports I coded in ever listen on boot up.
I've tried the following
Startup Applications - didn't work
Systemd - the .sh script works perfectly when I run it nornally, .jar runs and the ports open, but when booting up nothing happens. Using sudo service bla bla bla start
also runs the app perfectly. It just won't work on boot up
The target specified is graphical.target
and the unit starts AFTER mysql.service
Using init.d - jack shit happens
I'm at my wits end on what to do. Please help, thanks.
systemd
Ok I'll make this quick. I'm developing a client-server app with an Ubuntu 17.04 server as the server. In that server is a jar containing all the server-side code.
The code just binds some sockets and continuously listen for client requests and makes threads for each request.
The problem is, that I can't get the .jar to startup on system boot. I check this by checking for open ports and none of the ports I coded in ever listen on boot up.
I've tried the following
Startup Applications - didn't work
Systemd - the .sh script works perfectly when I run it nornally, .jar runs and the ports open, but when booting up nothing happens. Using sudo service bla bla bla start
also runs the app perfectly. It just won't work on boot up
The target specified is graphical.target
and the unit starts AFTER mysql.service
Using init.d - jack shit happens
I'm at my wits end on what to do. Please help, thanks.
systemd
systemd
asked Aug 18 '17 at 6:11
user4442318user4442318
612
612
Show us how your systemd service looked like.
– Ziazis
Aug 18 '17 at 6:18
add a comment |
Show us how your systemd service looked like.
– Ziazis
Aug 18 '17 at 6:18
Show us how your systemd service looked like.
– Ziazis
Aug 18 '17 at 6:18
Show us how your systemd service looked like.
– Ziazis
Aug 18 '17 at 6:18
add a comment |
2 Answers
2
active
oldest
votes
i) Create your bash script called mystartup.sh to run the .jar file in /etc/init.d/ directory(login as root)
# vi /etc/init.d/mystartup.sh
ii) Add commands to this script one by one:
#!/bin/bash
echo “Setting up customized environment…”
fortune
iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh
iv)Make sure this script get executed every time Debian Linux system boot up/comes up:
# update-rc.d mystartup.sh defaults 100
To read more follow this link
add a comment |
A simple way is provided by the upstart
package, after installing it just save the following script in etc/init/onshutdown.conf
:
# /etc/init/onshutdown.conf
start on starting rc RUNLEVEL=2
# execute single command
exec /bin/sh /path/to/mystartup.sh
# alternatively without an extra script
script
java -jar /path/to/jarfile.jar
# your commands here
end script
Replace 2
with your preferred runlevel(s) (e. g. [2345]
). For more information about upstart
see man 5 init and the upstart cookbook.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f947344%2fhow-to-run-a-jar-application-as-a-service-start-on-boot-of-system%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
i) Create your bash script called mystartup.sh to run the .jar file in /etc/init.d/ directory(login as root)
# vi /etc/init.d/mystartup.sh
ii) Add commands to this script one by one:
#!/bin/bash
echo “Setting up customized environment…”
fortune
iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh
iv)Make sure this script get executed every time Debian Linux system boot up/comes up:
# update-rc.d mystartup.sh defaults 100
To read more follow this link
add a comment |
i) Create your bash script called mystartup.sh to run the .jar file in /etc/init.d/ directory(login as root)
# vi /etc/init.d/mystartup.sh
ii) Add commands to this script one by one:
#!/bin/bash
echo “Setting up customized environment…”
fortune
iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh
iv)Make sure this script get executed every time Debian Linux system boot up/comes up:
# update-rc.d mystartup.sh defaults 100
To read more follow this link
add a comment |
i) Create your bash script called mystartup.sh to run the .jar file in /etc/init.d/ directory(login as root)
# vi /etc/init.d/mystartup.sh
ii) Add commands to this script one by one:
#!/bin/bash
echo “Setting up customized environment…”
fortune
iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh
iv)Make sure this script get executed every time Debian Linux system boot up/comes up:
# update-rc.d mystartup.sh defaults 100
To read more follow this link
i) Create your bash script called mystartup.sh to run the .jar file in /etc/init.d/ directory(login as root)
# vi /etc/init.d/mystartup.sh
ii) Add commands to this script one by one:
#!/bin/bash
echo “Setting up customized environment…”
fortune
iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh
iv)Make sure this script get executed every time Debian Linux system boot up/comes up:
# update-rc.d mystartup.sh defaults 100
To read more follow this link
answered Aug 18 '17 at 6:23
fireball.1fireball.1
1118
1118
add a comment |
add a comment |
A simple way is provided by the upstart
package, after installing it just save the following script in etc/init/onshutdown.conf
:
# /etc/init/onshutdown.conf
start on starting rc RUNLEVEL=2
# execute single command
exec /bin/sh /path/to/mystartup.sh
# alternatively without an extra script
script
java -jar /path/to/jarfile.jar
# your commands here
end script
Replace 2
with your preferred runlevel(s) (e. g. [2345]
). For more information about upstart
see man 5 init and the upstart cookbook.
add a comment |
A simple way is provided by the upstart
package, after installing it just save the following script in etc/init/onshutdown.conf
:
# /etc/init/onshutdown.conf
start on starting rc RUNLEVEL=2
# execute single command
exec /bin/sh /path/to/mystartup.sh
# alternatively without an extra script
script
java -jar /path/to/jarfile.jar
# your commands here
end script
Replace 2
with your preferred runlevel(s) (e. g. [2345]
). For more information about upstart
see man 5 init and the upstart cookbook.
add a comment |
A simple way is provided by the upstart
package, after installing it just save the following script in etc/init/onshutdown.conf
:
# /etc/init/onshutdown.conf
start on starting rc RUNLEVEL=2
# execute single command
exec /bin/sh /path/to/mystartup.sh
# alternatively without an extra script
script
java -jar /path/to/jarfile.jar
# your commands here
end script
Replace 2
with your preferred runlevel(s) (e. g. [2345]
). For more information about upstart
see man 5 init and the upstart cookbook.
A simple way is provided by the upstart
package, after installing it just save the following script in etc/init/onshutdown.conf
:
# /etc/init/onshutdown.conf
start on starting rc RUNLEVEL=2
# execute single command
exec /bin/sh /path/to/mystartup.sh
# alternatively without an extra script
script
java -jar /path/to/jarfile.jar
# your commands here
end script
Replace 2
with your preferred runlevel(s) (e. g. [2345]
). For more information about upstart
see man 5 init and the upstart cookbook.
edited Aug 18 '17 at 7:05
answered Aug 18 '17 at 6:28
dessertdessert
24.9k672105
24.9k672105
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f947344%2fhow-to-run-a-jar-application-as-a-service-start-on-boot-of-system%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Show us how your systemd service looked like.
– Ziazis
Aug 18 '17 at 6:18