I need to copy a bunch of files into some folder every time the httpd service restarts
e.g.:
yes | cp ./dynamic/*.file /folder/inside/my/webapp
is there a way to run some additional commands when the httpd is restarted?
According to this: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
You can edit the httpd service file with:
sudo systemctl edit --full httpd.service
You should be able to add more directives to the service unit, such as running your additional commands.
Related
Getting access denied error while running the systemctl command in a pod.
Whenever try to start any service, for example, MySQL or tomcat server in a pod, it gives access denied error.
Is there any way by which I can run systemctl within a pod.
This is a problem related to Docker, not Kubernetes.
According to the page Run multiple services in a container in docker docs:
It is generally recommended that you separate areas of concern by
using one service per container
However if you really want to use a process manager, you can try supervisord, which allows you to use supervisorctl commands, similar to systemctl. The page above explains how to do that:
Here is an example Dockerfile using this approach, that assumes the
pre-written supervisord.conf, my_first_process, and my_second_process
files all exist in the same directory as your Dockerfile.
FROM ubuntu:latest
RUN apt-get update && apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY my_first_process my_first_process
COPY my_second_process my_second_process
CMD ["/usr/bin/supervisord"]
That's a rather short question. The 'systemctl' command does try to talk to the systemd daemon which is not running in a pod by default (it could however). Running multiple services is yet another question about service management. It both cases it could help to use a tool like the docker-systemctl-replacement overwriting /usr/bin/systemctl and registering it as the init-CMD of the container.
I'm running Ubuntu 18.04 and I've installed haproxy 1.8.8. I want to modify the config so that the "-f" option will read a directory rather than a single haproxy.cfg file.
I see /lib/systemd/system/haproxy.service and also /etc/init.d/haproxy were installed. I think systemd is managing haproxy. But I've read that I'm not supposed to modify the installed haproxy.service.
I copied haproxy.service to /etc/systemd/system/ and edited it there. The changes I made were not picked up when I ran sudo systemctl daemon-reload; sudo service haproxy restart.
Which file do I need to modify and then get systemd to recognize the changes? TIA
As you suspected, you should not edit the unit-files (provided by the OS packager) directly. You can supply a drop-in-snippet using the command
systemctl edit haproxy
and customize the relevant directives (ExecStart)
I wrote a program (node js, on Raspberry Pi) that I can start manually, but not as a systemd service:
pi#blueberry ~ $ systemd --version
systemd 215
+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
pi#blueberry ~ $ sudo systemctl daemon-reload
pi#blueberry ~ $ sudo systemctl start /etc/systemd/system/rfxtrx.service
Failed to start etc-systemd-system-rfxtrx.service.mount: Unit etc-systemd-system-rfxtrx.service.mount failed to load: No such file or directory.
pi#blueberry ~ $
The error message complains that there is no rfxtrx.service.mount unit. Correct. Should there be such unit? The most common suggestion is to daemon-reload; this doid not help. Or as per https://github.com/systemd/systemd/issues/5375 this could be a bug in systemd that was fixed but only in a later systemd version than the one in raspbian (raspbian has version 215).
Is there any other solution than trying to update to a version not supported by the raspbian maintainers?
Well the first problem here is that you're running to start the service name rfxtrx.service however systemd is expecting etc-systemd-system-rfxtrx.service.mount.
If you are trying to have a systemd mount configuration then your file name should follow the following rule:
Mount units must be named after the mount point directories they
control. Example: the mount point /home/lennart must be configured in
a unit file home-lennart.mount.
So if you were wanting to create a mount point at say /dir/to/rfxtrx then the systemd mount file needs to be named dir-to-rfxtrx.mount, and it's recommended that it sits in either /usr/lib/systemd/system/ or /etc/systemd/system/ with the latter directory taking precedence.
If you just wanted to have a service file then enable the unit systemctl enable rfxtrx.service. systemctl daemon-reload is used when the unit has already been registered with systemd and requires a reload.
You can check if the service exists with systemd by using the command systemctl list-units or systemctl status rfxtrx.service.
The error you have is that you're doing sudo systemctl start /etc/systemd/system/rfxtrx.service instead of sudo systemctl start rfxtrx.service.
I want to set target to service in CentOS7 (Systemd).
I want to know following.
How to set target to service.
How to show target of service.
In other words, I want to know substitution for following commands.
$ sudo chkconfig --level=2345 mysql on (<- set runlevel)
$ chkconfig --list mysql (<- show runlevel)
I understood that "runlevel" in CentOS6 changed "target" in CentOS7and I should use "systemctl" command.
But problems were not solved.
I heard that following command is replacement for "chkconfig --list"
, but I can't check target and can't set target.
systemctl list-unit-files
Setting the target is done in the unit file for the service. For example:
[Install]
WantedBy=multi-user.target
Then you run systemctl enable $service_name to create a symlink which enables the service to start as part of a particular target. You could also create the symlinks manually. The enable command will print out the paths of the symlinks it's creating.
I think systemctl --reverse list-dependencies $service is the way to find what services and targets depend on a specific services to boot.
How do I check whether a service is running or not on Linux Mint?
If that service is not running, I need to start it.
I have tried using
service <service-name> status
But for some services it is not returning any results.
service --status-all is not of much use either as it has ? marks for some services.
In Linux Mint 16 and 17, by default you should be able to use a combination of sudo service <options> and sudo update-rc.d <options>.
For example, to get a list of services, try:
sudo service --status-all (as you said).
On the displayed list, + = started, - = stopped and ? is unknown.
To disable a listed service from starting at boot try:
sudo update-rc.d <service name> disable
To enable a service to start at boot:
sudo update-rc.d <service name> enable
There are many more options for update-rc.d, try man update-rc.d for details.
A service that has been disabled (or stopped) can be manually started with:
sudo service <service name> start
A service (started manually or at boot) can stopped with:
sudo service <service name> stop
Many services also have other options like restart and force-reload but all should have start and stop.
update-rc.d - install and remove System-V style init script links
sysv-rc-conf - Run-level configuration for SysV like init script links
sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf
top - display Linux processes
sudo apt-get install top
bum Boot-Up Manager - Graphical runlevel configuration tool
There are two methods of starting and managing services in Ubuntu/Mint. The old System-V style init way and upstart.
Your service can either be managed by upstart or not. If you don't see it with
service --status-all that means it is. To list services managed by upstart, use sudo initctl list. For more info, check the man pages for service and initctl.