2022-08-12 07:51:59 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2022-09-16 15:42:45 +00:00
|
|
|
"github.com/kairos-io/kairos/pkg/machine/openrc"
|
|
|
|
"github.com/kairos-io/kairos/pkg/machine/systemd"
|
2022-08-12 07:51:59 +00:00
|
|
|
|
2022-09-16 15:42:45 +00:00
|
|
|
"github.com/kairos-io/kairos/pkg/machine"
|
|
|
|
"github.com/kairos-io/kairos/pkg/utils"
|
2022-08-12 07:51:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const edgevpnOpenRC string = `#!/sbin/openrc-run
|
|
|
|
|
|
|
|
depend() {
|
|
|
|
after net
|
|
|
|
provide edgevpn
|
|
|
|
}
|
|
|
|
|
|
|
|
supervisor=supervise-daemon
|
|
|
|
name="edgevpn"
|
|
|
|
command="edgevpn"
|
|
|
|
supervise_daemon_args="--stdout /var/log/edgevpn.log --stderr /var/log/edgevpn.log"
|
|
|
|
pidfile="/run/edgevpn.pid"
|
|
|
|
respawn_delay=5
|
|
|
|
set -o allexport
|
|
|
|
if [ -f /etc/environment ]; then source /etc/environment; fi
|
2022-09-16 15:42:45 +00:00
|
|
|
if [ -f /etc/systemd/system.conf.d/edgevpn-kairos.env ]; then source /etc/systemd/system.conf.d/edgevpn-kairos.env; fi
|
2022-08-12 07:51:59 +00:00
|
|
|
set +o allexport`
|
|
|
|
|
|
|
|
const edgevpnSystemd string = `[Unit]
|
|
|
|
Description=EdgeVPN Daemon
|
|
|
|
After=network.target
|
|
|
|
[Service]
|
|
|
|
EnvironmentFile=/etc/systemd/system.conf.d/edgevpn-%i.env
|
|
|
|
LimitNOFILE=49152
|
|
|
|
ExecStart=edgevpn
|
|
|
|
Restart=always
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target`
|
|
|
|
|
2022-09-16 15:42:45 +00:00
|
|
|
const EdgeVPNDefaultInstance string = "kairos"
|
2022-08-12 07:51:59 +00:00
|
|
|
|
|
|
|
func EdgeVPN(instance, rootDir string) (machine.Service, error) {
|
|
|
|
if utils.IsOpenRCBased() {
|
|
|
|
return openrc.NewService(
|
|
|
|
openrc.WithName("edgevpn"),
|
|
|
|
openrc.WithUnitContent(edgevpnOpenRC),
|
|
|
|
openrc.WithRoot(rootDir),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return systemd.NewService(
|
|
|
|
systemd.WithName("edgevpn"),
|
|
|
|
systemd.WithInstance(instance),
|
|
|
|
systemd.WithUnitContent(edgevpnSystemd),
|
|
|
|
systemd.WithRoot(rootDir),
|
|
|
|
)
|
|
|
|
}
|