Run script with rc.local: script works, but not at boot

前端 未结 16 1044
失恋的感觉
失恋的感觉 2020-12-02 07:38

I have a node.js script which need to start at boot and run under the www-data user. During development I always started the script with:

su www-dat         


        
相关标签:
16条回答
  • 2020-12-02 08:02

    first make the script executable using sudo chmod 755 /path/of/the/file.sh now add the script in the rc.local sh /path/of/the/file.sh before exit 0 in the rc.local, next make the rc.local to executable with sudo chmod 755 /etc/rc.local next to initialize the rc.local use sudo /etc/init.d/rc.local start this will initiate the rc.local now reboot the system. Done..

    0 讨论(0)
  • 2020-12-02 08:02

    I found that because I was using a network-oriented command in my rc.local, sometimes it would fail. I fixed this by putting sleep 3 at the top of my script. I don't know why but it seems when the script is run the network interfaces aren't properly configured or something, and this just allows some time for the DHCP server or something. I don't fully understand but I suppose you could give it a try.

    0 讨论(0)
  • 2020-12-02 08:04

    It is my understanding that if you place your script in a certain RUN Level, you should use ln -s to link the script to the level you want it to work in.

    0 讨论(0)
  • 2020-12-02 08:06

    You might also have made it work by specifying the full path to node. Furthermore, when you want to run a shell command as a daemon you should close stdin by adding 1<&- before the &.

    0 讨论(0)
提交回复
热议问题