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










share|improve this question






















  • What does screen -listsay? 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















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










share|improve this question






















  • What does screen -listsay? 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













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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 1 '17 at 5:03









Chris Robock

61




61












  • What does screen -listsay? 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


















  • What does screen -listsay? 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
















What does screen -listsay? 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 -listsay? 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










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.






share|improve this answer























    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',
    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
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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.






    share|improve this answer



























      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.






      share|improve this answer

























        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 22:03

























        answered Nov 21 at 21:42









        MysticEagle

        184




        184






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            How did Captain America manage to do this?

            迪纳利

            南乌拉尔铁路局