1
I'd like to run a Java backend program on startup (in fact it may be on user login) with systemd, which would use X server to create a render window in memory. The render window is created by VTK to do volume rendering with a GPU, and I'll get screen shots from it.
the following is my service file I put in /etc/systemd/system
directory.
[Unit]
Description= myservice
After=mysql.service
[Service]
User=root
Environment=DISPLAY=:0
Restart=always
Type=forking
ExecStart=/root/myservice/startup.sh
ExecStop=/root/myservice/shutdown.sh
[Install]
WantedBy=multi-user.target
after I login by GUI, the service doesn't get started. so I execute command xhost +
to let all user access to display and run systemctl start myservice
to start service manually. Then I get what I want.
I'm wondering if there's any way to let myservice run automatically on login. And another question, is that ok to set environment to a fixed DISPLAY number for all computers?
I'm using Ubuntu 16.04/18.04.
1Does it really have to run as root? Is it an app or a service? (Or is it both? That would be incredibly poor architecture.) – user1686 – 2019-07-18T10:14:33.197
it's a service. we put all program files under /root/ dierctory, code protection may be one reason i think. – clementstone – 2019-07-18T10:18:01.727
Well, it's not about it being under /root/ directory, it's about it using User=root ... Does the program require root privileges for its regular operations (aside from this "code protection")? Basically I'm trying to figure out how to combine two contradictory requirements here. – user1686 – 2019-07-18T10:22:17.357
And – what's this "render window" for? I mean, is it supposed to actually show something on screen to the logged-in user, or is it only for processing? (In other words, does it require Xorg with a real GPU, or could it use Xdummy or Xvfb?) – user1686 – 2019-07-18T10:22:25.047
sorry to reply late. i think it's not necessary to require root privileges for regular operations. the render window here is created by VTK to do volume rendering with gpu, and it will get screen shots from it as outputs of the running service. – clementstone – 2019-07-19T04:56:56.717