0

I have a little node application on a server (node mailer) that I run by going to its source folder and executing npm start. I figured the best way to run this automatically would be to create a my_script.sh file and drop it in the init.d directory of my debian box. Inside the file (below the !#/bin/bash line), the code to execute is

'/opt/mycode/source/npm start'

I save the line to the .sh file and restarted the machine, but so far haven't got it to work. My question is: is this even how you start a script like this (using that command and an .sh file)? It does start normally when I do it manually (when I navigate to it and run npm start in the terminal). I included the single quotes around it because of the space between npm start. Also, if I want to verify that it worked, which process would I look for other than just pinging my smtp mailer? Finally, I know I need to run:

update-rc.d my_script.sh defaults

but I was also confused at to whether I had done this correctly either (is it just the name of the file that goes there or the file plus the extension)?

jcoop7777
  • 73
  • 6

1 Answers1

0

The script that you leave on the init.d folder should not have any extension and should have functions to start, stop and get the status of the service (your application).

I'll leave a link with an example as well as with some basis in order to build the Linux service script.

I would suggest reloading the daemon with systemctl daemon-reload in order to refresh the Linux service files once you add a new one.

luckongas
  • 1,651
  • 8
  • 17