Advertisement
Tritonio

Making scripts run at boot time with Debian (Devuan)

Mar 15th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Debian uses a Sys-V like init system for executing commands when the system runlevel changes - for example at bootup and shutdown time.
  2.  
  3. 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.
  4.  
  5. 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".
  6.  
  7. #! /bin/sh
  8. # /etc/init.d/blah
  9. #
  10.  
  11. # Some things that run always
  12. touch /var/lock/blah
  13.  
  14. # Carry out specific functions when asked to by the system
  15. case "$1" in
  16. start)
  17. echo "Starting script blah "
  18. echo "Could do more here"
  19. ;;
  20. stop)
  21. echo "Stopping script blah"
  22. echo "Could do more here"
  23. ;;
  24. *)
  25. echo "Usage: /etc/init.d/blah {start|stop}"
  26. exit 1
  27. ;;
  28. esac
  29.  
  30. exit 0
  31.  
  32. Once you've saved your file into the correct location make sure that it's executable by running "chmod 755 /etc/init.d/blah".
  33.  
  34. Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up.
  35.  
  36. The simplest way of doing this is to use the Debian-specific command update-rc.d:
  37.  
  38. root@skx:~# update-rc.d blah defaults
  39. Adding system startup for /etc/init.d/blah ...
  40. /etc/rc0.d/K20blah -> ../init.d/blah
  41. /etc/rc1.d/K20blah -> ../init.d/blah
  42. /etc/rc6.d/K20blah -> ../init.d/blah
  43. /etc/rc2.d/S20blah -> ../init.d/blah
  44. /etc/rc3.d/S20blah -> ../init.d/blah
  45. /etc/rc4.d/S20blah -> ../init.d/blah
  46. /etc/rc5.d/S20blah -> ../init.d/blah
  47.  
  48. If you wish to remove the script from the startup sequence in the future run:
  49.  
  50. root@skx:/etc/rc2.d# update-rc.d -f blah remove
  51. update-rc.d: /etc/init.d/blah exists during rc.d purge (continuing)
  52. Removing any system startup links for /etc/init.d/blah ...
  53. /etc/rc0.d/K20blah
  54. /etc/rc1.d/K20blah
  55. /etc/rc2.d/S20blah
  56. /etc/rc3.d/S20blah
  57. /etc/rc4.d/S20blah
  58. /etc/rc5.d/S20blah
  59. /etc/rc6.d/K20blah
  60.  
  61. This will leave the script itself in place, just remove the links which cause it to be executed.
  62.  
  63. You can find more details of this command by running "man update-rc.d".
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement