systemd - How can you find out whether the service was started on booting or by "systemctl restart ..."? - systemd

I wrote a service that has to behave differently, depending on whether it is started after a boot or by the command "systemctl restart ...".
Can I find out that in the daemon itself? Or alternatively set an environment variable in the "daemon.service" file for the daemon?
At the moment I don't see how this can be decided e.g. from the environment.
Thanks in advance,
Poldi

Sorry,
stupid question. I just have to write a temporary file to a ram disk ;-)

Related

Boot hangs: A start job is running

In a virtual box I have a Debian that I sometimes want to run without X. So I edited /etc/grub.d/10_linux and added another menu item with a kernel option "nox" appended. Then I added a line to /lib/systemd/system/lightdm.service, Section [Unit]:
ConditionKernelCommandLine=!nox
However, when starting this, it hangs with the message:
A start job is running for Hold until boot process finishes up (56min / no limit)
Thank you, systemd for informing me about that. I wouldn't have noticed. Yet, I would like to know, which job it is that's hanging.
The system allows me to connect via SSH, but none of the systemctl or journalctl commands I tried did tell me the name of the service causing the problem. lightdm.service itself seems to be satisfied.
I known it's a but late, but I just found out that one can use:
systemctl list-jobs
to find out what units are waiting or running at any given moment.
By adding systemd.debug-shell=1 to the kernel command line, a root shell will be available on TTY9 (crlt+alt+F9) to run the command above.
I first tried "systemd-analyze", and that gave me the message about "systemctl list-jobs".
hope this helps someone with similar problems.

What are the systemd dependencies of ntpd?

My ntptime is showing error code 5 when the system starts. Restarting the ntpd through systemctl fixes this. Waiting a few minutes also seems to fix this. I have verified that ntpq shows that ntpd is talking to my intended server. This may be caused by another issue, but I think I'll take this time to ask a more general-purpose question.
Does anybody know which systemd dependencies are required for ntpd to work? I would love to see a minimum working example ntpd.service file from a system whose ntptime shows great success on system start.
Check your dependencies of a systemd unit with:
systemctl list-dependencies ntp
That command was found by reviewing man systemctl.

How to shutdown elasticsearch completely?

Could anybody help me how to shutdown elasticSearch completely ! It starts automatically when system starts.
Yes, it should because you are initialing it in the config file, which fires every time the system starts.
To answer your question, I believe this answer should help.
It probably runs as a service. If it is on linux remove the service file, usually on /etc/init.d/elasticsearch
If it is on windows - there is a service.bat file on the installation/bin folder, you can uninstall using:
service.bat remove
If you are using Ubuntu 15.04+
systemctl disable elasticsearch
For Ubuntu < 15.04
To toggle a service from starting or stopping permanently you would need to:
echo manual | sudo tee /etc/init/SERVICE.override
where the stanza manual will stop Upstart from automatically loading the service on next boot. Any service with the .override ending will take precedence over the original service file. You will only be able to start the service manually afterwards. If you do not want this then simply delete the .override.
For more details, you may check this

Starting a application with graphical interface on boot

I have a small question that I havn't found any answers to.
I run a virtual machine on my CentOS server, and I have made a simple script to start the virtual machine. I would like to run the script on boot so that the virtual machine starts up on boot also. So I successfully registered the script with following
chkconfig --add myscript
and enabled it with following
chkconfig --level 2345 myscript on
at last I checked it so its registered and enabled correctly with
$ chkconfig --list | grep myscript
So long, so fine, but when I restart my machine to test it, well nothing happens.
So now I wonder why isn't my script running? I had some thaughts that it cold be because of some missing arguments, myscript requires an argument "start" to run properly, so I think that could be the cause why it's not running, in that case where should I add the argument?
Note also, my script is ok, or at least I can run it manually.
UPDATE
The script is run during boot and is working as it should. Tha application I try to start with a script, my virtal machine, has a graphical interface and it seems like it's that causing the trouble. Does anyone have any experience in starting a graphical application with script on boot, on unix based OS's ofcourse? Or if there are any other clever ways of achieve this?
Thanks!
Make sure that the proper symlinks get created in /etc/rc.?/ and your startup script in /etc/init.d/ should contain start and stop methods.

Launch Daemons in MAC OSX

I have written a daemon is MAC OS 10.8.
I copied the Unix executable file to startup items.
I have created a .plist file which has Label,KeepAlive flag set to YES and progrrammArguments array's Item0 as /Libray/StartupItems/updaterDaemon.
I want this daemon to run as root when a system start up hence I copied it into startupItems,but the daemon does not get launched.
Please tell what I am doing wrong or What I need to do to launch and run this daemon on system/machine start up.
Thanks in advance.
You are confusing startup items and launchd jobs. A startup item is a special kind of bundle with certain properties. This is deprecated technology. You want to write a launch daemon. How to do this has been answered here. There are also some launchd GUIs out there which can help you to achieve your goal.
Should your job still fail make sure to set StandardErrorPath and StandardOutPath. Check those files to find out what went wrong.
You can read exhaustive overview of macOS daemons here: https://medium.com/#alkenso/macos-daemonology-d471fd21edd2
For detailed configuration of daemon.plist, use man launchd.plist or refer the article: https://www.real-world-systems.com/docs/launchdPlist.1.html

Resources