我有一个nodejs应用程序,我想在oracle linux服务器上作为一个服务运行它。
我已经创建了服务文件/etc/init.d/wsdlsrv,然后运行以下命令:

cd /etc/init.d
chmod +x wsdlsrv
/sbin/chkconfig wsdlsrv on
systemctl start wsdlsrv

wsdlsrv代码如下:
user="root"
. /etc/init.d/functions
export PATH="/usr/local/bin/:/usr/bin/:$PATH"
name='wsdlsrv'
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"
get_pid() {
    cat "$pid_file"
}
is_running() {
    [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
}
case "$1" in
    start)
    if is_running; then
        echo "Already started"
    else
        echo "Starting $name"
        cd "/home/wsdlsrv"
            su $user -c "node app" >> "$stdout_log" 2>> "$stderr_log" &

        echo $! > "$pid_file"
        if ! is_running; then
            echo "Unable to start, see $stdout_log and $stderr_log"
            exit 1
        fi
    fi
    ;;
    stop)
    if is_running; then
        echo -n "Stopping $name.."
        kill `get_pid`
        for i in {1..10}
        do
            if ! is_running; then
                break
            fi

            echo -n "."
            sleep 1
        done
        echo

        if is_running; then
            echo "Not stopped; may still be shutting down or shutdown may have failed"
            exit 1
        else
            echo "Stopped"
                if [ -f "$pid_file" ]; then
                rm "$pid_file"
            fi
        fi
    else
        echo "Not running"
    fi
    ;;
    restart)
    $0 stop
    if is_running; then
        echo "Unable to stop, will not attempt to start"
        exit 1
    fi
    $0 start
    ;;
    status)
    if is_running; then
        echo "Running"
    else
        echo "Stopped"
        exit 1
    fi
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0

但是,当我尝试用StulcLT启动服务时,它抛出了错误:WSDLSRv.Service的作业失败,因为控制过程退出了错误代码。有关详细信息,请参阅“StultCTL状态WSDLSRv.Service”和“NejalCTL -XE”。WSDLSRv.Service的作业失败,因为控制过程退出了错误代码。有关详细信息,请参阅“systemctl status wsdlsrv.service”和“journalctl-xe”。

最佳答案

你试过使用service wsdlsrv start吗?
确保在/etc/sysconfig/wsdlsrv处至少有空文件项

[root@centos ~]# cat /etc/sysconfig/wsdlsrv
# TODO: add relevant configuration stuff here.

然后需要通过执行systemctl daemon-reload重新加载systemctl守护进程。
在此之后,您可以使用systemctl status wsdlsrvsystemctl start wsdlsrv等。
前任:
[root@centos init.d]# systemctl status wsdlsrv
● wsdlsrv.service - (null)
   Loaded: loaded (/etc/rc.d/init.d/wsdlsrv; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2017-03-14 17:12:47 EDT; 7min ago
     Docs: man:systemd-sysv-generator(8)

Mar 14 17:12:47 centos systemd[1]: Starting (null)...
Mar 14 17:12:47 centos systemd[1]: wsdlsrv.service: control process exited, code=exited status=203
Mar 14 17:12:47 centos systemd[1]: Failed to start (null).
Mar 14 17:12:47 centos systemd[1]: Unit wsdlsrv.service entered failed state.
Mar 14 17:12:47 centos systemd[1]: wsdlsrv.service failed.

您可以使用journalctl -xe查看来自systemd的错误消息

09-10 12:08