ossrs / srs

SRS is a simple, high-efficiency, real-time media server supporting RTMP, WebRTC, HLS, HTTP-FLV, HTTP-TS, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.32k stars 5.33k forks source link

srs failed to start automatically on boot'. #3545

Closed ytsdayou closed 1 year ago

ytsdayou commented 1 year ago

Note: Please read FAQ before file an issue, see #2716

Description

Please description your issue here

  1. SRS Version: v4.0 Server: Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-148-generic x86_64)

  2. SRS Log:

xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx

/var/log/syslog:

May 18 08:46:53 ms systemd[1]: Started Dispatcher daemon for systemd-networkd.
May 18 08:46:53 ms srs[858]: SRS start failed#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:53 ms srs[858]: see /usr/local/srs/objs/srs.log#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:53 ms systemd[1]: srs.service: Control process exited, code=exited, status=1/FAILURE
May 18 08:46:53 ms systemd[1]: srs.service: Failed with result 'exit-code'.
May 18 08:46:53 ms systemd[1]: Failed to start The SRS Media Stream Cluster.
May 18 08:46:54 ms systemd[1]: srs.service: Scheduled restart job, restart counter is at 1.
May 18 08:46:54 ms systemd[1]: Stopped The SRS Media Stream Cluster.
May 18 08:46:54 ms systemd[1]: Starting The SRS Media Stream Cluster...
May 18 08:46:54 ms srs[977]: Starting SRS...#033[60G#033[0m[#033[32m  OK  #033[0m]
May 18 08:46:54 ms srs[977]: SRS start failed#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms srs[977]: see /usr/local/srs/objs/srs.log#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms systemd[1]: srs.service: Control process exited, code=exited, status=1/FAILURE
May 18 08:46:54 ms systemd[1]: srs.service: Failed with result 'exit-code'.
May 18 08:46:54 ms systemd[1]: Failed to start The SRS Media Stream Cluster.
May 18 08:46:54 ms systemd[1]: srs.service: Scheduled restart job, restart counter is at 2.
May 18 08:46:54 ms systemd[1]: Stopped The SRS Media Stream Cluster.
May 18 08:46:54 ms systemd[1]: Starting The SRS Media Stream Cluster...
May 18 08:46:54 ms srs[1015]: Starting SRS...#033[60G#033[0m[#033[32m  OK  #033[0m]
May 18 08:46:54 ms thermald[873]: I/O warning : failed to load external entity "/etc/thermald/thermal-conf.xml"
May 18 08:46:54 ms thermald[873]: error: could not parse file /etc/thermald/thermal-conf.xml
May 18 08:46:54 ms thermald[873]: I/O warning : failed to load external entity "/etc/thermald/thermal-conf.xml"
May 18 08:46:54 ms thermald[873]: error: could not parse file /etc/thermald/thermal-conf.xml
May 18 08:46:54 ms srs[1015]: SRS start failed#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms srs[1015]: see /usr/local/srs/objs/srs.log#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms systemd[1]: srs.service: Control process exited, code=exited, status=1/FAILURE
May 18 08:46:54 ms systemd[1]: srs.service: Failed with result 'exit-code'.
May 18 08:46:54 ms systemd[1]: Failed to start The SRS Media Stream Cluster.
May 18 08:46:54 ms ntpd[940]: Soliciting pool server 193.70.94.182
May 18 08:46:54 ms ntpd[940]: Soliciting pool server 146.59.35.38
May 18 08:46:54 ms ntpd[940]: Soliciting pool server 79.133.44.136
May 18 08:46:54 ms systemd[1]: srs.service: Scheduled restart job, restart counter is at 3.
May 18 08:46:54 ms systemd[1]: Stopped The SRS Media Stream Cluster.
May 18 08:46:54 ms systemd[1]: Starting The SRS Media Stream Cluster...
May 18 08:46:54 ms srs[1052]: Starting SRS...#033[60G#033[0m[#033[32m  OK  #033[0m]
May 18 08:46:54 ms thermald[873]: I/O warning : failed to load external entity "/etc/thermald/thermal-conf.xml"
May 18 08:46:54 ms thermald[873]: error: could not parse file /etc/thermald/thermal-conf.xml
May 18 08:46:54 ms srs[1052]: SRS start failed#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms srs[1052]: see /usr/local/srs/objs/srs.log#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms systemd[1]: srs.service: Control process exited, code=exited, status=1/FAILURE
May 18 08:46:54 ms systemd[1]: srs.service: Failed with result 'exit-code'.
May 18 08:46:54 ms systemd[1]: Failed to start The SRS Media Stream Cluster.
May 18 08:46:54 ms set-cpufreq[844]: Setting powersave scheduler for all CPUs
May 18 08:46:54 ms systemd[1]: ondemand.service: Succeeded.
May 18 08:46:54 ms systemd[1]: srs.service: Scheduled restart job, restart counter is at 4.
May 18 08:46:54 ms systemd[1]: Stopped The SRS Media Stream Cluster.
May 18 08:46:54 ms systemd[1]: Starting The SRS Media Stream Cluster...
May 18 08:46:54 ms srs[1093]: Starting SRS...#033[60G#033[0m[#033[32m  OK  #033[0m]
May 18 08:46:54 ms ModemManager[964]: <info>  ModemManager (version 1.18.6) starting in system bus...
May 18 08:46:54 ms srs[1093]: SRS start failed#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms srs[1093]: see /usr/local/srs/objs/srs.log#033[60G#033[0m[#033[31mFAILED#033[0m]
May 18 08:46:54 ms systemd[1]: srs.service: Control process exited, code=exited, status=1/FAILURE
May 18 08:46:54 ms systemd[1]: srs.service: Failed with result 'exit-code'.
May 18 08:46:54 ms systemd[1]: Failed to start The SRS Media Stream Cluster.
May 18 08:46:55 ms systemd[1]: srs.service: Scheduled restart job, restart counter is at 5.
May 18 08:46:55 ms systemd[1]: Stopped The SRS Media Stream Cluster.
May 18 08:46:55 ms systemd[1]: srs.service: Start request repeated too quickly.
May 18 08:46:55 ms systemd[1]: srs.service: Failed with result 'exit-code'.
May 18 08:46:55 ms systemd[1]: Failed to start The SRS Media Stream Cluster.
  1. SRS Config:
# main config for srs.
# @see full.conf for detail config.

listen              1935;
max_connections     1000;
#srs_log_tank        file;
#srs_log_file        ./objs/srs.log;
daemon              on;
http_api {
    enabled         on;
    listen          1985;
}
http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
}
rtc_server {
    enabled on;
    listen 8000; # UDP port
    # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
    candidate 172.16.0.3;
    #candidate $CANDIDATE;
}
vhost __defaultVhost__ {
    hls {
        enabled         on;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
    }
    rtc {
        enabled     on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
        #rtmp_to_rtc off;
        rtmp_to_rtc on;
        # @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
        rtc_to_rtmp off;
    }
}

Replay

Please describe how to replay the bug?

Step 1: Server reboot

During the startup process, if the service fails to start, the system will automatically attempt to restart it 5 times. There is approximately a 90% chance that the service will not start successfully within these 5 retries, but there is a 10% chance that it will start successfully within these 5 retries.

Step 2: After restarting, manually executing the command sudo systemctl start srs will be successful.

xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx

Expect

I expect to be able to restart successfully every time after rebooting.

TRANS_BY_GPT3

ytsdayou commented 1 year ago

I solved it myself, and I will share it with friends who need it. Modify the /lib/systemd/system/srs.service file, and add multi-user.target after After=.

` [Unit] Description=The SRS Media Stream Cluster After=network.target multi-user.target

[Service] Type=forking Restart=always ExecStart=/etc/init.d/srs start ExecReload=/etc/init.d/srs reload ExecStop=/etc/init.d/srs stop

[Install] WantedBy=multi-user.target `

TRANS_BY_GPT3