I've a Spring boot app, i execute it through systemd service in Ubuntu, after starting the X server with sudo startkde
, i cannot launch GUI programs from the app using command line like gedit
in the meantime it works when i launch the app using sudo java -jar demo.jar
, i've tried putting gedit
commande inside a shell script but the problem persists.
is there any solution to use the service and launch GUI programs, or launch the spring boot with another kind services that could solve the the problem.
here's the systemd service :
[Unit]
Description=demo
After=syslog.target
[Service]
User=ubuntu
ExecStart=/home/ubuntu/demo.jar --logging.file=logfile.log
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
here's the spring boot code :
@RestController
@EnableAutoConfiguration
@SpringBootApplication
public class DemoApplication {
@RequestMapping("/")
String home() {
ProcessBuilder builder = new ProcessBuilder("gedit");
builder.redirectErrorStream(true);
try {
final Process process = builder.start();
try {
process.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
systemd
isn't a good fit for auto-starting GUI apps directly. As @jaysee explained, it's not connected to particularly GUI.
What systemd can do is start a window-manager, the window manager can be set to automatically log in a particular user, and that user can use the window manager's "autostart" feature to launch the GUI app.
I went down the same path myself trying to use exclusively systemd and the other route is what I found to work.
This is a common use-case for Raspberry Pis. So if you search for tutorials about [Raspberry PI autostart kiosk], you should find a number of options (whether you are using a Raspberry Pi or not). The newer Raspberry Pis use a newer systemd-based version of Debian, so in practice it's very similar to what you want to do with Ubuntu 16.04.