--- freem/src/fmadm.c 2025/04/01 23:21:45 1.22
+++ freem/src/fmadm.c 2025/04/03 01:41:02 1.29
@@ -1,5 +1,5 @@
/*
- * $Id: fmadm.c,v 1.22 2025/04/01 23:21:45 snw Exp $
+ * $Id: fmadm.c,v 1.29 2025/04/03 01:41:02 snw Exp $
* FreeM Administration Tool
*
*
@@ -24,6 +24,27 @@
* along with FreeM. If not, see .
*
* $Log: fmadm.c,v $
+ * Revision 1.29 2025/04/03 01:41:02 snw
+ * New features frozen; prepare 0.63.0-rc1
+ *
+ * Revision 1.28 2025/04/02 19:59:38 snw
+ * Automatically modify env.conf from fmadm reconfigure
+ *
+ * Revision 1.27 2025/04/02 15:36:25 snw
+ * Do extensive result checking for environment stop/start/restart in fmadm
+ *
+ * Revision 1.26 2025/04/02 14:37:57 snw
+ * Improve environment control parts of fmadm
+ *
+ * Revision 1.25 2025/04/02 04:50:49 snw
+ * Allow vendor routines to be upgraded
+ *
+ * Revision 1.24 2025/04/02 03:02:42 snw
+ * Stop requiring users to pass -e to fmadm when -u or -g are passed
+ *
+ * Revision 1.23 2025/04/02 02:16:27 snw
+ * Add fmadm status environment command and move journals to a better location
+ *
* Revision 1.22 2025/04/01 23:21:45 snw
* fmadm commands for stopping, starting, and restarting environments now functional
*
@@ -156,6 +177,7 @@ extern char config_file[4096];
extern char env_config_file[4096];
extern char env_user[255];
extern char env_group[255];
+extern char env_enabled[10];
int fm_shell(void);
void fm_checkperms(void);
@@ -165,6 +187,7 @@ int fm_daemonctl (short action, short ob
void fm_write (FILE *file, char *buf);
int fma_jobs_remove (int optc, char **opts);
void set_permissions(char *path, char *user, char *grp, int mode);
+int fm_environment_running (char *env);
extern int read_profile_string(char *file, char *section, char *key, char *value);
int main (int argc, char **argv)
@@ -185,6 +208,7 @@ int main (int argc, char **argv)
short got_action = FALSE;
short got_object = FALSE;
+ strcpy (env_enabled, "true");
/* snprintf (config_file, 4096, "%s/freem.conf", SYSCONFDIR); */
@@ -227,7 +251,6 @@ int main (int argc, char **argv)
env_user[k++] = argv[i][j];
}
- fma_explicit_environment = TRUE;
base_arg++;
break;
@@ -245,7 +268,6 @@ int main (int argc, char **argv)
env_group[k++] = argv[i][j];
}
- fma_explicit_environment = TRUE;
base_arg++;
break;
@@ -273,6 +295,31 @@ int main (int argc, char **argv)
base_arg++;
break;
+
+ case 'E':
+ if (argv[i][2] != '=') {
+ fprintf (stderr, "fmadm: missing equals sign in flag -%c\n", argv[i][1]);
+ fmadm_usage ();
+ exit (1);
+ }
+
+ k = 0;
+
+ for (j = 3; j < strlen (argv[i]); j++) {
+ env_enabled[k++] = argv[i][j];
+ }
+ env_enabled[k] = '\0';
+
+ if ((strcmp (env_enabled, "true") != 0) && (strcmp (env_enabled, "false") != 0)) {
+ fprintf (stderr, "fmadm: -E (environment enabled) option must be either 'true' or 'false'\n");
+ fmadm_usage ();
+ exit (1);
+ }
+
+ base_arg++;
+
+ break;
+
case 'n':
if (argv[i][2] != '=') {
@@ -295,7 +342,7 @@ int main (int argc, char **argv)
}
}
}
-
+
if (obj != OBJ_DAEMON) {
if (strlen (env_user) == 0) {
snprintf (env_user, 6, "freem");
@@ -314,10 +361,10 @@ int main (int argc, char **argv)
snprintf (env_config_file, 4096, "%s/freem/env.conf", SYSCONFDIR);
- /*
+/*
printf ("action = '%s' object = '%s' environment = '%s' namespace = '%s' config_file = '%s' base_arg = '%d' next argument = '%s'\n", action, obj_str, fma_environment, fma_namespace, config_file, base_arg, argv[base_arg]);
exit(1);
- */
+*/
/* override for fmadm configure and daemon stuff */
if (got_action) {
@@ -332,18 +379,24 @@ int main (int argc, char **argv)
else if (strcmp (argv[1], "start") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_START;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
}
else if (strcmp (argv[1], "stop") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_STOP;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
}
else if (strcmp (argv[1], "restart") == 0 && strcmp (argv[2], "environment") == 0) {
act = ACT_RESTART;
obj = OBJ_DAEMON;
- goto act_switch;
+ goto process_args;
+ }
+ else if (strcmp (argv[1], "status") == 0 && strcmp (argv[2], "environment") == 0) {
+ act = ACT_STATUS;
+ obj = OBJ_DAEMON;
+ goto process_args;
}
+
}
pid = getpid ();
@@ -364,7 +417,8 @@ int main (int argc, char **argv)
}
set_namespace (fma_namespace, FALSE);
-
+
+process_args:
/* allocate opts array */
/* first dimension */
@@ -387,7 +441,8 @@ int main (int argc, char **argv)
j = 1;
for (i = base_arg; i < argc; i++) {
- if (i > FMA_MAXARGS) return fmadm_usage(); /* bail if we're going to overrun the array */
+ if (i > FMA_MAXARGS) return fmadm_usage();
+ /* bail if we're going to overrun the array */
strncpy (opts[j++], argv[i], STRLEN - 1);
}
@@ -407,10 +462,10 @@ int main (int argc, char **argv)
else if (strncmp (action, "start", STRLEN - 1) == 0) act = ACT_START;
else if (strncmp (action, "stop", STRLEN - 1) == 0) act = ACT_STOP;
else if (strncmp (action, "restart", STRLEN - 1) == 0) act = ACT_RESTART;
+ else if (strncmp (action, "status", STRLEN - 1) == 0) act = ACT_STATUS;
else return fmadm_usage();
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK;
- else if (strncmp (obj_str, "zallocate", STRLEN - 1) == 0) obj = OBJ_ZALLOC;
else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL;
else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE;
else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL;
@@ -514,6 +569,7 @@ act_switch:
case ACT_START:
case ACT_STOP:
case ACT_RESTART:
+ case ACT_STATUS:
fmadm_exit (fm_daemonctl (act, obj, optc, opts));
default:
@@ -667,7 +723,6 @@ int fm_shell (void)
strcpy (obj_str, args[0]);
if (strncmp (obj_str, "lock", STRLEN - 1) == 0) obj = OBJ_LOCK;
- else if (strncmp (obj_str, "zallocate", STRLEN - 1) == 0) obj = OBJ_ZALLOC;
else if (strncmp (obj_str, "journal", STRLEN - 1) == 0) obj = OBJ_JOURNAL;
else if (strncmp (obj_str, "namespace", STRLEN - 1) == 0) obj = OBJ_NAMESPACE;
else if (strncmp (obj_str, "global", STRLEN - 1) == 0) obj = OBJ_GLOBAL;
@@ -860,18 +915,17 @@ void fmadm_exit (int retval)
int fmadm_usage (void)
{
- fprintf (stdout, "\nusage: fmadm