1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-25 02:49:52 +03:00

Create a non-forking softetherd for upstart and systemd.

Implement a daemon that expects to be invoked by a new-style init like upstart
or systemd as:

	/usr/sbin/softetherd [vpnbridge|vpnclient|vpnserver]

Alternatively, if the command line argument is empty, then use the
`SOFTETHER_MODE` environment variable instead.

Conflicts:
	src/bin/hamcore/strtable_en.stb
This commit is contained in:
Darik Horn 2014-10-03 13:30:24 -04:00
parent b9420c3bfc
commit 64dd780905
5 changed files with 147 additions and 0 deletions

View File

@ -36,6 +36,7 @@ AC_CONFIG_FILES([
src/vpnclient/Makefile src/vpnclient/Makefile
src/vpnbridge/Makefile src/vpnbridge/Makefile
src/vpncmd/Makefile src/vpncmd/Makefile
src/softetherd/Makefile
]) ])

View File

@ -27,3 +27,6 @@ SUBDIRS += libsoftether bin/hamcore
# These are the final build products. # These are the final build products.
SUBDIRS += vpnserver vpnclient vpnbridge vpncmd SUBDIRS += vpnserver vpnclient vpnbridge vpncmd
# This is a daemon for upstart and systemd.
SUBDIRS += softetherd

View File

@ -1063,6 +1063,7 @@ SVC_HIDE_TRAY_MSG This will hide the tasktray icons when starting %S in user mo
# Concerning services (UNIX) # Concerning services (UNIX)
UNIX_DAEMON_HELP SoftEther VPN non-forking daemon for upstart and systemd.\nCommand Usage:\n %S vpnbridge - Enable bridging features.\n %S vpnclient - Enable client features.\n %S vpnserver - Enable all features.\nThe parameter can be set in the SOFTETHER_MODE environment variable.\n\n
UNIX_SVC_HELP %S service program\nCopyright (c) SoftEther VPN Project. All Rights Reserved.\n\n%S command usage:\n %S start - Start the %S service.\n %S stop - Stop the %S service if the service has been already started.\n\n UNIX_SVC_HELP %S service program\nCopyright (c) SoftEther VPN Project. All Rights Reserved.\n\n%S command usage:\n %S start - Start the %S service.\n %S stop - Stop the %S service if the service has been already started.\n\n
UNIX_SVC_STARTED The %S service has been started.\n UNIX_SVC_STARTED The %S service has been started.\n
UNIX_SVC_STOPPING Stopping the %S service ...\n UNIX_SVC_STOPPING Stopping the %S service ...\n

View File

@ -0,0 +1,28 @@
# Copyright 2014 Darik Horn <dajhorn@vanadac.com>
#
# This file is part of SoftEther.
#
# SoftEther is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 2 of the License, or (at your option)
# any later version.
#
# SoftEther is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# SoftEther. If not, see <http://www.gnu.org/licenses/>.
include $(top_srcdir)/autotools/softether.am
sbin_PROGRAMS = \
softetherd
softetherd_SOURCES = \
softetherd.c
softetherd_LDADD = \
$(top_builddir)/src/libsoftether/libsoftether.la

114
src/softetherd/softetherd.c Normal file
View File

@ -0,0 +1,114 @@
// SoftEther VPN daemon for upstart and systemd.
//
// Copyright 2014 Darik Horn <dajhorn@vanadac.com>
//
// This file is part of SoftEther.
//
// SoftEther is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 2 of the License, or (at your option)
// any later version.
//
// SoftEther is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// SoftEther. If not, see <http://www.gnu.org/licenses/>.
#include <GlobalConst.h>
#define VPN_EXE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
#include <stdarg.h>
#include <time.h>
#include <Mayaqua/Mayaqua.h>
#include <Cedar/Cedar.h>
void DaemonUsage(char *name)
{
UniPrint(_UU("UNIX_DAEMON_HELP"), name, name, name);
}
void DaemonStartProcess()
{
// This environment variable is exported by upstart.
char *upstart_job = getenv("UPSTART_JOB");
InitCedar();
StInit();
StStartServer(false);
// Notify upstart that softetherd is ready.
if (upstart_job != NULL)
{
unsetenv("UPSTART_JOB");
raise(SIGSTOP);
}
}
void DaemonStopProcess()
{
StStopServer();
StFree();
FreeCedar();
}
int main(int argc, char *argv[])
{
// This environment variable is sourced and exported by the init process from /etc/default/softether.
char *softether_mode = getenv("SOFTETHER_MODE");
InitMayaqua(false, false, argc, argv);
// Check for an explicit invocation. (eg: "/usr/sbin/softetherd vpnserver")
if (argc >= 2)
{
if (StrCmpi(argv[1], "vpnbridge") == 0
|| StrCmpi(argv[1], "vpnclient") == 0
|| StrCmpi(argv[1], "vpnserver") == 0)
{
UnixExecService(argv[1], DaemonStartProcess, DaemonStopProcess);
FreeMayaqua();
return 0;
}
// Exit status codes 150..199 are reserved for the application by the LSB.
fprintf(stderr, "Error: Unrecognized parameter: %s\n", argv[1]);
fflush(stderr);
FreeMayaqua();
return 150;
}
// Alternatively, use the environment variable.
if (softether_mode != NULL)
{
if (StrCmpi(softether_mode, "vpnbridge") == 0
|| StrCmpi(softether_mode, "vpnclient") == 0
|| StrCmpi(softether_mode, "vpnserver") == 0)
{
UnixExecService(softether_mode, DaemonStartProcess, DaemonStopProcess);
FreeMayaqua();
return 0;
}
// Exit status codes 150..199 are reserved for the application by the LSB.
fprintf(stderr, "Error: Unrecognized environment variable: SOFTETHER_MODE=%s\n", softether_mode);
fflush(stderr);
FreeMayaqua();
return 151;
}
DaemonUsage(argv[0]);
FreeMayaqua();
return 3;
}