You are not logged in.

#1 2015-02-10 02:34:00

VanIsland
Member
Registered: 2014-01-14
Posts: 2

Autostarted Java program has no access to network

My project requires a headless unattended server, which runs an SSH server and a Java program. I have created a service which points to a shell file which in turn starts the java program. This part is working fine. The Java program starts up and runs. The problem is that the Java program, when started this way, is not getting access to the network, although it works fine when started manually by a logged in user. Since a program started as a service is not associated with a user, I wonder if this is a problem? Is this the best way to go about getting a Java program to start on bootup?
Thanks!

Offline

#2 2015-02-10 02:41:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: Autostarted Java program has no access to network

If it needs to run as a user, then run it as the proper user:

man systemd.exec wrote:

User=, Group=
           Sets the Unix user or group that the processes are executed as, respectively. Takes a single user or group name or ID as argument. If no group is set, the default group of the user is chosen.

But I suspect the real problem is that when run from the logged-in user session, /etc/profile.d/jre.sh has been sourced.  So for a service, you'd likely need to add the PATH environment variable.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2015-02-10 20:18:53

VanIsland
Member
Registered: 2014-01-14
Posts: 2

Re: Autostarted Java program has no access to network

Adding User= to the [Exec] section solved the problem. Since the program was otherwise working when started as a service, I suspected the problem was not the path.
Thanks!

Offline

Board footer

Powered by FluxBB