pull/230/head
Ryan Tharp 6 years ago
commit cf434ef3da

@ -0,0 +1,20 @@
#!/bin/sh
. /etc/rc.subr
name=lokinet
rcvar=lokinet_enable
command="/usr/local/bin/${name}"
command_args="/usr/local/etc/${name}/daemon.ini > /dev/null 2>&1"
pidfile="/usr/local/etc/${name}/lokinet.pid"
required_files="/usr/local/etc/${name}/daemon.ini"
sig_reload="HUP"
start_precmd="${command} -g /usr/local/etc/${name}/daemon.ini"
load_rc_config $name
run_rc_command "$1"

@ -65,6 +65,16 @@ namespace llarp
HandleSignal(int sig);
private:
void
SetPIDFile(const std::string & fname);
bool
WritePIDFile() const;
void
RemovePIDFile() const;
bool
Configure();
@ -82,6 +92,7 @@ namespace llarp
progress();
std::string configfile;
std::string pidfile;
};
} // namespace llarp

@ -153,6 +153,7 @@ llarp_generic_ensure_config(std::ofstream &f, std::string basepath)
f << "# ";
#endif
f << "group=" << DEFAULT_LOKINET_GROUP << std::endl;
f << "pidfile=" << basepath << "lokinet.pid" << std::endl;
f << std::endl << std::endl;
f << "# dns provider configuration section" << std::endl;

@ -53,6 +53,13 @@ namespace llarp
const char *key, const char *val)
{
Context *ctx = static_cast< Context * >(itr->user);
if(!strcmp(section, "system"))
{
if(!strcmp(key, "pidfile"))
{
ctx->SetPIDFile(val);
}
}
if(!strcmp(section, "router"))
{
if(!strcmp(key, "worker-threads") && !ctx->singleThreaded)
@ -81,6 +88,12 @@ namespace llarp
}
}
void
Context::SetPIDFile(const std::string & fname)
{
pidfile = fname;
}
int
Context::LoadDatabase()
{
@ -174,9 +187,12 @@ namespace llarp
llarp::LogError("cannot run non configured context");
return 1;
}
if(!WritePIDFile())
return 1;
// run
if(!router->Run(nodedb))
return 1;
// run net io thread
llarp::LogInfo("running mainloop");
llarp_ev_loop_run_single_process(mainloop, worker, logic);
@ -184,6 +200,34 @@ namespace llarp
return 0;
}
bool
Context::WritePIDFile() const
{
if(pidfile.size())
{
std::ofstream f(pidfile);
f << std::to_string(getpid());
return f.good();
}
else
return true;
}
void
Context::RemovePIDFile() const
{
if(pidfile.size())
{
fs::path f = pidfile;
std::error_code ex;
if(fs::exists(f, ex))
{
if(!ex)
fs::remove(f);
}
}
}
void
Context::HandleSignal(int sig)
{
@ -277,6 +321,7 @@ namespace llarp
delete logic;
logic = nullptr;
}
RemovePIDFile();
}
bool

Loading…
Cancel
Save