You are not logged in.
Hello,
Pretty much what the title says, I want to run a process which runs outside of systemd. The reason I want to do this is because I have a scheduled task which runs quite frequently and it is polluting the journal/logs. Setting standard output and error to /dev/null is not good enough because the start and stop of the unit itself produces several lines of output in the log.
Thanks for any help in advance!
Offline
So what does this have to do with a "secondary init process"? And what other init were you planning on using?
You really can't have two init process. You can - theoretically - run two service managers - but that too seems unrelated to your description.
How do you intend to run this scheduled task? If you run it as a cron job, then your cron implementation can be run from systemd and it's logs sent to /dev/null or wherever else - the starting and stopping of the child process would then not be in the journal at all.
EDIT: I suppose you can run a second init if you launch a virtual machine, nspawn, or perhaps some other containers. But that too seems entirely tangential to the stated goals.
Last edited by Trilby (2022-05-02 03:52:58)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Online
So what does this have to do with a "secondary init process"? And what other init were you planning on using?
A secondary process would not pollute systemd's logs ![]()
I am not planning to run another init system (like systemd, OpenRC etc.), I am just wanting to run another program/script to do my bidding outside systemd.
You really can't have two init process. You can - theoretically - run two service managers - but that too seems unrelated to your description.
My preliminary findings do agree with you, it doesn't look like Linux support a secondary init process.
How do you intend to run this scheduled task?
I didn't give it much thought, but probably just a simple shell script with a infinite loop and sleep in it. I did consider cron but it's overkill for what I need.
EDIT: I suppose you can run a second init if you launch a virtual machine, nspawn, or perhaps some other containers. But that too seems entirely tangential to the stated goals.
Ha ha ha ha, definitely! I don't want a VM or a docker container ![]()
---
I got an idea after I posted this yesterday... init seems to be just another program in /usr/bin, so what if I just substitute it with a wrapper shell script to launch both the real init and my own secondary init process? I will try that and report back.
Offline
... what if I just substitute it with a wrapper shell script to launch both the real init and my own secondary init process?
That's not likely to work the way you want - and it could cause real trouble. But more importantly, there's absolutely no need for this.
I am just wanting to run another program/script to do my bidding outside systemd... I didn't give it much thought, but probably just a simple shell script ...
So just run a shell script then. You don't need to create a new init system to run a shell script.
You could even run your shell script from systemd and it would not "pollute the logs" as you describe so long as you are not using a systemd timer but rather using your own infinite loop in the script. The systemd service would only start that script once, then that script can do whatever it is you wanted it to do.
This is all definitely a huge X-Y problem. What are you really trying to do? What is this script?
Last edited by Trilby (2022-05-02 20:51:18)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Online
So just run a shell script then. You don't need to create a new init system to run a shell script.
Well, that's exactly what I did. I never said I was creating an entirely new init system.
I wrote this init wrapper script for testing:
~> cat /usr/local/sbin/init-wrapper
#!/usr/bin/fish
# Set $PATH
set --export PATH /sbin /bin /usr/bin /usr/sbin
# Start secondary init processes
sleep 1h &
disown
# Start actual init
exec /sbin/initAnd instead of replacing it with the default init, I did a smart thing and manually specified the path to this wrapper init via the kernel command line's `init` option. Unfortunately it didn't work for me though, the kernel panicked and just stopped during the boot process.
I don't know what went wrong but obviously it wasn't as simple as I thought, so for now I've decided to give up...
You could even run your shell script from systemd and it would not "pollute the logs" as you describe so long as you are not using a systemd timer but rather using your own infinite loop in the script.
...and decided to just do this. I can't really be bothered about it much anymore.
What is this script?
Oh, it's a very simple script called fake-hwclock to save the system time periodically. My system doesn't have a timer and I don't want the time to go into the past everytime I reboot ![]()
Here's the service and loop script I made if anyone is interested:
$ systemctl cat fake-hwclock-loop.service
# /etc/systemd/system/fake-hwclock-loop.service
[Unit]
Description=Fake Hardware Clock
Conflicts=shutdown.target
[Service]
Type=exec
ExecStart=/usr/local/bin/fake-hwclock-loop
[Install]
WantedBy=basic.target
$ cat /usr/local/bin/fake-hwclock-loop
#!/usr/bin/fish
while true
fake-hwclock
sleep 1h
endYes, I use fish for both my interactive and scripting shell needs, I don't know bash ![]()
Last edited by TheDcoder (2022-05-03 01:25:19)
Offline
First why does that need to run every hour? The whole purpose of fake-hwclock is to save/restore time to a file on startup and shutdown. There should be no need for it to keep running every hour. And where did the 1h interval come from ... why 1 hour?
Second, once an hour doesn't seem "quite frequently" - are you really worried about a timer unit putting an entry in your journal every hour?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Online
I don't know why you're being so critical about the whole thing... but to answer your question, it runs every hour because there could be a power outage or an unexpected shutdown. The interval is arbitrary and I came up with it.
I didn't like seeing a ton of entries of only "Starting fake clock" and "Stopping fake clock" on my system when it's idle. Just some quality of life improvements ![]()
Offline
I don't know why you're being so critical about the whole thing...
I'm trying to understand your goals or actual needs so I can help you acheive them in the most effective way. But so be it, I'll not bother you further.
Last edited by Trilby (2022-05-03 02:00:49)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Online
Sorry, I didn't mean to offend you. Thanks for the help!
Also if anyone knows a way to get my init wrapper working then I'm still interested in it, it's a fun exercise and could come in handy sometime.
Offline
Also if anyone knows a way to get my init wrapper working then I'm still interested in it, it's a
… pointless attempt to shoot your own foot.
An inherently unstable and risky process to find the most clumsy workaround for a clumsy solution for yet another problem.
My system doesn't have a timer
Is this an ARM system?
Here's the service and loop script I made if anyone is interested
That logs its start *once*, whatever you're seeing afterwards likely stems from whatever "fake-hwclock" is - unless there's also a .timer
Is this derivative of https://aur.archlinux.org/packages/fake-hwclock ? Or https://aur.archlinux.org/packages/fake-hwclock-git?
#!/usr/bin/fish
I so much wish that Eli was still around…
Online
Is this an ARM system?
No, the system just doesn't have a working battery.
That logs its start *once*, whatever you're seeing afterwards likely stems from whatever "fake-hwclock"
You've misunderstood, these are the scripts I made to avoid the repeated messages, so it's deliberate. The original fake-hwclock does come with a .timer and I made this setup to avoid using that.
I so much wish that Eli was still around…
Who's Eli? ![]()
Offline