add option pid

This commit is contained in:
Nick Peng
2018-06-20 23:41:47 +08:00
parent 2fec5f7e14
commit 0e72262be3
2 changed files with 9 additions and 3 deletions

View File

@@ -51,6 +51,7 @@ void help(void)
"Start smartdns server.\n"
" -f run forground.\n"
" -c [conf] config file.\n"
" -p [pid] pid file path\n"
" -h show this help message.\n"
"\n";
/* clang-format on */
@@ -251,10 +252,12 @@ int main(int argc, char *argv[])
int is_forground = 0;
int opt;
char config_file[MAX_LINE_LEN];
char pid_file[MAX_LINE_LEN];
strncpy(config_file, SMARTDNS_CONF_FILE, MAX_LINE_LEN);
strncpy(pid_file, SMARTDNS_PID_FILE, MAX_LINE_LEN);
while ((opt = getopt(argc, argv, "fhc:")) != -1) {
while ((opt = getopt(argc, argv, "fhc:p:")) != -1) {
switch (opt) {
case 'f':
is_forground = 1;
@@ -262,6 +265,9 @@ int main(int argc, char *argv[])
case 'c':
snprintf(config_file, sizeof(config_file), optarg);
break;
case 'p':
snprintf(pid_file, sizeof(pid_file), optarg);
break;
case 'h':
help();
return 1;
@@ -280,7 +286,7 @@ int main(int argc, char *argv[])
if (load_conf(config_file) != 0) {
}
if (create_pid_file(SMARTDNS_PID_FILE) != 0) {
if (create_pid_file(pid_file) != 0) {
fprintf(stderr, "create pid file failed, %s\n", strerror(errno));
goto errout;
}

View File

@@ -4,7 +4,7 @@ After=network.target
[Service]
PIDFile=/var/run/smartdns.pid
EnvironmentFile=-/etc/default/smartdns
EnvironmentFile=/etc/default/smartdns
ExecStart=/usr/sbin/smartdns $SMART_DNS_OPTS
KillMode=process
Restart=always