summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--man/journalctl.xml6
-rw-r--r--shell-completion/bash/journalctl2
-rw-r--r--src/journal/journalctl.c37
3 files changed, 44 insertions, 1 deletions
diff --git a/man/journalctl.xml b/man/journalctl.xml
index ca933645a9..305f1b9412 100644
--- a/man/journalctl.xml
+++ b/man/journalctl.xml
@@ -767,6 +767,12 @@
complete.</para></listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>--rotate</option></term>
+
+ <listitem><para>Asks the Journal daemon to rotate journal files.
+ </para></listitem>
+ </varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
<xi:include href="standard-options.xml" xpointer="no-pager" />
diff --git a/shell-completion/bash/journalctl b/shell-completion/bash/journalctl
index bb2bb25deb..056cdbce70 100644
--- a/shell-completion/bash/journalctl
+++ b/shell-completion/bash/journalctl
@@ -47,7 +47,7 @@ _journalctl() {
--version --list-catalog --update-catalog --list-boots
--show-cursor --dmesg -k --pager-end -e -r --reverse
--utc -x --catalog --no-full --force --dump-catalog
- --flush'
+ --flush --rotate'
[ARG]='-b --boot --this-boot -D --directory --file -F --field
-o --output -u --unit --user-unit -p --priority
--vacuum-size --vacuum-time'
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 75e59dbd42..b42c51a29b 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -121,6 +121,7 @@ static enum {
ACTION_UPDATE_CATALOG,
ACTION_LIST_BOOTS,
ACTION_FLUSH,
+ ACTION_ROTATE,
ACTION_VACUUM,
} arg_action = ACTION_SHOW;
@@ -236,6 +237,7 @@ static void help(void) {
" --vacuum-size=BYTES Reduce disk usage below specified size\n"
" --vacuum-time=TIME Remove journal files older than specified date\n"
" --flush Flush all journal data from /run into /var\n"
+ " --rotate Request immediate rotation of the journal files\n"
" --header Show journal header information\n"
" --list-catalog Show all message IDs in the catalog\n"
" --dump-catalog Show entries in the message catalog\n"
@@ -277,6 +279,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_FORCE,
ARG_UTC,
ARG_FLUSH,
+ ARG_ROTATE,
ARG_VACUUM_SIZE,
ARG_VACUUM_TIME,
};
@@ -330,6 +333,7 @@ static int parse_argv(int argc, char *argv[]) {
{ "machine", required_argument, NULL, 'M' },
{ "utc", no_argument, NULL, ARG_UTC },
{ "flush", no_argument, NULL, ARG_FLUSH },
+ { "rotate", no_argument, NULL, ARG_ROTATE },
{ "vacuum-size", required_argument, NULL, ARG_VACUUM_SIZE },
{ "vacuum-time", required_argument, NULL, ARG_VACUUM_TIME },
{}
@@ -696,6 +700,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_action = ACTION_FLUSH;
break;
+ case ARG_ROTATE:
+ arg_action = ACTION_ROTATE;
+ break;
+
case '?':
return -EINVAL;
@@ -1769,6 +1777,30 @@ static int flush_to_var(void) {
return 0;
}
+static int rotate(void) {
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_bus_flush_close_unref_ sd_bus *bus = NULL;
+ int r;
+
+ r = bus_connect_system_systemd(&bus);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get D-Bus connection: %m");
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "KillUnit",
+ &error,
+ NULL,
+ "ssi", "systemd-journald.service", "main", SIGUSR2);
+ if (r < 0)
+ return log_error_errno(r, "Failed to kill journal service: %s", bus_error_message(&error, r));
+
+ return 0;
+}
+
int main(int argc, char *argv[]) {
int r;
_cleanup_journal_close_ sd_journal *j = NULL;
@@ -1804,6 +1836,11 @@ int main(int argc, char *argv[]) {
goto finish;
}
+ if (arg_action == ACTION_ROTATE) {
+ r = rotate();
+ goto finish;
+ }
+
if (arg_action == ACTION_SETUP_KEYS) {
r = setup_keys();
goto finish;