28

I have a Debian server and I just need to run a script at startup.

I read that: https://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian

I got now: insserv: warning: script ' missing LSB tags and overrides

so it looks like I have to add now:

### BEGIN INIT INFO
# Provides:          scriptname
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

It looks now crazy: like 30 lines of script just to run a program at startup.

Is there a tool that allows to do that a simply way ?

Regards

wurtel
  • 3,999
yarek
  • 847

3 Answers3

37

Consider using /etc/rc.local (executed as root) or crontab (executed as a user of your choice).

Two examples:

  • /etc/rc.local

    #!/bin/sh -e
    #(Multiple lines of comments removed.)
    /usr/local/bin/your-script.sh
    exit 0
    
  • crontab (edited via, for example, crontab -e)

    #(Multiple lines of comments removed.)
    @reboot /usr/local/bin/your-script.sh
    

If your script needs to run continuously in the background, I would advise against using rc.local or crontab, and instead write a proper (or multiple) init.d script(s). This way you / your system is able to cleanly restart/reload/start/stop etc. the daemons.

The LSB tags provide some value: "By documenting the run-time dependencies for init.d scripts, it becomes possible to verify the current boot order, order the boot using these dependencies, and run boot scripts in parallel to speed up the boot process." For more details, head over to the Debian wiki.

By the way, the missing headers: It's a warning, so actually, it's up to you, how and what to do with this.

TZubiri
  • 190
gxx
  • 5,199
0

supervisord is also an option. You will write again some lines in order to start your node.js and PHP stuff, but they will be fewer.

adamo
  • 7,045
0

You can use monitd for this, just write some monit definition and it will start daemons for you. But why you don't use proper way with LSB scripts? It's not so hard to write it (you're writting it just once) and it is the cleanest and most valuable way how to achieve this.