I have an embedded Linux board that uses systemd for startup processes. I also have a GUI written in Qt that I can launch just fine from the command line and interact with using the board's touchscreen or buttons. To launch the app I usually do:
ssh root#192.168.1.2
cd ~/
./gui
I'd like this to startup automatically using SystemD so I wrote a service file that looks like this:
[Unit]
Description=The Qt Gui
After=dropbear.service systemd-logind.service
ConditionFileIsExecutable=/home/user/gui
[Service]
ExecStart=/home/user/gui
Restart=on-abort
[Install]
WantedBy=multi-user.target
When the board boots I see in the systemd log that it is starting my gui right after the dropbear SSH service:
[ OK ] Started Dropbear SSH2 daemon.
Starting The Qt Gui...
[ OK ] Started The Qt Gui.
And if I SSH to the board after it boots and run 'ps' I can see my process started ( and if I kill it it restarts as expected from systemd ):
196 root 26868 S /home/user/gui
The output of systemctl status looks OK to me, notice the last line 'ARM build' is a qDebug() print statement from my code:
gui.service - The Qt Gui
Loaded: loaded (/etc/systemd/system/gui.service; enabled)
Active: active (running) since Tue, 2012-11-20 21:30:20 UTC; 4min 35s ago
Main PID: 196 (gui)
CGroup: name=systemd:/system/gui.service
└ 196 /home/user/gui
Nov 20 21:30:20 systemd[1]: Starting The Qt Gui...
Nov 20 21:30:20 systemd[1]: Started The Qt Gui.
Nov 20 21:30:22 gui[196]: ARM build
However I can not interact at all with the instance of the GUI being launched using systemd! If I launch a secondary instance from the command line than I can press buttons or the touchscreen and the GUI pops up on the screen and works as expected. What gives? I've tried 'Type=forking' in the service file and this doesn't help either. Any ideas on what is wrong here? How can I get systemd to launch my Qt GUI just as if I did it from the command line? Thanks -
Thanks for the input above. It actually was not a working directory or timing issue. The problem was that my Qt GUI was not getting the proper environment variables that it needed for communicating with the touchscreen. Sourcing /etc/profile worked for me:
[Unit]
Description=The Qt Gui
After=dropbear.service
ConditionFileIsExecutable=/home/user/gui
[Service]
Type=simple
TimeoutStartSec=60
WorkingDirectory=/home/user
ExecStartPre=/bin/sh -c 'echo 127 > /sys/class/backlight/generic-bl/brightness'
ExecStart=/bin/sh -c 'source /etc/profile ; /home/user/gui -qws'
Restart=always
[Install]
WantedBy=multi-user.target
Related
I have simple console application, I want to run application as service in ubuntu.
I have created .service file in /etc/systemd/system folder HelloWorld.service as below
[Unit]
Description=HelloWorld Application
[Service]
ExecStart=/usr/share/dotnet/dotnet /home/prasadg/HelloWorld/dev/HelloWorld.dll
SyslogIdentifier=HelloWorld
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
after I saved file I have reload daemon with command
systemctl daemon-reload
then I have started newly created service systemctl start HelloWorld
it get started and nothing happens, after sometime, when I checked status using command systemctl status HelloWorld it shows error as below
HelloWorld.service - HelloWorld Application
Loaded: loaded (/etc/systemd/system/HelloWorld.service; disabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: core-dump) since Tue 2022-06-28 21:20:13 IST; 4s ago
Process: 28389 ExecStart=/usr/share/dotnet/dotnet /home/prasadg/HelloWorld/dev/HelloWorld.dll (code=dumped, signal=ABRT)
Main PID: 28389 (code=dumped, signal=ABRT)
if try run directly with command as /usr/share/dotnet/dotnet /home/prasadg/HelloWorld/dev/HelloWorld.dll it runs successfully
A full log message would help more, but I guess you need to add a WorkingDirectory to your HelloWorld.service.
I want to open a qml interface using systemd and when the user closes the window, the system automatically restarts the process to open the window again, but the interface doesn't open.
I tried this configuration:
[Unit]
Description=test
After=graphical.target
Wants=graphical.target
[Service]
Type=simple
ExecStart=~/test
Restart=on-failure
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target
Alias=test.Service
test is my binary, that runs my qml interface.
How can I do this?
Please if possible provide an example for my case.
I am looking for the command to invoke RStudio from Linux. I VNC into the linux system and don't see any other option to launch RStudio from the gnome-terminal. I know R files can be directly read in the terminal, but I searched and couldn't find any command to invoke RStudio.
Are you referring to the RStudio desktop version, or the server instance? The former is started by just calling rstudio:
edd#rob:~$ type -p rstudio
/usr/bin/rstudio
edd#rob:~$
The latter is always running and started as system process:
edd#rob:~$ systemctl status rstudio-server
● rstudio-server.service - RStudio Server
Loaded: loaded (/etc/systemd/system/rstudio-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2018-07-15 20:12:01 CDT; 1 weeks 1 days ago
Main PID: 1665 (rserver)
Tasks: 3 (limit: 4915)
CGroup: /system.slice/rstudio-server.service
└─1665 /usr/lib/rstudio-server/bin/rserver
Jul 15 20:12:00 rob systemd[1]: Starting RStudio Server...
Jul 15 20:12:01 rob systemd[1]: Started RStudio Server.
edd#rob:~$
If you want to access the latter you do not need VNC. Just point your browser at port 8787 on that machine.
Have you tried to launch it from here ?
/usr/bin/rstudio
PS : You need R to be installed on the system too.
On Arch the command is
rstudio-bin
I have created a simple Qt console application (dbus service) and I need to launch it using systemd.
However every time I execute systemctl start my_serv it fails to start the application and I end up having log in journalctl -xe indicating that application has failed to load libQt5Gui.so.5 (i'm pretty sure it is not related to this particular library):
raspberrypi systemd[1]: Started my_serv.service.
raspberrypi MyService[2812]: /opt/services/MyService: error while loading shared libraries: libQt5Gui.so.5: cannot open shared object file: No such file or directory
raspberrypi systemd[1]: my_serv.service: main process exited, code=exited, status=127/n/a
raspberrypi systemd[1]: Unit my_serv.service entered failed state.
From the other hand application launches fine when I do this from console under root user (i.e. it fails to register an object on dbus, but I think it is not relevant):
./MyService
WELCOME FROM MY SERVICE
Object was registered on dbus
Service was not registered on dbus
Qt libraries are locates by the following path:
ls -al /usr/local/qt5/lib/libQt5Gui.*
-rwxrwxrwx /usr/local/qt5/lib/libQt5Gui.la
-rwxrwxrwx /usr/local/qt5/lib/libQt5Gui.prl
lrwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so -> libQt5Gui.so.5.9.1
lrwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so.5 -> libQt5Gui.so.5.9.1
lrwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so.5.9 -> libQt5Gui.so.5.9.1
-rwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so.5.9.1
It seems that everything is fine with links to libraries in the binary. The ldd output is as follows:
ldd MyService
libQt5Gui.so.5 => /usr/local/qt5/lib/libQt5Gui.so.5 (0x76a92000)
libQt5DBus.so.5 => /usr/local/qt5/lib/libQt5DBus.so.5 (0x76a0d000)
libQt5Core.so.5 => /usr/local/qt5/lib/libQt5Core.so.5 (0x7654e000)
The service file looks like this (/etc/systemd/system/my_serv.service)
[Service]
ExecStart=/opt/services/MyService
User=root
Most probably the linker directories are not known in the context of systemctl. Try setting the environment variable LD_LIBRARY_PATH to the relevant dirs at the start of your service script; see man ld.so for details. Or look at other service scripts on your system to get an idea how the environment is correctly set there.
You can check /etc/ld.so.conf file, example the content is include ld.so.conf.d/.conf.So,you can type a new file under /etc/ld.so.conf.d/ , and put your base path of libQt.so to the file . exmaple:usr/local/qt5/lib/.
And last, execute ldconfig.
I tried to integrate Plone with a systemctl based startup (on openSUSE 12.3)
As a first attempt I have a very simple plone.service file
[Unit]
Description=Plone content management system
After=network.target
[Service]
Type=simple
ExecStart=/srv/plone/zeocluster/bin/plonectl start
[Install]
WantedBy=multi-user.target
Checking with systemclt status plone I see that the processes get started, but they immediatly vanish again. I've also tried Type=Daemon, but the endresult is the same.
Any hints were my error is?
The service actually finds/executes the plonectl script successfully, just the processes die quickly
linux-wezo:/etc/systemd/system # systemctl start plone.service
linux-wezo:/etc/systemd/system # systemctl status plone.service
plone.service - Plone content management system
Loaded: loaded (/etc/systemd/system/plone.service; disabled)
Active: inactive (dead) since Mon, 2013-03-18 22:00:50 CET; 1s ago
Process: 25494 ExecStart=/srv/plone/zeocluster/bin/plonectl start (code=exited, status=0/SUCCESS)
CGroup: name=systemd:/system/plone.service
Mar 18 22:00:42 linux-wezo.site systemd[1]: Starting Plone content management system...
Mar 18 22:00:42 linux-wezo.site systemd[1]: Started Plone content management system.
Mar 18 22:00:43 linux-wezo.site plonectl[25494]: zeoserver: .
Mar 18 22:00:43 linux-wezo.site plonectl[25494]: daemon process started, pid=25502
Mar 18 22:00:46 linux-wezo.site plonectl[25494]: client1: .
Mar 18 22:00:46 linux-wezo.site plonectl[25494]: daemon process started, pid=25507
Mar 18 22:00:49 linux-wezo.site plonectl[25494]: client2: .
Mar 18 22:00:49 linux-wezo.site plonectl[25494]: daemon process started, pid=25522
I do have a SysV style init script, that works via systemctl, but think it would be great to have a service file since this should be more generic than the various init scripts floating around.
The issue is the program plonectl is not a daemon, it is a wrapper script that starts Zope. You need to change the type to forking and probably to tell systemd where to find the PID file.
Plonectl forks the daemon. Try this in plone.service:
[Unit]
Description=Plone content management system
After=network.target
ConditionPathExists=/srv/plone/zeocluster/bin/plonectl
[Service]
Type=forking
ExecStart=/srv/plone/zeocluster/bin/plonectl start
ExecStop=/srv/plone/zeocluster/bin/plonectl stop
ExecReload=/srv/plone/zeocluster/bin/plonectl restart
[Install]
WantedBy=multi-user.target