I'm running linux on a mips based system (specifically openwrt on a router).
When I run the reboot (as supplied by busybox) i.e. just reboot on it's own, the system reboots, but some of the services (webserver, dhcp/dns, dsl stuff) don't start up.
However when I reboot via the web interface, all the services start normally. I looked at the code and saw that the web interface runs reboot > /dev/null 2>&1. Running this command also reboots and starts up0 the services properly.
My question is how does redirecting stdout and stderr to /dev/null affect the startup of services upon the next boot?
Also, I'm wondering, would reboot contain architecture specific code?
No, redirecting stdout/stderr must not be able to affect the boot process (and where would that be saved anyway?). There must be something else causing this.
Does "shutdown -r now" work?
Related
I would like to make tomcat auto start with a non-root user while system booting. I have created a daemon.sh under folder /etc/init.d . And I executed chkconfig tomcat on. The linux server is in another city. I access it by ssh. And I cannot reboot server to test it.
The problem is if tomcat start failed while booting, I am afraid that linux server cannot not be start succesfully. That whould be a disaster for me. Perhaps my worry is unnecessary.
How to avoid this problem?
On my raspberry pi, I want my own written server to be started at startup, and to be restarted when it segfaults, so I added it to /etc/inittab. The problem is that the server won't start
The line I added:
1:2345:respawn:/home/gear/lionfish/main /home/gear/lionfish/app
When I run this command from the command line it works just fine, but the server doesn't run. I've checked this with ps aux, and it didn't show up
Have I made some sort of mistake?
EDIT: Small side question. The server needs root privileges, does inittab do this automatically or do I need to add something to it?
Typical problems:
As already mentioned, environment is set up differently. Make sure $PATH iscorrect.
Does your program try to execute in a directory which becomes unmounted? If so, cd to / first.
Access restrictions to files and directories.
Process doesn't detach from stdin/stdout/stderr.
The process runs in foreground instead of background.
Parent process receives a terminating signal such as SIGTERM which kills your process as well. Try ignoring this (and some others) signals by using nohup or sigset/sigignore.
Debugging hint: Let the server start by appending current time to the end of an already existing file in a directory which is guaranteed to be writable. Make sure you flush (and close) the file pointer immediately. Then at least you can see whether it was started at all or not.
I have a script (twoRules.sh) which add rules to ovs plugin bridge.
The rules gets deleted when someone does service neutron-plugin-openvswitch-agent restart or reboots the system. So where should I put my scripts so that after the restart of neutron-plugin-openvswitch-agent the (twoRules.sh) scripts get executed successfully and rules remain added.
I tried putting it in /etc/init.d/neutron-plugin-openvswitch-agent file as other people suggested but this file is only called on /etc/init.d/neutron-plugin-openvswitch-agent restart and not on service neutron-plugin-openvswitch-agent restart.
You have to convert the script to a a SysV-style init script. There are many documents out there explaining about this.
http://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian
http://www.cyberciti.biz/tips/how-to-controlling-access-to-linux-services.html
https://wiki.debian.org/Daemon
This way you can configure the script to be executed after certain services start or stop or when runlevel changes.
I have ssh-ed to a remote machine. I have enabled X11 forwarding (ssh -X) and I have started a GUI program.
The program takes 5 minutes to set up to do some processing but the actual processing takes 1-2 hours. I don't want to stream data while the program is working. I don't even want to see the program again as it produces files as output when it finishes and I can just scp them.
So how can I quit the ssh session but leave the program running on the machine? CRTL+C in the terminal?
EDIT: For the answer please see my comment just below.
Long story short - you can't do this without making some modifications to the way you run things. A GUI application requires for an X server target to be accepting it's GUI updates - if you're using your local X server to do this, then it'll require (1) the connection to be open (2) that you actually handle the updates.
A way around this is to use something like Xvfb - which is a headless way of hosting a virtual X-server. Above and beyond the examples provided on the wikipedia page, folks who seem to make frequent use of this mechanism are Selenium users.
Awesome, I've been looking for an acceptable answer to my problem for hours, and finally one pops up. ssh -X -f login#machine yourprogram worked perfectly for me. Though I used ssh -Y -f login#machine yourprogram. This has been driving me nuts.
Like some people said, SSH -X is using your local X server, so it needs the connection. I had the same problem, wanted to quit ssh but leaving GUI applications running. To do this I installed X server and VNC server on the remote host. With a VNC client on your local computer, you can easily connect to the VNC server and disconnect leaving GUI applications running.
By the way, you will have better performances with VNC or X2Go. In my case, Firefox was very slow and some sites didn't load at all with SSH -X, even with -Y or -C optimizations.
Running ssh -X -f login#machine yourprogram should do the trick.
Starting your program with nohup program & will make it safe to just close your terminal - program will still be running.
You won't be able to see the UI after you end ssh session, but since you don't need it anyway - it's going to do the job.
Since I install pending updates for my Ubuntu server as soon as possible, I have to restart my linux server quite often. I'm running an webapp on that server and would like to warn my users about the pending restart. Right now, I do this manually, adding an announcement before the restart, give them some time to finish their work, restart and remove the announcement.
I hope, shutdown -r +60 writes an file with all the information about the restart, which I can check on every access. Is there such a file? Would prefer a file in a virtual file system like /proc for performance reasons...
I'm running Ubuntu 10.04.2 LTS
If you are using systemd, the following command shows the scheduled shutdown info.
cat /run/systemd/shutdown/scheduled
Example of output:
USEC=1636410600000000
WARN_WALL=1
MODE=reboot
As remarked in a comment by #Björn, USEC is the timestamp in micro seconds.
You can convert it to a human friendly format dropping the last 6 figures and using date like this:
$ date -d #1636410600
Mon Nov 8 23:30:00 CET 2021
The easiest solution I can envisage means writing a script to wrap the shutdown command, and in that script create a file that your web application can check for.
As far as I know, shutdown doesn't write a file to the underlying files system, although it does trigger broadcast messages warning of the shutdown, which I suppose you could write a program to intercept .. but the above solution seems the easiest.
Script example:
shutdown.bsh
touch /somefolder/somefile
shutdown -r $1
then check for 'somefile' in your web app.
You'd need to add a startup link that erased the 'somefile' otherwise it would still be there when the system comes up and the web app would always be telling your users it was about to shut down.
You can simply check for running shutdown process:
if ps -C shutdown > /dev/null; then
echo "Shutdown is pending"
else
echo "Shutdown is not scheduled"
fi
For newer linux distributions versions you might need to do:
busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown
The method of how shutdown works has changed
Tried on:
- Debian Stretch 9.6
- Ubuntu 18.04.1 LTS
References
Check if shutdown schedule is active and when it is
The shutdown program on a modern systemd-based Linux system
You could write a daemon that does the announcement when it catches the SIGINT / SIGQUIT signal.