I have an application (OS is Ubuntu 16.04) that basically open the camera do some stuff with the video stream. It's managed by a systemd service:
[Unit]
Description=My Application
After=network.target
StartLimitInterval=0
[Service]
Type=simple
Restart=always
RestartSec=5
User=myuser
WorkingDirectory=/opt/foo/
ExecStart=/opt/foo/myapplication
[Install]
WantedBy=multi-user.target
Then I have a desktop entry that stop the service and re-run my application with an argument:
[Desktop Entry]
Name=Myapp
Type=Application
Exec=/opt/foo/launcher.sh
Terminal=true
Path=/opt/foo/
Categories=None;
This is my launcher:
#!/bin/bash
service myservice stop
/opt/foo/myapplication --debug
This is working, anyway I canno find a way to restart the service when I close the application launched by the desktop entry. I tried to add a service restart at the end of the launcher but it doesn't work, because when I close the terminal in which the application run, everything I presume is killed. How can I do it?