I've set up a server running Ubuntu 20.04, and if for any reason the power fails or it is rebooted, I want to be able to have a script run automatically that will do the following;
sudo systemctl restart ovenmediaengine.service
export DISPLAY=:0 && obs --startstreaming &
I'm not sure why the ovenmediaengine service needs to be restarted when the server is rebooted, it is already enabled as a service when it was installed.
I have looked into using crontab by doing
sudo crontab -e
and adding to the end of the line:
@reboot /path/to/script.sh
The script file contains two lines as written above, and it is also set as executable. I have also tried to add a few seconds delay at the start of the script as that was preventing me from running scripts on reboot on a different project.
How would I go about checking what can be wrong?
Is there a better way to do what I need to do here?
Edit: Here are the outputs of sudo systemctl status ovenmediaengine.service
before and after a restart:
● ovenmediaengine.service - OvenMediaEngine
Loaded: loaded (/lib/systemd/system/ovenmediaengine.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-07-13 08:03:46 BST; 13min ago
Process: 670 ExecStart=/usr/bin/OvenMediaEngine -d (code=exited, status=0/SUCCESS)
Main PID: 750 (OvenMediaEngine)
Tasks: 24 (limit: 4611)
Memory: 23.3M
CGroup: /system.slice/ovenmediaengine.service
└─750 /usr/bin/OvenMediaEngine -d
Jul 13 08:03:40 streambox-PowerEdge-R210-II systemd[1]: Starting OvenMediaEngine...
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.744] W [OvenMediaEngine:750] HLS | hls_publisher.cpp:38 | HLS Publ>
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.744] W [OvenMediaEngine:750] DASH | dash_publisher.cpp:36 | DASH P>
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.745] W [OvenMediaEngine:750] LLDASH | cmaf_publisher.cpp:39 | LLDA>
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.813] W [OvenMediaEngine:750] Thumbnail | thumbnail_publisher.cpp:45 >
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.935] W [OvenMediaEngine:750] Publisher | publisher.cpp:69 | File p>
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.935] W [OvenMediaEngine:750] Publisher | publisher.cpp:69 | MPEGTS>
Jul 13 08:03:45 streambox-PowerEdge-R210-II OvenMediaEngine[750]: [2022-07-13 08:03:45.935] W [OvenMediaEngine:750] Publisher | publisher.cpp:69 | RTMPPu>
Jul 13 08:03:46 streambox-PowerEdge-R210-II systemd[1]: Started OvenMediaEngine.
After:
● ovenmediaengine.service - OvenMediaEngine
Loaded: loaded (/lib/systemd/system/ovenmediaengine.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-07-13 08:19:45 BST; 7s ago
Process: 2293 ExecStart=/usr/bin/OvenMediaEngine -d (code=exited, status=0/SUCCESS)
Main PID: 2294 (OvenMediaEngine)
Tasks: 30 (limit: 4611)
Memory: 7.5M
CGroup: /system.slice/ovenmediaengine.service
└─2294 /usr/bin/OvenMediaEngine -d
Jul 13 08:19:45 streambox-PowerEdge-R210-II systemd[1]: Starting OvenMediaEngine...
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.303] W [OvenMediaEngine:2294] HLS | hls_publisher.cpp:38 | HLS Pu>
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.303] W [OvenMediaEngine:2294] DASH | dash_publisher.cpp:36 | DASH>
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.304] W [OvenMediaEngine:2294] LLDASH | cmaf_publisher.cpp:39 | LL>
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.305] W [OvenMediaEngine:2294] Thumbnail | thumbnail_publisher.cpp:4>
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.312] W [OvenMediaEngine:2294] Publisher | publisher.cpp:69 | File>
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.312] W [OvenMediaEngine:2294] Publisher | publisher.cpp:69 | MPEG>
Jul 13 08:19:45 streambox-PowerEdge-R210-II OvenMediaEngine[2294]: [2022-07-13 08:19:45.312] W [OvenMediaEngine:2294] Publisher | publisher.cpp:69 | RTMP>
Jul 13 08:19:45 streambox-PowerEdge-R210-II systemd[1]: Started OvenMediaEngine.
I have added the following in sudo crontab -e
@reboot /home/streambox4/startupScript.sh >> /var/log/startupScript.log 2>&1
Here is the output of the log file. Does this mean that due to the order things get initialised, it isn't starting because it needs to wait?
No protocol specified
qt.qpa.xcb: could not connect to display :0
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
root
instead. Also, you haven't actually explained what's not working.systemctl status ovenmediaengine.service
right after a reboot, and again right after you have restarted it.