0

I have a software written in C language which opens a UDP socket to my server through internet.

I use a systemd service approach to run the code at startup. It works fine. But in some cases which I use it in some networks (specially an organization or company network), code runs at OS startup but it can't open socket. When I manually stop and start it using systemctl command in root access all things is OK.

I put a delay in the code, but the issue still exists

0

If your program fails to open a UDP socket when started with systemd, it sounds like it is started too early. Make sure the network is up before starting this service.

You can do that by adding this to your service file:

[Unit]
After=network.target
1
  • you are right, but your recommendation couldn't solve the issue. I will tell the solution in a new post. thank you. – King May 17 '20 at 12:40
0

@Stewart thinks right. I added this in my service file:

After=syslog.target network.target sockets.target network-online.target multi-user.target

It causes to the service starts later and the issue is resolves.

1
  • I think multi-user.target element plays the main rule. – King May 17 '20 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.