How to start an application automatically on boot

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
21
down vote

favorite
7












I am new to Linux & looking forward to start application (which toggles a led every 10 sec).
I have written the application program & it is working fine but now I want to start it automatically on boot.



The documentation here says to copy the startup script to the /etc/init.d directory and make a symbolic link to the copied script in the rc.d directory.



What should be the extension and name of these script files?
Can we manually add the symbolic link in rc.d or is there some specific procedure for this?



Any suggestion how to achieve it?










share|improve this question























  • The preferred way to add an init script to startup varies by distros. Some are even phasing them out in favor of upstart and systemd. I wouldn't recommend simply using "&" to background, as something like Debian's start-stop-daemon handles it better (although it preferable the program itself daemonizes). What distro are you using? Outside of desktop MIME types, file extensions are meaningless in *nix and its preferred that executables don't have one.
    – jordanm
    Nov 28 '12 at 4:54











  • If you are using petalogix, just follow that documentation - no special names required, just do as they say. Did you try it? What problems are you having? (If not, please specify your distro and explain what doesn't work with what you tried.)
    – Mat
    Nov 28 '12 at 5:14










  • I am using Debian “wheezy” for RPi.
    – gorge
    Nov 28 '12 at 6:12






  • 1




    if you need to do it approximately every 10 seconds (i.e. not 10 seconds sharp), you might want to use cron instead.
    – peterph
    Nov 28 '12 at 10:08










  • @peterph: but it sounds like the program toggles the LED every 10 seconds, not a program that is executed every 10 seconds.
    – Zorawar
    Nov 28 '12 at 13:47














up vote
21
down vote

favorite
7












I am new to Linux & looking forward to start application (which toggles a led every 10 sec).
I have written the application program & it is working fine but now I want to start it automatically on boot.



The documentation here says to copy the startup script to the /etc/init.d directory and make a symbolic link to the copied script in the rc.d directory.



What should be the extension and name of these script files?
Can we manually add the symbolic link in rc.d or is there some specific procedure for this?



Any suggestion how to achieve it?










share|improve this question























  • The preferred way to add an init script to startup varies by distros. Some are even phasing them out in favor of upstart and systemd. I wouldn't recommend simply using "&" to background, as something like Debian's start-stop-daemon handles it better (although it preferable the program itself daemonizes). What distro are you using? Outside of desktop MIME types, file extensions are meaningless in *nix and its preferred that executables don't have one.
    – jordanm
    Nov 28 '12 at 4:54











  • If you are using petalogix, just follow that documentation - no special names required, just do as they say. Did you try it? What problems are you having? (If not, please specify your distro and explain what doesn't work with what you tried.)
    – Mat
    Nov 28 '12 at 5:14










  • I am using Debian “wheezy” for RPi.
    – gorge
    Nov 28 '12 at 6:12






  • 1




    if you need to do it approximately every 10 seconds (i.e. not 10 seconds sharp), you might want to use cron instead.
    – peterph
    Nov 28 '12 at 10:08










  • @peterph: but it sounds like the program toggles the LED every 10 seconds, not a program that is executed every 10 seconds.
    – Zorawar
    Nov 28 '12 at 13:47












up vote
21
down vote

favorite
7









up vote
21
down vote

favorite
7






7





I am new to Linux & looking forward to start application (which toggles a led every 10 sec).
I have written the application program & it is working fine but now I want to start it automatically on boot.



The documentation here says to copy the startup script to the /etc/init.d directory and make a symbolic link to the copied script in the rc.d directory.



What should be the extension and name of these script files?
Can we manually add the symbolic link in rc.d or is there some specific procedure for this?



Any suggestion how to achieve it?










share|improve this question















I am new to Linux & looking forward to start application (which toggles a led every 10 sec).
I have written the application program & it is working fine but now I want to start it automatically on boot.



The documentation here says to copy the startup script to the /etc/init.d directory and make a symbolic link to the copied script in the rc.d directory.



What should be the extension and name of these script files?
Can we manually add the symbolic link in rc.d or is there some specific procedure for this?



Any suggestion how to achieve it?







linux debian startup






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '12 at 23:11









Gilles

513k12010161547




513k12010161547










asked Nov 28 '12 at 3:21









gorge

106113




106113











  • The preferred way to add an init script to startup varies by distros. Some are even phasing them out in favor of upstart and systemd. I wouldn't recommend simply using "&" to background, as something like Debian's start-stop-daemon handles it better (although it preferable the program itself daemonizes). What distro are you using? Outside of desktop MIME types, file extensions are meaningless in *nix and its preferred that executables don't have one.
    – jordanm
    Nov 28 '12 at 4:54











  • If you are using petalogix, just follow that documentation - no special names required, just do as they say. Did you try it? What problems are you having? (If not, please specify your distro and explain what doesn't work with what you tried.)
    – Mat
    Nov 28 '12 at 5:14










  • I am using Debian “wheezy” for RPi.
    – gorge
    Nov 28 '12 at 6:12






  • 1




    if you need to do it approximately every 10 seconds (i.e. not 10 seconds sharp), you might want to use cron instead.
    – peterph
    Nov 28 '12 at 10:08










  • @peterph: but it sounds like the program toggles the LED every 10 seconds, not a program that is executed every 10 seconds.
    – Zorawar
    Nov 28 '12 at 13:47
















  • The preferred way to add an init script to startup varies by distros. Some are even phasing them out in favor of upstart and systemd. I wouldn't recommend simply using "&" to background, as something like Debian's start-stop-daemon handles it better (although it preferable the program itself daemonizes). What distro are you using? Outside of desktop MIME types, file extensions are meaningless in *nix and its preferred that executables don't have one.
    – jordanm
    Nov 28 '12 at 4:54











  • If you are using petalogix, just follow that documentation - no special names required, just do as they say. Did you try it? What problems are you having? (If not, please specify your distro and explain what doesn't work with what you tried.)
    – Mat
    Nov 28 '12 at 5:14










  • I am using Debian “wheezy” for RPi.
    – gorge
    Nov 28 '12 at 6:12






  • 1




    if you need to do it approximately every 10 seconds (i.e. not 10 seconds sharp), you might want to use cron instead.
    – peterph
    Nov 28 '12 at 10:08










  • @peterph: but it sounds like the program toggles the LED every 10 seconds, not a program that is executed every 10 seconds.
    – Zorawar
    Nov 28 '12 at 13:47















The preferred way to add an init script to startup varies by distros. Some are even phasing them out in favor of upstart and systemd. I wouldn't recommend simply using "&" to background, as something like Debian's start-stop-daemon handles it better (although it preferable the program itself daemonizes). What distro are you using? Outside of desktop MIME types, file extensions are meaningless in *nix and its preferred that executables don't have one.
– jordanm
Nov 28 '12 at 4:54





The preferred way to add an init script to startup varies by distros. Some are even phasing them out in favor of upstart and systemd. I wouldn't recommend simply using "&" to background, as something like Debian's start-stop-daemon handles it better (although it preferable the program itself daemonizes). What distro are you using? Outside of desktop MIME types, file extensions are meaningless in *nix and its preferred that executables don't have one.
– jordanm
Nov 28 '12 at 4:54













If you are using petalogix, just follow that documentation - no special names required, just do as they say. Did you try it? What problems are you having? (If not, please specify your distro and explain what doesn't work with what you tried.)
– Mat
Nov 28 '12 at 5:14




If you are using petalogix, just follow that documentation - no special names required, just do as they say. Did you try it? What problems are you having? (If not, please specify your distro and explain what doesn't work with what you tried.)
– Mat
Nov 28 '12 at 5:14












I am using Debian “wheezy” for RPi.
– gorge
Nov 28 '12 at 6:12




I am using Debian “wheezy” for RPi.
– gorge
Nov 28 '12 at 6:12




1




1




if you need to do it approximately every 10 seconds (i.e. not 10 seconds sharp), you might want to use cron instead.
– peterph
Nov 28 '12 at 10:08




if you need to do it approximately every 10 seconds (i.e. not 10 seconds sharp), you might want to use cron instead.
– peterph
Nov 28 '12 at 10:08












@peterph: but it sounds like the program toggles the LED every 10 seconds, not a program that is executed every 10 seconds.
– Zorawar
Nov 28 '12 at 13:47




@peterph: but it sounds like the program toggles the LED every 10 seconds, not a program that is executed every 10 seconds.
– Zorawar
Nov 28 '12 at 13:47










4 Answers
4






active

oldest

votes

















up vote
18
down vote













Here's the excerpt from http://www.debian-administration.org/articles/28 which seems to answer your question.



Note: In the example script below just add a call to the "start)" section to actually launch your program.
You can test the script's functionality without rebooting the system: call it with the full path and giving it a parameter of "start" or "stop"



Here goes:



Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.



If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.



Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".



#! /bin/sh
# /etc/init.d/blah
#

# Some things that run always
touch /var/lock/blah

# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting script blah "
echo "Could do more here"
;;
stop)
echo "Stopping script blah"
echo "Could do more here"
;;
*)
echo "Usage: /etc/init.d/blah start"
exit 1
;;
esac

exit 0


Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".



Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.



The simplest way of doing this is to use the Debian-specific command update-rc.d:



root@skx:~# update-rc.d blah defaults
Adding system startup for /etc/init.d/blah ...
/etc/rc0.d/K20blah -> ../init.d/blah
/etc/rc1.d/K20blah -> ../init.d/blah
/etc/rc6.d/K20blah -> ../init.d/blah
/etc/rc2.d/S20blah -> ../init.d/blah
/etc/rc3.d/S20blah -> ../init.d/blah
/etc/rc4.d/S20blah -> ../init.d/blah
/etc/rc5.d/S20blah -> ../init.d/blah





share|improve this answer




















  • do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
    – user137717
    Jun 29 '16 at 14:54










  • I'm getting "-sh: update-rc.d: command not found"
    – m4l490n
    Jun 22 '17 at 19:57






  • 1




    Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
    – Alexander Shcheblikin
    Jul 10 at 2:38

















up vote
2
down vote













The best way is to check package source of your distribution for a regular system service, e.g. for OpenSSH - you'll see what the good practices are. After all, one of the reasons behind open-source is to be able to learn from the sources.






share|improve this answer
















  • 1




    Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
    – Bruce0
    Apr 9 '17 at 15:48

















up vote
2
down vote













Use Supervisor, an effective program that manages and logs the startup applications with arguments.
Learn more from http://supervisord.org/running.html and
(Follow the installation instruction.



Create a conf file at /etc/supervisor/conf.d/PROGRAM_NAME.conf and
Here is the code,



[program:PROGRAM_NAME]
command=/usr/bin/PROGRAM_NAME -arg1 -arg2
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor/PROGRAM_NAME.err.log
stdout_logfile=/var/log/supervisor/PROGRAM_NAME.out.log


Then execute from cmd line:



supervisorctl reload






share|improve this answer






















  • Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
    – dlewin
    Mar 15 at 16:45

















up vote
0
down vote













Using crontab is much easier.



Use crontab -e to edit user's crontab.

Add following line at the end:



@reboot <command>


Examples:



  • @reboot my_script.sh

  • @reboot python my_script.py arg1 arg2

Finally use contab -l to make sure your script was added to the list.






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f56957%2fhow-to-start-an-application-automatically-on-boot%23new-answer', 'question_page');

    );

    Post as a guest






























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    18
    down vote













    Here's the excerpt from http://www.debian-administration.org/articles/28 which seems to answer your question.



    Note: In the example script below just add a call to the "start)" section to actually launch your program.
    You can test the script's functionality without rebooting the system: call it with the full path and giving it a parameter of "start" or "stop"



    Here goes:



    Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.



    If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.



    Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".



    #! /bin/sh
    # /etc/init.d/blah
    #

    # Some things that run always
    touch /var/lock/blah

    # Carry out specific functions when asked to by the system
    case "$1" in
    start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
    stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
    *)
    echo "Usage: /etc/init.d/blah start"
    exit 1
    ;;
    esac

    exit 0


    Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".



    Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.



    The simplest way of doing this is to use the Debian-specific command update-rc.d:



    root@skx:~# update-rc.d blah defaults
    Adding system startup for /etc/init.d/blah ...
    /etc/rc0.d/K20blah -> ../init.d/blah
    /etc/rc1.d/K20blah -> ../init.d/blah
    /etc/rc6.d/K20blah -> ../init.d/blah
    /etc/rc2.d/S20blah -> ../init.d/blah
    /etc/rc3.d/S20blah -> ../init.d/blah
    /etc/rc4.d/S20blah -> ../init.d/blah
    /etc/rc5.d/S20blah -> ../init.d/blah





    share|improve this answer




















    • do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
      – user137717
      Jun 29 '16 at 14:54










    • I'm getting "-sh: update-rc.d: command not found"
      – m4l490n
      Jun 22 '17 at 19:57






    • 1




      Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
      – Alexander Shcheblikin
      Jul 10 at 2:38














    up vote
    18
    down vote













    Here's the excerpt from http://www.debian-administration.org/articles/28 which seems to answer your question.



    Note: In the example script below just add a call to the "start)" section to actually launch your program.
    You can test the script's functionality without rebooting the system: call it with the full path and giving it a parameter of "start" or "stop"



    Here goes:



    Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.



    If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.



    Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".



    #! /bin/sh
    # /etc/init.d/blah
    #

    # Some things that run always
    touch /var/lock/blah

    # Carry out specific functions when asked to by the system
    case "$1" in
    start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
    stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
    *)
    echo "Usage: /etc/init.d/blah start"
    exit 1
    ;;
    esac

    exit 0


    Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".



    Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.



    The simplest way of doing this is to use the Debian-specific command update-rc.d:



    root@skx:~# update-rc.d blah defaults
    Adding system startup for /etc/init.d/blah ...
    /etc/rc0.d/K20blah -> ../init.d/blah
    /etc/rc1.d/K20blah -> ../init.d/blah
    /etc/rc6.d/K20blah -> ../init.d/blah
    /etc/rc2.d/S20blah -> ../init.d/blah
    /etc/rc3.d/S20blah -> ../init.d/blah
    /etc/rc4.d/S20blah -> ../init.d/blah
    /etc/rc5.d/S20blah -> ../init.d/blah





    share|improve this answer




















    • do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
      – user137717
      Jun 29 '16 at 14:54










    • I'm getting "-sh: update-rc.d: command not found"
      – m4l490n
      Jun 22 '17 at 19:57






    • 1




      Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
      – Alexander Shcheblikin
      Jul 10 at 2:38












    up vote
    18
    down vote










    up vote
    18
    down vote









    Here's the excerpt from http://www.debian-administration.org/articles/28 which seems to answer your question.



    Note: In the example script below just add a call to the "start)" section to actually launch your program.
    You can test the script's functionality without rebooting the system: call it with the full path and giving it a parameter of "start" or "stop"



    Here goes:



    Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.



    If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.



    Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".



    #! /bin/sh
    # /etc/init.d/blah
    #

    # Some things that run always
    touch /var/lock/blah

    # Carry out specific functions when asked to by the system
    case "$1" in
    start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
    stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
    *)
    echo "Usage: /etc/init.d/blah start"
    exit 1
    ;;
    esac

    exit 0


    Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".



    Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.



    The simplest way of doing this is to use the Debian-specific command update-rc.d:



    root@skx:~# update-rc.d blah defaults
    Adding system startup for /etc/init.d/blah ...
    /etc/rc0.d/K20blah -> ../init.d/blah
    /etc/rc1.d/K20blah -> ../init.d/blah
    /etc/rc6.d/K20blah -> ../init.d/blah
    /etc/rc2.d/S20blah -> ../init.d/blah
    /etc/rc3.d/S20blah -> ../init.d/blah
    /etc/rc4.d/S20blah -> ../init.d/blah
    /etc/rc5.d/S20blah -> ../init.d/blah





    share|improve this answer












    Here's the excerpt from http://www.debian-administration.org/articles/28 which seems to answer your question.



    Note: In the example script below just add a call to the "start)" section to actually launch your program.
    You can test the script's functionality without rebooting the system: call it with the full path and giving it a parameter of "start" or "stop"



    Here goes:



    Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.



    If you wish to add a new service to start when the machine boots you should add the necessary script to the directory /etc/init.d/. Many of the scripts already present in that directory will give you an example of the kind of things that you can do.



    Here's a very simple script which is divided into two parts, code which always runs, and code which runs when called with "start" or "stop".



    #! /bin/sh
    # /etc/init.d/blah
    #

    # Some things that run always
    touch /var/lock/blah

    # Carry out specific functions when asked to by the system
    case "$1" in
    start)
    echo "Starting script blah "
    echo "Could do more here"
    ;;
    stop)
    echo "Stopping script blah"
    echo "Could do more here"
    ;;
    *)
    echo "Usage: /etc/init.d/blah start"
    exit 1
    ;;
    esac

    exit 0


    Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".



    Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.



    The simplest way of doing this is to use the Debian-specific command update-rc.d:



    root@skx:~# update-rc.d blah defaults
    Adding system startup for /etc/init.d/blah ...
    /etc/rc0.d/K20blah -> ../init.d/blah
    /etc/rc1.d/K20blah -> ../init.d/blah
    /etc/rc6.d/K20blah -> ../init.d/blah
    /etc/rc2.d/S20blah -> ../init.d/blah
    /etc/rc3.d/S20blah -> ../init.d/blah
    /etc/rc4.d/S20blah -> ../init.d/blah
    /etc/rc5.d/S20blah -> ../init.d/blah






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 '12 at 21:23









    Alexander Shcheblikin

    8901712




    8901712











    • do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
      – user137717
      Jun 29 '16 at 14:54










    • I'm getting "-sh: update-rc.d: command not found"
      – m4l490n
      Jun 22 '17 at 19:57






    • 1




      Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
      – Alexander Shcheblikin
      Jul 10 at 2:38
















    • do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
      – user137717
      Jun 29 '16 at 14:54










    • I'm getting "-sh: update-rc.d: command not found"
      – m4l490n
      Jun 22 '17 at 19:57






    • 1




      Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
      – Alexander Shcheblikin
      Jul 10 at 2:38















    do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
    – user137717
    Jun 29 '16 at 14:54




    do I have to actually place this script in etc/init.d/ or does the line at the top, # /etc/init.d/blah, indicate a location to the shell?
    – user137717
    Jun 29 '16 at 14:54












    I'm getting "-sh: update-rc.d: command not found"
    – m4l490n
    Jun 22 '17 at 19:57




    I'm getting "-sh: update-rc.d: command not found"
    – m4l490n
    Jun 22 '17 at 19:57




    1




    1




    Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
    – Alexander Shcheblikin
    Jul 10 at 2:38




    Newer systems employ systemd for many things, including for bootup configuration. Use systemctl to control and configure systemd.
    – Alexander Shcheblikin
    Jul 10 at 2:38












    up vote
    2
    down vote













    The best way is to check package source of your distribution for a regular system service, e.g. for OpenSSH - you'll see what the good practices are. After all, one of the reasons behind open-source is to be able to learn from the sources.






    share|improve this answer
















    • 1




      Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
      – Bruce0
      Apr 9 '17 at 15:48














    up vote
    2
    down vote













    The best way is to check package source of your distribution for a regular system service, e.g. for OpenSSH - you'll see what the good practices are. After all, one of the reasons behind open-source is to be able to learn from the sources.






    share|improve this answer
















    • 1




      Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
      – Bruce0
      Apr 9 '17 at 15:48












    up vote
    2
    down vote










    up vote
    2
    down vote









    The best way is to check package source of your distribution for a regular system service, e.g. for OpenSSH - you'll see what the good practices are. After all, one of the reasons behind open-source is to be able to learn from the sources.






    share|improve this answer












    The best way is to check package source of your distribution for a regular system service, e.g. for OpenSSH - you'll see what the good practices are. After all, one of the reasons behind open-source is to be able to learn from the sources.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 '12 at 15:33









    peterph

    22.7k24357




    22.7k24357







    • 1




      Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
      – Bruce0
      Apr 9 '17 at 15:48












    • 1




      Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
      – Bruce0
      Apr 9 '17 at 15:48







    1




    1




    Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
    – Bruce0
    Apr 9 '17 at 15:48




    Excellent advice! Truly wise and relevant, and tuned to all the Distos. (And incidentally answers the "new to Linux" and the "how do I do it" part of the question. I will use this answer to improve my start stop scripts.
    – Bruce0
    Apr 9 '17 at 15:48










    up vote
    2
    down vote













    Use Supervisor, an effective program that manages and logs the startup applications with arguments.
    Learn more from http://supervisord.org/running.html and
    (Follow the installation instruction.



    Create a conf file at /etc/supervisor/conf.d/PROGRAM_NAME.conf and
    Here is the code,



    [program:PROGRAM_NAME]
    command=/usr/bin/PROGRAM_NAME -arg1 -arg2
    autostart=true
    autorestart=true
    stderr_logfile=/var/log/supervisor/PROGRAM_NAME.err.log
    stdout_logfile=/var/log/supervisor/PROGRAM_NAME.out.log


    Then execute from cmd line:



    supervisorctl reload






    share|improve this answer






















    • Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
      – dlewin
      Mar 15 at 16:45














    up vote
    2
    down vote













    Use Supervisor, an effective program that manages and logs the startup applications with arguments.
    Learn more from http://supervisord.org/running.html and
    (Follow the installation instruction.



    Create a conf file at /etc/supervisor/conf.d/PROGRAM_NAME.conf and
    Here is the code,



    [program:PROGRAM_NAME]
    command=/usr/bin/PROGRAM_NAME -arg1 -arg2
    autostart=true
    autorestart=true
    stderr_logfile=/var/log/supervisor/PROGRAM_NAME.err.log
    stdout_logfile=/var/log/supervisor/PROGRAM_NAME.out.log


    Then execute from cmd line:



    supervisorctl reload






    share|improve this answer






















    • Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
      – dlewin
      Mar 15 at 16:45












    up vote
    2
    down vote










    up vote
    2
    down vote









    Use Supervisor, an effective program that manages and logs the startup applications with arguments.
    Learn more from http://supervisord.org/running.html and
    (Follow the installation instruction.



    Create a conf file at /etc/supervisor/conf.d/PROGRAM_NAME.conf and
    Here is the code,



    [program:PROGRAM_NAME]
    command=/usr/bin/PROGRAM_NAME -arg1 -arg2
    autostart=true
    autorestart=true
    stderr_logfile=/var/log/supervisor/PROGRAM_NAME.err.log
    stdout_logfile=/var/log/supervisor/PROGRAM_NAME.out.log


    Then execute from cmd line:



    supervisorctl reload






    share|improve this answer














    Use Supervisor, an effective program that manages and logs the startup applications with arguments.
    Learn more from http://supervisord.org/running.html and
    (Follow the installation instruction.



    Create a conf file at /etc/supervisor/conf.d/PROGRAM_NAME.conf and
    Here is the code,



    [program:PROGRAM_NAME]
    command=/usr/bin/PROGRAM_NAME -arg1 -arg2
    autostart=true
    autorestart=true
    stderr_logfile=/var/log/supervisor/PROGRAM_NAME.err.log
    stdout_logfile=/var/log/supervisor/PROGRAM_NAME.out.log


    Then execute from cmd line:



    supervisorctl reload







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 26 at 21:33









    Community♦

    1




    1










    answered Jan 30 at 5:13









    Cosmo Arun

    214




    214











    • Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
      – dlewin
      Mar 15 at 16:45
















    • Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
      – dlewin
      Mar 15 at 16:45















    Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
    – dlewin
    Mar 15 at 16:45




    Whereas your answer is fine, I think you should change it to show that "supervisorctl reload " is to be executed from the CLI, not to be inserted in the .conf file
    – dlewin
    Mar 15 at 16:45










    up vote
    0
    down vote













    Using crontab is much easier.



    Use crontab -e to edit user's crontab.

    Add following line at the end:



    @reboot <command>


    Examples:



    • @reboot my_script.sh

    • @reboot python my_script.py arg1 arg2

    Finally use contab -l to make sure your script was added to the list.






    share|improve this answer
























      up vote
      0
      down vote













      Using crontab is much easier.



      Use crontab -e to edit user's crontab.

      Add following line at the end:



      @reboot <command>


      Examples:



      • @reboot my_script.sh

      • @reboot python my_script.py arg1 arg2

      Finally use contab -l to make sure your script was added to the list.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Using crontab is much easier.



        Use crontab -e to edit user's crontab.

        Add following line at the end:



        @reboot <command>


        Examples:



        • @reboot my_script.sh

        • @reboot python my_script.py arg1 arg2

        Finally use contab -l to make sure your script was added to the list.






        share|improve this answer












        Using crontab is much easier.



        Use crontab -e to edit user's crontab.

        Add following line at the end:



        @reboot <command>


        Examples:



        • @reboot my_script.sh

        • @reboot python my_script.py arg1 arg2

        Finally use contab -l to make sure your script was added to the list.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Jithin Pavithran

        1185




        1185



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f56957%2fhow-to-start-an-application-automatically-on-boot%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?