Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't work with systemd #40

Open
jmhazty opened this issue Oct 11, 2017 · 2 comments
Open

can't work with systemd #40

jmhazty opened this issue Oct 11, 2017 · 2 comments

Comments

@jmhazty
Copy link

jmhazty commented Oct 11, 2017

I use systemd to manage go app.
config:
ExecReload=/bin/kill -s HUP $MAINPID

Because of pid change, systemd think process failed, and use ExecStart to start process.But process was started by endless, systemd think process start failed.

How can I use endless with systemd?

@fmpwizard
Copy link

in your service/unit file, use the parameter

PIDFile=

and specify the path to the pid file

That will help systemd work with endless

@andrewrbe
Copy link

Another option is to use Type=notify in unit file:

Description=image proxy
After=network.target

[Service]
Type=notify
ExecStart=/usr/bin/my-proxy &
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
WorkingDirectory=/etc/my-proxy/
LimitNOFILE=infinity
WatchdogSec=30s

[Install]
WantedBy=multi-user.target 

and add notify in your code: https://vincent.bernat.ch/en/blog/2017-systemd-golang

So, you call

_, _ = daemon.SdNotify(false, daemon.SdNotifyReady)
go watchdog()

on server start. Where watchdog is:

func watchdog() {
	interval, err := daemon.SdWatchdogEnabled(false)
	if err != nil || interval == 0 {
		if err != nil {
			log.Println(err)
		}
		return
	}
	for {
		daemon.SdNotify(false, daemon.SdNotifyWatchdog)
		time.Sleep(interval / 3)
	}

}

As result you have working systemctl reload command (without unnecessary process restarting) and you server is rebooted even after kill command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants