8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright 2015, Joyent, Inc. All rights reserved.
28 */
29
30 /*
31 * svcadm - request adminstrative actions for service instances
32 */
33
34 #include <locale.h>
35 #include <libintl.h>
36 #include <libscf.h>
37 #include <libscf_priv.h>
38 #include <libcontract.h>
39 #include <libcontract_priv.h>
40 #include <sys/contract/process.h>
41 #include <libuutil.h>
42 #include <stddef.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <string.h>
46 #include <unistd.h>
47 #include <fcntl.h>
1914 static int
1915 force_degraded(void *data, scf_walkinfo_t *wip)
1916 {
1917 int flags = (int)data;
1918 char state[MAX_SCF_STATE_STRING_SZ];
1919
1920 if (inst_get_state(wip->inst, state, wip->fmri, NULL) != 0) {
1921 exit_status = 1;
1922 return (0);
1923 }
1924
1925 if (svcsearch && strcmp(state, svcstate) != 0)
1926 return (0);
1927
1928 if (strcmp(state, SCF_STATE_STRING_ONLINE) != 0) {
1929 uu_warn(gettext("Instance \"%s\" is not online.\n"), wip->fmri);
1930 exit_status = 1;
1931 return (0);
1932 }
1933
1934 set_inst_action(wip->fmri, wip->inst, (flags & MARK_IMMEDIATE) ?
1935 SCF_PROPERTY_DEGRADE_IMMEDIATE : SCF_PROPERTY_DEGRADED);
1936
1937 return (0);
1938 }
1939
1940 static int
1941 force_maintenance(void *data, scf_walkinfo_t *wip)
1942 {
1943 int flags = (int)data;
1944 const char *prop;
1945
1946 if (svcsearch) {
1947 char state[MAX_SCF_STATE_STRING_SZ];
1948
1949 if (inst_get_state(wip->inst, state, wip->fmri, NULL) != 0)
1950 return (0);
1951 if (strcmp(state, svcstate) != 0)
1952 return (0);
1953 }
2490
2491 ++optind;
2492
2493 while ((o = getopt(argc, argv, "It")) != -1) {
2494 if (o == 'I')
2495 flags |= MARK_IMMEDIATE;
2496 else if (o == 't')
2497 flags |= MARK_TEMPORARY;
2498 else if (o == '?')
2499 usage();
2500 else {
2501 assert(0);
2502 abort();
2503 }
2504 }
2505
2506 if (argc - optind < 2)
2507 usage();
2508
2509 if (strcmp(argv[optind], "degraded") == 0) {
2510 if (flags & MARK_TEMPORARY)
2511 uu_xdie(UU_EXIT_USAGE, gettext("-t may not be "
2512 "used with degraded.\n"));
2513 callback = force_degraded;
2514
2515 } else if (strcmp(argv[optind], "maintenance") == 0) {
2516 callback = force_maintenance;
2517 } else {
2518 usage();
2519 }
2520
2521 optind++;
2522 argc -= optind;
2523 argv += optind;
2524
2525 if (argc == 0 && !svcsearch)
2526 usage();
2527
2528 if (argc > 0 && svcsearch)
2529 usage();
2530
2531 if ((err = scf_walk_fmri(h, argc, argv, WALK_FLAGS, callback,
2532 NULL, &exit_status, pr_warn)) != 0) {
2533 pr_warn(gettext("failed to iterate over "
2534 "instances: %s\n"),
2535 scf_strerror(err));
2536 exit_status = UU_EXIT_FATAL;
2537 }
2538
2539 } else if (strcmp(argv[optind], "clear") == 0) {
2540 ++optind;
2541 argc -= optind;
2542 argv += optind;
2543
2544 if (argc == 0 && !svcsearch)
2545 usage();
2546
2547 if (svcsearch) {
2548 if (argc > 0)
2549 usage();
2550 if (strcmp(svcstate, SCF_STATE_STRING_MAINT) != 0 &&
2551 strcmp(svcstate, SCF_STATE_STRING_DEGRADED) != 0)
2552 uu_die(gettext("State must be '%s' or '%s'\n"),
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /*
27 * Copyright 2015, Joyent, Inc. All rights reserved.
28 * Copyright 2017 RackTop Systems.
29 */
30
31 /*
32 * svcadm - request adminstrative actions for service instances
33 */
34
35 #include <locale.h>
36 #include <libintl.h>
37 #include <libscf.h>
38 #include <libscf_priv.h>
39 #include <libcontract.h>
40 #include <libcontract_priv.h>
41 #include <sys/contract/process.h>
42 #include <libuutil.h>
43 #include <stddef.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47 #include <unistd.h>
48 #include <fcntl.h>
1915 static int
1916 force_degraded(void *data, scf_walkinfo_t *wip)
1917 {
1918 int flags = (int)data;
1919 char state[MAX_SCF_STATE_STRING_SZ];
1920
1921 if (inst_get_state(wip->inst, state, wip->fmri, NULL) != 0) {
1922 exit_status = 1;
1923 return (0);
1924 }
1925
1926 if (svcsearch && strcmp(state, svcstate) != 0)
1927 return (0);
1928
1929 if (strcmp(state, SCF_STATE_STRING_ONLINE) != 0) {
1930 uu_warn(gettext("Instance \"%s\" is not online.\n"), wip->fmri);
1931 exit_status = 1;
1932 return (0);
1933 }
1934
1935 if ((flags & MARK_TEMPORARY) == 0) {
1936 uu_warn(gettext("Instance \"%s\" cannot be degraded "
1937 "permantently.\n"), wip->fmri);
1938 exit_status = 1;
1939 return (0);
1940 }
1941
1942 set_inst_action(wip->fmri, wip->inst, (flags & MARK_IMMEDIATE) ?
1943 SCF_PROPERTY_DEGRADE_IMMEDIATE : SCF_PROPERTY_DEGRADED);
1944
1945 return (0);
1946 }
1947
1948 static int
1949 force_maintenance(void *data, scf_walkinfo_t *wip)
1950 {
1951 int flags = (int)data;
1952 const char *prop;
1953
1954 if (svcsearch) {
1955 char state[MAX_SCF_STATE_STRING_SZ];
1956
1957 if (inst_get_state(wip->inst, state, wip->fmri, NULL) != 0)
1958 return (0);
1959 if (strcmp(state, svcstate) != 0)
1960 return (0);
1961 }
2498
2499 ++optind;
2500
2501 while ((o = getopt(argc, argv, "It")) != -1) {
2502 if (o == 'I')
2503 flags |= MARK_IMMEDIATE;
2504 else if (o == 't')
2505 flags |= MARK_TEMPORARY;
2506 else if (o == '?')
2507 usage();
2508 else {
2509 assert(0);
2510 abort();
2511 }
2512 }
2513
2514 if (argc - optind < 2)
2515 usage();
2516
2517 if (strcmp(argv[optind], "degraded") == 0) {
2518 callback = force_degraded;
2519 } else if (strcmp(argv[optind], "maintenance") == 0) {
2520 callback = force_maintenance;
2521 } else {
2522 usage();
2523 }
2524
2525 optind++;
2526 argc -= optind;
2527 argv += optind;
2528
2529 if (argc == 0 && !svcsearch)
2530 usage();
2531
2532 if (argc > 0 && svcsearch)
2533 usage();
2534
2535 if ((err = scf_walk_fmri(h, argc, argv, WALK_FLAGS, callback,
2536 (void *)flags, &exit_status, pr_warn)) != 0) {
2537 pr_warn(gettext("failed to iterate over "
2538 "instances: %s\n"),
2539 scf_strerror(err));
2540 exit_status = UU_EXIT_FATAL;
2541 }
2542
2543 } else if (strcmp(argv[optind], "clear") == 0) {
2544 ++optind;
2545 argc -= optind;
2546 argv += optind;
2547
2548 if (argc == 0 && !svcsearch)
2549 usage();
2550
2551 if (svcsearch) {
2552 if (argc > 0)
2553 usage();
2554 if (strcmp(svcstate, SCF_STATE_STRING_MAINT) != 0 &&
2555 strcmp(svcstate, SCF_STATE_STRING_DEGRADED) != 0)
2556 uu_die(gettext("State must be '%s' or '%s'\n"),
|