I'm running a customized linux distribution built with reference to ubuntu 12.04 which has init as user space startup process by default. But now I want to switch over to systemd init system which is available from ubuntu 15.04. I installed the systemd components & libraries and also written unit files to replace init.d service daemon scripts.
I want to know how the system can start the systemd as init process?
The kernel starts the init system located in /sbin/init (see also this wikipedia article)
This process is responsible for starting every other process and should not die or exit (this will result in a panic).
One can also temporarily change the init daemon by using the init boot param on the kernel command line: init=/path/to/init_program.
Depending on your bootloader you should be able to edit the kernel commandline and test your changes.
Related
I want my raspberry to execute 2 commands when he starts but i don't know how to setup it
the commands are
cd /var/www/restaurant && php -S 10.0.0.1:8000 -t public
i have tried to edit /etc/rc.local and add my command but it doesn't work
The "official" way to run a program at boot time on systemd-based Raspbian systems (and, in fact, most modern Linux distributions) is to create a systemd unit file. There are specific instructions for Raspbian here:
https://www.raspberrypi.org/documentation/linux/usage/systemd.md
The entry After=network.target is particular relevant in this case, because I imagine your program will need network interfaces to be up.
rc.local is a hold-over from the SysV init days, and I've heard reports of it not working reliably in Raspbian. Creating a systemd unit file provides a simple way to test the service using systemctl without actually having to reboot. If it fails on boot, you'll probably need to use journalctl to see the error messages.
NOTE: I am running Red Hat 6.7
I have a service that is configured with the Linux init system to start a process as a service when the machine boots. This was done by doing this one-time configuration from the command line:
ln -snf /home/me/bin/my_service /etc/init.d/my_service
chkconfig --add my_service
chkconfig --level 235 my_service on
When the OS reboots, the service starts as expected.
I ALSO need the service to be restarted if the service (my_service) crashes. From what I've read, all I need to do is add an entry to /etc/inittab that looks like this:
mysvc:235:respawn:/home/me/bin/my_service_starter
Where my_service_starter looks like:
#!/bin/bash
/home/me/bin/my_service start
My understanding is that when the init system detects that my_service is not running, it will attempt to restart it by running "my_service_starter".
However this does not seem to be working.
I need to understand how to tell the Linux init system to restart my service when the service crashes.
Given an entry like:
mysvc:235:respawn:/home/me/bin/my_service_starter
Then inittab will:
call /home/me/bin/my_service_starter
which will call /home/me/bin/my_service start
...and then exit, so init will thing your service has failed
so init will call /home/me/bin/my_service_starter again
...and so forth, which will result in init deciding that your script is respawning too fast, after which it will ignore it completely.
A process started by inittab is not expected to exit. If you really want to use inittab to maintain your service, you could remove /etc/init.d/my_service, and then in /etc/inittab you would have something like:
mysvc:235:respawn:/home/me/bin/my_service
And you would need to ensure that my_service runs in the foreground (some programs automatically daemonize by default, although these will often have some sort of --run-in-foreground flag).
If you upgrade to CentOS 7 or something else with systemd, this all becomes easier.
You can also investigate "third-party" process supervisors like "supervisord" or "runit" that you could use for process monitoring/restarting on CentOS 6.
Update
As mangotang points out, and I forgot, RHEL 6 actually shipped with upstart, even though it used almost exclusively SysV-style init scripts. So a better solution would be to create an upstart service instead. There are some reasonable getting-started docs here.
On RHEL 6.X, at top of the /etc/inittab file it says:
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM
RHEL 6.X uses Upstart instead of the System V init system. See the man pages for initctl(8) and initctl(5), or ask Google about Upstart.
I wrote a simple JAVA application which runs as a service. When my application is up and running, I maintain the PID in a file which will be used while stopping the application.
Issue:
When I restart the OS the stop script is not called (not sure how to make this happen) and the old PID is left as it is in the PID file. Now, after reboot (which start my app) when I stop the app using stop script now my stop script will try to clean up all the PID listed in the file. Most of the time, I will get "No such process". But there are chance the same PID might have been used for some other process
Question:
How I can make sure my stop script will be invoked when I shutdown ore reboot the OS? I am looking a solution for RHEL environment.
I think your are looking for a init script. (startup/shutdown services at different run levels)
This is a good reference
http://blog.rimuhosting.com/2009/09/30/one-java-init-script/
this has a good refernce to Linux init.d scripts
http://coreymaynard.com/blog/creating-a-custom-initd-script-on-fedora/
Hope it helps
If you are looking for scripts that run after reboot, I guess you can write the script in /etc/rc.local and then you can start your service.
This script will run after all your init scripts have run while your machine starts. Using this you can delete the old PID file.
I'm currently designing a program that I want to run when my computer boots up. I've written a daemon that runs the code, so what I want is a way to run the daemon on startup. Here's my problem: I don't want to my end user to have to manually add the daemon into their list of startup scripts, I want the daemon to be added automatically when the program is installed. At the moment I have a makefile that is installing the software to my pc, so is there a way to get the makefile to insert the daemon into the user's list startup scripts, so the daemon is run on startup?
Cheers
You could have some target (perhaps installcron) in your Makefile that would use the crontab(1) command to add (perhaps after verifying it is not there already) a crontab(5) entry for #reboot (which is run at boot time).
I want to start a java program ( class ) when the system starts ( even though when no user has logged in the system ). I read some documentation and I found that Linux executes the init command when booting and executes the scripts in the rc.d directory. And the rc.local file is executed last. So I wonder if it is right to edit this file in order to run an application when the system has finished booting up ?
It depends. If your program
is a purely local modification and
you don't need daemon control over the software (start/stop it later at system run) and
a simple SIGTERM suffices to stop your program on system shutdown,
then yes, rc.local is just the point to put it.
If you intend to install the file on other systems, put a file in /etc/init.d and use the system specific commands to let it run at the appropriate runlevels.