How can we launch a process through systemd on method_call on some session dbus - dbus

I have one agent service (org.bluez.map_agent)
[D-BUS Service]
Name=org.bluez.map_agent
Exec=echo "Hello"
SystemdService=bluetooth-map-agent.service
Content of bluetooth-map-agent.service
[Unit]
Description=launch MAP agent.
[Service]
User=app
ExecStart=/usr/bin/map-agent
ExecStop=/usr/bin/killall map-agent
KillMode=process
[Install]
WantedBy=multi-user.target
But when dbus call happens my map-agent is not getting launched, what could be the reason?

Make your service to launch by systemd itself when the required bus is created by dbus. This can be achieved using below service file:
[Unit]
Description=launch MAP agent.
[Service]
Type=dbus
User=app
BusName=org.bluez.map_agent
ExecStart=/usr/bin/map-agent
ExecStop=/usr/bin/killall map-agent
KillMode=process
[Install]
WantedBy=multi-user.target
And enable your service file using systemctl enable xyz.service
Systemd will wait for bus-name to acquire on dbus, only then service will be activated.

Related

error on start nginx service on ubuntu vps

i am begginer user of vps, i have a reactJS app, and i wnat to deploy it on my ubuntu 18 vps with nginx.
I have followed the stpes of this tutorial Deploying create-react-app with Nginx and Ubuntu
i had already check all the steps, but when i put the command
sudo service nginx start
the system show's me, the next error message:
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
and when i put "journalctl -xe" shows me this:
nginx, error
ngnix, error
please help me friends
Look in your log file on messages before the error "Failed to startup nginx"
You will see the reason of problem.
bind() to 0.0.0.0:80 failed (98: Address already in use)
Looks like port 80 on your vps server is already in use by some application.
Port 80 used for HTTP services.
So most likely you already have run Apache HTTP server, or some other.
use this command to see what application use it
sudo netstat -tulpn | grep ":80"
If you see apache
tcp6 0 0 :::80 :::* LISTEN 349/apache2
then you can stop apache
# apache service name also can be httpd (use right command)
# sudo service httpd stop
sudo service apache stop
and run nginx
sudo service nginx start
But you should be sure that you don't use apache for another website.

systemd ignores services from overlayFS

I want to build a system with applications on another partition, an app-filessystem. All binaries, configs and service files which belong to the application should be in the app-fs.
I'm using the following versions: kernel 4.9.x, systemd v234.
The app-partition is mounted at /opt, this includes following files:
/opt/usr/bin/app-binary
/opt/etc/systemd/system/multiuser.target/link_2_app.service
/opt/lib/systemd/system/app.service
Here is the service file:
[Unit]
Description=The application description.
After=syslog.target basic.target
[Service]
ExecStart=/opt/usr/bin/app-binary
Type=simple
[Install]
WantedBy=multi-user.target
To synchronize the files with rootfilesystem I created 2 overlays, this could be the /etc/fstab entries (sorry for format, one line didn't work):
/dev/app-partition /opt auto defaults,x-systemd.mount 0 2
overlay /etc overlay defaults,x-systemd.mount, x-systemd.after=opt.mount,lowerdir=/etc,upperdir=/opt/etc,workdir=/work/etc 0 2
overlay /lib/systemd/system overlay defaults,x-systemd.mount,x-systemd.after=opt.mount,lowerdir=/lib/systemd/system,upperdir=/opt/lib/systemd/system,workdir=/work/lib 0 2
This is handled before local-fs.target is reached.
Result
I can start the app successfully but manually with systemctl start app.service. The status with "systemctl status app.service" says it is enabled. But the app is not starting at boot time. Systemd does not give a message about trying to start the app.
Questions
Is there a way to debug this behaviour? When does systemd check the service files? Is there a way to trigger it again? Are there other ways to handle this use case with systemd?
systemd is checking the unit files once at start, an init script which is creating the overlayFS before systemd startup can handle this use case.
Another idea (but not tested) would be: systemctl daemon-reload
systemctl daemon-reload
I test this not work.
In my situation . I use systemd-networkd,and I overlay
For disabling autostart of services seems using
ConditionPathIsSymbolicLink=#OVERLAY_UPPER_LAYER#/etc/systemd/system/../XX.service
as additional condition in service drop-in works

Systemd Service status remains running even after ExecStart process not present in centos 7.3

I have created a systemd service like way any interruption triggered to running process then it has to restart itself. but service shows its status as running (Used systemctl status x.service) even after process is exited (which is mentioned in exec_start).
Below is my service script
{
[Unit]
Description=xserverd
After=syslog.target rsyslog-x.service systemd-modules-load.service
Requires=rsyslog-x.service systemd-modules-load.service
[Service]
Type=forking
ExecStart=/opt/bin/xserver
Restart=always
RestartSec=2s
RemainAfterExit=no
RestartPreventExitStatus=SIGINT
KillMode=process
TimeoutSec=300s
[Install]
WantedBy=multi-user.target
}
/opt/bin/xserver is a C executable which 777 permission. Added signal handler for SIGINT and SIGSEGV. SIGINT is to say proper exit from user. SIGSEGV to log backtrace to our custom log file. Whenever process receives these signals it will exit with
{
exit(EXIT_FAILURE)
}
For Type=forking, systemd assume the child or child of child of the start command is the daemon process.
Change it to simple if your daemon does not go this way.

Using gdbus to start a systemd service

I've created a new systemd service that I would like to be able to active via a dbus call. The service simply executes a shell script.
I've defined the service here:
/lib/systemd/system/testamundo.service
[Unit]
Description=Testamundo
[Service]
Type=dbus
BusName=org.freedesktop.testamundo
ExecStart=/home/test/systemd/testamundo.sh
I've also defined a D-Bus service for it here:
/usr/share/dbus-1/system-services
[D-BUS Service]
Name=org.freedesktop.testamundo
Exec=/usr/sbin/console-kit-daemon --no-daemon
User=root
SystemdService=testamundo.service
I am attempting to start it using gdbus, this is the command I'm trying to use:
sudo gdbus call --system --dest org.freedesktop.systemd1 --object-path /org/freedesktop/systemd1 --method org.freedesktop.systemd1.StartUnit "org.freedesktop.testamundo"
If I use --system as I did above the command returns with an Unknown Method error, if I use --session it returns with an exit code 1 from the child process. When I look at journalctl with --session and --system I can see the command, but beyond that no additional information.
Appreciate any thoughts or advice, thanks!
Your dbus command is using non-existing interfaces. First of all it is org.freedesktop.systemd1.Manager.Start unit not org.freedesktop.systemd1.StartUnit. Second, org.freedesktop.systemd1.Manager.Start needs 2 parameters, service name and start mode. Ref: http://www.freedesktop.org/wiki/Software/systemd/dbus/
You have defined a dbus service but you are bypassing dbus by directly asking systemd to activate the service. Other note is, dbus actually sends a signal to systemd not a method call.
You have everything in place, if you just do an introspection on your service, it should be activate.
sudo gdbus call --system --dest org.freedesktop.testamundo --object-path /org/freedesktop/testamundo --method org.freedesktop.DBus.Introspectable. Introspect

X11: Start desktop manager inside daemon

What I'm trying to do:
Make screenshots of desktop and running program (Firefox Webdriver with Selenium, if it's important) in daemon (celeryd) in auto mode.
And I need desktop manager to be running, this is mandatory requirement. Currently I'm trying to use Fluxbox but I can switch to any other manager.
Current progress:
I can start X-server (Xvfb) in daemon and start Selenium Webdriver. Fluxbox start succeeds when I try to make it from terminal, but fails in daemon with following errors in log:
Can't create directory
Failed to load database:
Failed to load database:/init
Retrying with: /etc/X11/fluxbox/init
I tried to specify init-file directly, but Can't create directory error still exists and Fluxbox fails to start.
This might be daemon-mode restriction.
Question:
Is it possible to run any desktop manager inside daemon?
If yes, then how can I do this?

Resources