Why does my systemd service shut down immediately after running?
up vote
1
down vote
favorite
I created a simple script to run four other commands. I have it located at /usr/local/bin/lbrystartup.sh, and it contains the following:
#!/bin/bash
#Start web scripts
screen -dmS main /var/www/html/main.sh
screen -dmS loop2 /var/www/html/loop2.sh
screen -dmS blocks /var/www/html/blocks.sh
screen -dmS lbry /var/stratum/run.sh lbry
When I run this script, it works fine. I end up with four screen instances in the list, and they're all running as necessary.
Next, I created a service for systemd to run on startup.
coinscripts.service looks like this:
[Unit]
Description = Coinscripts daemon
After network.target = auditd.service
[Service]
type=Simple
ExecStart =/usr/local/bin/lbrystartup.sh
[Install]
WantedBy = multi-user.target
I've enabled the service, and it's successful in doing so. However, when I run the service with "sudo systemctl start coinscripts", the screen instances don't open. But, when I use systemctl status coinscripts, I get the following:
● coinscripts.service - Coinscripts daemon Loaded: loaded (/etc/systemd/system/coinscripts.service; enabled; vendor pres
Active: inactive (dead) since Fri 2017-06-30 21:59:10 PDT; 1min 3s ago
Process: 1050 ExecStart=/usr/local/bin/lbrystartup.sh (code=exited,
status=0/S Main PID: 1050 (code=exited, status=0/SUCCESS)
Jun 30 21:59:10 ubuntu systemd[1]: Started Coinscripts daemon.
Same happens when I restart the machine.
What am I doing wrong with the service script? I'm using Ubuntu 16.04
scripts services systemd
add a comment |
up vote
1
down vote
favorite
I created a simple script to run four other commands. I have it located at /usr/local/bin/lbrystartup.sh, and it contains the following:
#!/bin/bash
#Start web scripts
screen -dmS main /var/www/html/main.sh
screen -dmS loop2 /var/www/html/loop2.sh
screen -dmS blocks /var/www/html/blocks.sh
screen -dmS lbry /var/stratum/run.sh lbry
When I run this script, it works fine. I end up with four screen instances in the list, and they're all running as necessary.
Next, I created a service for systemd to run on startup.
coinscripts.service looks like this:
[Unit]
Description = Coinscripts daemon
After network.target = auditd.service
[Service]
type=Simple
ExecStart =/usr/local/bin/lbrystartup.sh
[Install]
WantedBy = multi-user.target
I've enabled the service, and it's successful in doing so. However, when I run the service with "sudo systemctl start coinscripts", the screen instances don't open. But, when I use systemctl status coinscripts, I get the following:
● coinscripts.service - Coinscripts daemon Loaded: loaded (/etc/systemd/system/coinscripts.service; enabled; vendor pres
Active: inactive (dead) since Fri 2017-06-30 21:59:10 PDT; 1min 3s ago
Process: 1050 ExecStart=/usr/local/bin/lbrystartup.sh (code=exited,
status=0/S Main PID: 1050 (code=exited, status=0/SUCCESS)
Jun 30 21:59:10 ubuntu systemd[1]: Started Coinscripts daemon.
Same happens when I restart the machine.
What am I doing wrong with the service script? I'm using Ubuntu 16.04
scripts services systemd
What doesscreen -list
say? As the service runs asroot
, maybe you have to run that asroot
. Or look for sockets in/var/run/screen
viasudo ls -lR /var/run/screen
.
– ridgy
Jul 1 '17 at 8:53
When running the service, screen -list says there are no running screens.
– Chris Robock
Jul 1 '17 at 16:58
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I created a simple script to run four other commands. I have it located at /usr/local/bin/lbrystartup.sh, and it contains the following:
#!/bin/bash
#Start web scripts
screen -dmS main /var/www/html/main.sh
screen -dmS loop2 /var/www/html/loop2.sh
screen -dmS blocks /var/www/html/blocks.sh
screen -dmS lbry /var/stratum/run.sh lbry
When I run this script, it works fine. I end up with four screen instances in the list, and they're all running as necessary.
Next, I created a service for systemd to run on startup.
coinscripts.service looks like this:
[Unit]
Description = Coinscripts daemon
After network.target = auditd.service
[Service]
type=Simple
ExecStart =/usr/local/bin/lbrystartup.sh
[Install]
WantedBy = multi-user.target
I've enabled the service, and it's successful in doing so. However, when I run the service with "sudo systemctl start coinscripts", the screen instances don't open. But, when I use systemctl status coinscripts, I get the following:
● coinscripts.service - Coinscripts daemon Loaded: loaded (/etc/systemd/system/coinscripts.service; enabled; vendor pres
Active: inactive (dead) since Fri 2017-06-30 21:59:10 PDT; 1min 3s ago
Process: 1050 ExecStart=/usr/local/bin/lbrystartup.sh (code=exited,
status=0/S Main PID: 1050 (code=exited, status=0/SUCCESS)
Jun 30 21:59:10 ubuntu systemd[1]: Started Coinscripts daemon.
Same happens when I restart the machine.
What am I doing wrong with the service script? I'm using Ubuntu 16.04
scripts services systemd
I created a simple script to run four other commands. I have it located at /usr/local/bin/lbrystartup.sh, and it contains the following:
#!/bin/bash
#Start web scripts
screen -dmS main /var/www/html/main.sh
screen -dmS loop2 /var/www/html/loop2.sh
screen -dmS blocks /var/www/html/blocks.sh
screen -dmS lbry /var/stratum/run.sh lbry
When I run this script, it works fine. I end up with four screen instances in the list, and they're all running as necessary.
Next, I created a service for systemd to run on startup.
coinscripts.service looks like this:
[Unit]
Description = Coinscripts daemon
After network.target = auditd.service
[Service]
type=Simple
ExecStart =/usr/local/bin/lbrystartup.sh
[Install]
WantedBy = multi-user.target
I've enabled the service, and it's successful in doing so. However, when I run the service with "sudo systemctl start coinscripts", the screen instances don't open. But, when I use systemctl status coinscripts, I get the following:
● coinscripts.service - Coinscripts daemon Loaded: loaded (/etc/systemd/system/coinscripts.service; enabled; vendor pres
Active: inactive (dead) since Fri 2017-06-30 21:59:10 PDT; 1min 3s ago
Process: 1050 ExecStart=/usr/local/bin/lbrystartup.sh (code=exited,
status=0/S Main PID: 1050 (code=exited, status=0/SUCCESS)
Jun 30 21:59:10 ubuntu systemd[1]: Started Coinscripts daemon.
Same happens when I restart the machine.
What am I doing wrong with the service script? I'm using Ubuntu 16.04
scripts services systemd
scripts services systemd
asked Jul 1 '17 at 5:03
Chris Robock
61
61
What doesscreen -list
say? As the service runs asroot
, maybe you have to run that asroot
. Or look for sockets in/var/run/screen
viasudo ls -lR /var/run/screen
.
– ridgy
Jul 1 '17 at 8:53
When running the service, screen -list says there are no running screens.
– Chris Robock
Jul 1 '17 at 16:58
add a comment |
What doesscreen -list
say? As the service runs asroot
, maybe you have to run that asroot
. Or look for sockets in/var/run/screen
viasudo ls -lR /var/run/screen
.
– ridgy
Jul 1 '17 at 8:53
When running the service, screen -list says there are no running screens.
– Chris Robock
Jul 1 '17 at 16:58
What does
screen -list
say? As the service runs as root
, maybe you have to run that as root
. Or look for sockets in /var/run/screen
via sudo ls -lR /var/run/screen
.– ridgy
Jul 1 '17 at 8:53
What does
screen -list
say? As the service runs as root
, maybe you have to run that as root
. Or look for sockets in /var/run/screen
via sudo ls -lR /var/run/screen
.– ridgy
Jul 1 '17 at 8:53
When running the service, screen -list says there are no running screens.
– Chris Robock
Jul 1 '17 at 16:58
When running the service, screen -list says there are no running screens.
– Chris Robock
Jul 1 '17 at 16:58
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Are you still having this issue? This is more of a comment than an answer, but I apparently don't have enough points or whatever to comment...
I'm having a somewhat related issue on 18.04. Are you on 16.04?
I notice that you have an error in your After= section. should be:
After=network.target auditd.service
Not sure you really need the auditd.service there, but I think it should be ok. Also, you have:
type=Simple
which I believe needs to be:
Type=simple
The ExecStart line may also be having a problem with the equals sign (try deleting the preceding space), but I'm not sure how systemd handles the spaces, so that may be fine.
Lastly, I think you may want this to be Type=forking, since you are calling a child process in screen that will not exit upon completion.
Edit:
I also just realized that you're not using absolute paths in your script (i.e. /usr/bin/program instead of just program). Try that too.
I also would like to throw in a suggestion to use tmux instead of screen. In my experience screen is not very robust and often crashes, and tmux is a much better implementation of the same service. The commands are different though, so read up on those if you do decide to try it.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Are you still having this issue? This is more of a comment than an answer, but I apparently don't have enough points or whatever to comment...
I'm having a somewhat related issue on 18.04. Are you on 16.04?
I notice that you have an error in your After= section. should be:
After=network.target auditd.service
Not sure you really need the auditd.service there, but I think it should be ok. Also, you have:
type=Simple
which I believe needs to be:
Type=simple
The ExecStart line may also be having a problem with the equals sign (try deleting the preceding space), but I'm not sure how systemd handles the spaces, so that may be fine.
Lastly, I think you may want this to be Type=forking, since you are calling a child process in screen that will not exit upon completion.
Edit:
I also just realized that you're not using absolute paths in your script (i.e. /usr/bin/program instead of just program). Try that too.
I also would like to throw in a suggestion to use tmux instead of screen. In my experience screen is not very robust and often crashes, and tmux is a much better implementation of the same service. The commands are different though, so read up on those if you do decide to try it.
add a comment |
up vote
0
down vote
Are you still having this issue? This is more of a comment than an answer, but I apparently don't have enough points or whatever to comment...
I'm having a somewhat related issue on 18.04. Are you on 16.04?
I notice that you have an error in your After= section. should be:
After=network.target auditd.service
Not sure you really need the auditd.service there, but I think it should be ok. Also, you have:
type=Simple
which I believe needs to be:
Type=simple
The ExecStart line may also be having a problem with the equals sign (try deleting the preceding space), but I'm not sure how systemd handles the spaces, so that may be fine.
Lastly, I think you may want this to be Type=forking, since you are calling a child process in screen that will not exit upon completion.
Edit:
I also just realized that you're not using absolute paths in your script (i.e. /usr/bin/program instead of just program). Try that too.
I also would like to throw in a suggestion to use tmux instead of screen. In my experience screen is not very robust and often crashes, and tmux is a much better implementation of the same service. The commands are different though, so read up on those if you do decide to try it.
add a comment |
up vote
0
down vote
up vote
0
down vote
Are you still having this issue? This is more of a comment than an answer, but I apparently don't have enough points or whatever to comment...
I'm having a somewhat related issue on 18.04. Are you on 16.04?
I notice that you have an error in your After= section. should be:
After=network.target auditd.service
Not sure you really need the auditd.service there, but I think it should be ok. Also, you have:
type=Simple
which I believe needs to be:
Type=simple
The ExecStart line may also be having a problem with the equals sign (try deleting the preceding space), but I'm not sure how systemd handles the spaces, so that may be fine.
Lastly, I think you may want this to be Type=forking, since you are calling a child process in screen that will not exit upon completion.
Edit:
I also just realized that you're not using absolute paths in your script (i.e. /usr/bin/program instead of just program). Try that too.
I also would like to throw in a suggestion to use tmux instead of screen. In my experience screen is not very robust and often crashes, and tmux is a much better implementation of the same service. The commands are different though, so read up on those if you do decide to try it.
Are you still having this issue? This is more of a comment than an answer, but I apparently don't have enough points or whatever to comment...
I'm having a somewhat related issue on 18.04. Are you on 16.04?
I notice that you have an error in your After= section. should be:
After=network.target auditd.service
Not sure you really need the auditd.service there, but I think it should be ok. Also, you have:
type=Simple
which I believe needs to be:
Type=simple
The ExecStart line may also be having a problem with the equals sign (try deleting the preceding space), but I'm not sure how systemd handles the spaces, so that may be fine.
Lastly, I think you may want this to be Type=forking, since you are calling a child process in screen that will not exit upon completion.
Edit:
I also just realized that you're not using absolute paths in your script (i.e. /usr/bin/program instead of just program). Try that too.
I also would like to throw in a suggestion to use tmux instead of screen. In my experience screen is not very robust and often crashes, and tmux is a much better implementation of the same service. The commands are different though, so read up on those if you do decide to try it.
edited Nov 21 at 22:03
answered Nov 21 at 21:42
MysticEagle
184
184
add a comment |
add a comment |
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%2f930892%2fwhy-does-my-systemd-service-shut-down-immediately-after-running%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
What does
screen -list
say? As the service runs asroot
, maybe you have to run that asroot
. Or look for sockets in/var/run/screen
viasudo ls -lR /var/run/screen
.– ridgy
Jul 1 '17 at 8:53
When running the service, screen -list says there are no running screens.
– Chris Robock
Jul 1 '17 at 16:58