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

前端 未结 16 1260
失恋的感觉
失恋的感觉 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条回答
  •  猫巷女王i
    2020-12-02 07:41

    In this example of a rc.local script I use io redirection at the very first line of execution to my own log file:

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    exec 2> /tmp/rc.local.log  # send stderr from rc.local to a log file
    exec 1>&2                      # send stdout to the same log file
    set -x                         # tell sh to display commands before execution
    
    /opt/stuff/somefancy.error.script.sh
    
    exit 0
    

提交回复
热议问题