You are not logged in.
@jpgg:
Is there an advantage of doing that instead of killing all processes (except init) with "kill -s TERM -1; kill -s KILL -1"?
One thing I get out of this: When you call that from a script and it does what is said (man kill: "kill all processes w/ a pid larger than 1") then this would kill the script itself too...
Though I'm not really sure what it's effectively doing...
I think this is different when it's e.g. in an inittab that init (pid 1) itself is processing, like e.g. busybox does.
Btw. Thanks dimigon for explaining.
Edit: Ah, dimigon we just crossposted, I meant the above explanation .
@MrGreen: It depends... You specify the script or whatever you want and it's argument to be executed by this.
So this would call
/sbin/rc init
at boot
/sbin/rc shutdown
when sinit receives SIGUSR1
/sbin/rc reboot
when sinit receives SIGINT.
So for this to work you would need an init script "rc" in /sbin/ (/sbin is symlinked to /usr/bin on Arch). This script needs to accept the arguments "init", "shutdown" and "reboot".
The process of shutting down is usually as explained by progandy above.
Remember that this is compiled into sinit, so you need to rebuild sinit after modifiyng.
To avoid this you could, e.g. w/ this configuration put a simple script under /sbin/rc that calls
the real init scripts. Like:
#!/bin/bash
# $1 is the first argument
case $1 in
init)
# put the real init script command here e.g.
/usr/bin/realcommand realargument
;;
shutdown)
# put the real init script command here e.g.
/usr/bin/realcommand realargument
;;
reboot)
# put the real init script command here e.g.
/usr/bin/realcommand realargument
;;
esac
This must be executable (chmod 755 /sbin/rc).
Might be useful for experimenting but also a bit clumsy .
Edit: What might be confusing here is that for shutting down you now usually don't call "/sbin/rc shutdown" directly, but instead you signal (s)init w/ the respective signal (as mentioned by progandy). (s)init then calls the shutdown script. The reasons for this were indicated above.
As it's a bit clumsy to input "kill -s USR1 1" to shutdown you would usually put this in another script or e.g. an alias. I think it should also be possible to put all of these commands in a single script... but e.g. separated by a case as in the example I gave. As of typing this I realize that I'll may try that w/ my dependency init.
Last edited by rebootl (2014-04-24 14:51:38)
Personal website: reboot.li
GitHub: github.com/rebootl
Offline
My rc script based on servman was in sbin and had those functions. Compiled sinit with above config.h. Script runs shutdown function but then either hangs or jumps back to login. The opt commands are not working well not for me anyway. Busybox worked out of the box without any real issue other than it is slower to boot.
Have a feeling with all the messing about I have been doing the poor vm does not know which way up is... Can set up a new one and try again, base does not take long to set up and then I can test properly
Thanks rebootl
Mr Green I like Landuke!
Offline
Well, I'd need to see an up to date version of the script to comment on this.
Good Luck
Personal website: reboot.li
GitHub: github.com/rebootl
Offline
https://github.com/mrgreen3/busyrc
There you go :-)
Mr Green I like Landuke!
Offline
Yeah ok, but that already got commented on.
In the rc script you still have "busybox reboot" and "busybox shutdown -h now". Review the comments above. Those are not the right commands at that point, even when using busybox.
And the kill commands may be a problem too as discussed in the latest comments above.
Last edited by rebootl (2014-04-24 16:57:44)
Personal website: reboot.li
GitHub: github.com/rebootl
Offline
I made my script work with busybox for testing, it was based of course on servman. Seems to be an issue with any other init system, power down as user. Systemd does it without too much fuss.
Mr Green I like Landuke!
Offline
Have done some searching and reading up on shutdown as user, two things creating /etc/shutdown.allow with list of users (that did not make any difference) and setting the s bit
chmod +s /usr/bin/shutdown
Allows my user to use shutdown, you can of course apply to reboot.
Do not know how safe this method is or the affect on a multi user system but just thought I would mention it.
Mr Green I like Landuke!
Offline
Do not know how safe this method is or the affect on a multi user system
Probably not safe at all.
What is /usr/bin/shutdown in this case, a link ?
(You should be able to use sudo/visudo for this as discussed before. You may look at the (ugly) script I posted.
E.g. for sinit:
As mentioned for sinit to poweroff you would send
kill -s USR1 1
. This needs to be done as root to work, so -->
sudo kill -s USR1 1
Now, if you dont want to enter a password you need to adapt sudo, using visudo add the line:
<your_username> ALL=NOPASSWD: /usr/bin/kill -s USR1 1, <evtl._more_commands>
replace the <..> by yours, see the sudo wiki for more information.
You can place the call in a script, e.g.
mypoweroff
#!/bin/bash
sudo kill -s USR1 1
)
Edit: In case your /usr/bin/poweroff is a symlink to busybox, be very careful. I noticed that the SUID (+s) is not applied to the symlink itself but to the target. That means that _every_ command executed using busybox, by any user, will be executed as the owner of busybox (most likely root) now...
And setting a SUID on a script doesn't work. It will be ignored by the system (kernel), too dangerous .
Last edited by rebootl (2014-04-27 10:57:45)
Personal website: reboot.li
GitHub: github.com/rebootl
Offline
That is fine, I am only using it under a VM not a real machine. The problem I had was more done the line in rc script rather than commands themselves. It has been a while since I was using an init system. Thought with old Arch it was a group thing (power,wheel).
Still learning ;-)
Mr Green I like Landuke!
Offline
No problem. I don't know how this was set up in the old Arch init. But I'm pretty sure groups could also be used in the sudoers file etc.. Just a matter of setting it up correctly, "wheel" is a typical group for sudoers.
Personal website: reboot.li
GitHub: github.com/rebootl
Offline