Created
February 23, 2024 00:32
-
-
Save oskarirauta/59ad0493b8a606b7bcc0b72b6dbc470a to your computer and use it in GitHub Desktop.
add restart function uxc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- a/uxc.c | |
+++ b/uxc.c | |
@@ -82,6 +82,7 @@ enum uxc_cmd { | |
CMD_DISABLE, | |
CMD_DELETE, | |
CMD_CREATE, | |
+ CMD_RESTART, | |
CMD_UNKNOWN | |
}; | |
@@ -124,6 +125,7 @@ static int usage(void) { | |
printf("\tstart [--console] <conf>\t\tstart container <conf>\n"); | |
printf("\tstate <conf>\t\t\t\tget state of container <conf>\n"); | |
printf("\tkill <conf> [<signal>]\t\t\tsend signal to container <conf>\n"); | |
+ printf("\trestart [--console] <conf> [<signal>]\trestart container <conf>\n"); | |
printf("\tenable <conf>\t\t\t\tstart container <conf> on boot\n"); | |
printf("\tdisable <conf>\t\t\t\tdon't start container <conf> on boot\n"); | |
printf("\tdelete <conf> [--force]\t\t\tdelete <conf>\n"); | |
@@ -1600,6 +1602,8 @@ int main(int argc, char **argv) | |
cmd = CMD_STATE; | |
else if(!strcmp("kill", argv[optind]) || !strcmp("stop", argv[optind])) | |
cmd = CMD_KILL; | |
+ else if(!strcmp("restart", argv[optind])) | |
+ cmd = CMD_RESTART; | |
else if(!strcmp("enable", argv[optind])) | |
cmd = CMD_ENABLE; | |
else if(!strcmp("disable", argv[optind])) | |
@@ -1649,6 +1653,39 @@ int main(int argc, char **argv) | |
ret = uxc_start(argv[optind + 1], console); | |
break; | |
+ | |
+ case CMD_RESTART: | |
+ if (optind == (argc - 3)) | |
+ signal = atoi(argv[optind + 2]); | |
+ else if (optind != argc - 2) | |
+ goto usage_out; | |
+ | |
+ uxc_kill(argv[optind + 1], signal); | |
+ | |
+ runtime_free(); // poll runtime | |
+ sleep(1); | |
+ runtime_load(); | |
+ | |
+ ret = uxc_exists(argv[optind + 1]); | |
+ if (ret) | |
+ goto runtime_out; | |
+ | |
+ ret = uxc_set(argv[optind + 1], bundle, autostart, pidfile, tmprwsize, writepath, requiredmounts); | |
+ if (ret < 0) | |
+ goto runtime_out; | |
+ else if (ret > 0) | |
+ reload_conf(); | |
+ | |
+ ret = uxc_create(argv[optind + 1], false); | |
+ if (ret != 0) | |
+ goto runtime_out; | |
+ | |
+ runtime_free(); // poll runtime again | |
+ sleep(1); | |
+ runtime_load(); | |
+ | |
+ ret = uxc_start(argv[optind + 1], console); | |
+ break; | |
case CMD_STATE: | |
if (optind != argc - 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment