what does hyphen before slash in systemctl service file? - systemd

I see ExecStop=-/sbin/start-stop-daemon in the nginx.service file, what does -/sbin mean?
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid
TimeoutStopSec=5
KillMode=mixed

If the executable path is prefixed with "-", an exit code of the command normally considered a failure (i.e. non-zero exit status or abnormal exit due to signal) is recorded, but has no further effect and is considered equivalent to success.
From Table 1. Special executable prefixes in https://www.freedesktop.org/software/systemd/man/systemd.service.html

Related

Running a bash script after startup in an NGINX docker container

I need send curl request to itself while docker container starting.
But after nginx starting any command not working because nginx stay in foreground.
Example of entrypoint.sh
echo "Starting memcached"
memcached memcache -m 1024 -d
service memcached restart
echo "Starting php-fpm"
php-fpm -D
echo "Starting Nginx"
nginx -g 'daemon off;'
!!this part not working!!!
check_robots=$(wp wpc check_robots)
echo "Starting check robots"
if [ "$check_robots" != "Robots checked successfully!" ]; then
echo ERROR: Robots checked failed
exit 0
fi
exec "$#"
Not sure if it would work, but lanching nginx to background directly could be a solution, like so:
nginx -g 'daemon off;' &
Have not tested in case of Docker entrypoint though.

Why are shell builtins not found when using Kubectl exec

I am making a bash script to copy files from a Kubernetes pod running Debian. When I include the following line:
kubectl --namespace "$namesp" exec "$pod" -c "$container" -- cd /var
it errors out:
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "cd": executable file not found in $PATH: unknown
command terminated with exit code 126
I also tried
kubectl --namespace "$namesp" exec "$pod" -c "$container" -- builtin
kubectl --namespace "$namesp" exec "$pod" -c "$container" -it -- cd /var
which gave the same result.
I was able to resolve the issue by changing the command to:
kubectl --namespace "$namesp" exec "$pod" -c "$container" -- /bin/bash -c "builtin"
Would love to understand why the first command(s) don't work and the latter one does. I would have thought that builtin commands are the one group of commands that would always be found, in contrast to commands that rely on the PATH environment variable.
kubectl exec is used to execute an executable in a running container. The command has to be built into the container.
Neither builtin nor cd are valid executables in your container. Only /bin/bash is.
To execute a builtin shell command, you have to execute the shell and call it as the command argument like in your third example.

Unable to Find Entrypoint For Nextcloud (Alpine-based Version) For a Cron Container

I'm using Docker with Rancher v1.6, setting up a Nextcloud stack.
I would like to use a dedicated container for running cron tasks every 15 minutes.
The "normal" Nextcloud Docker image can simply use the following:
entrypoint: |
bash -c 'bash -s <<EOF
trap "break;exit" SIGHUP SIGINT SIGTERM
while /bin/true; do
su -s "/bin/bash" -c "/usr/local/bin/php /var/www/html/cron.php" www-data
echo $$(date) - Running cron finished
sleep 900
done
EOF'
(Pulled from this GitHub post)
However, the Alpine-based image does not have bash, and so it cannot be used.
I found this script in the list of examples:
#!/bin/sh
set -eu
exec busybox crond -f -l 0 -L /dev/stdout
However, I cannot seem to get that working with my docker-compose.yml file.
I don't want to use an external file, just to have the script entirely in the docker-compose.yml file, to make preparation and changes a bit easier.
Thank you!

Elasticsearch 5.6.5 cannot starup on Ubuntu14.04

All
I am new to elasticsearch. and I have installed the elasticsearch 5.6 on Ubuntu 14.04, with apt-get following the instruction on this page.
However, it fail to start when I was trying this command
sudo -i service elasticsearch start
Then I add a log line to check what the command really is.
log_daemon_msg "sudo -u $ES_USER $DAEMON $DAEMON_OPTS"
start-stop-daemon -d $ES_HOME --start --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
It returns
sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch -d -p /var/run/elasticsearch/elasticsearch.pid -Edefault.path.logs=/var/log/elasticsearch -Edefault.path.data=/var/lib/elasticsearch -Edefault.path.conf=/etc/elasticsearch
I try to run is command directly, and the command exit without print any log. I also check the /var/log/elasticsearch, which is an empty dir.
Could anyone help to find out what do I miss?
Thanks.
BTW. I am running a 512M RAM, and 1G swap machine. and I have modifed the jvm.options to -Xms256m and -Xmx256m

Socat and systemd

I need to run a script, which among many things running socat.
Running the script from the command line works fine, now what I want is that this script is run as a service.
This is the script I have:
#!/usr/bin/env sh
set -e
TTY=${AQM_TTY:-/dev/ttyUSB0}
/reg_sesion/create
DESTINOS=(http://127.0.0.1)
LOG_DIR=./logs-aqm
mkdir -p "${LOG_DIR}"
###ADDED####
echo $$ > /var/run/colector.pid
socat -b 115200 ${TTY},echo=0,crnl - |
grep --line-buffered "^rs" |
while read post; do
for destino in ${DESTINOS[#]}; do
wget --post-data="$(echo "${post}" | tr -d "\n")" \
-O /dev/null \
--no-verbose \
--background \
--append-output="${LOG_DIR}/${destino//\/}.log" \
"${destino}/reg_sesion/create"
done
echo "${post}" | tee -a "${LOG_DIR}/aqm.log"
done
And the service file:
[Unit]
Description=colector
[Service]
Type=simple
PIDFile=/var/run/colector.pid
User=root
Group=root
#ExecStart=/root/socat.sh
ExecStart=/bin/sh -c '/root/socat.sh'
[Install]
WantedBy=multi-user.target
When I start the service, the process starts and ends quickly.
any ideas?
Thanks for your time
Remove PIDFile= from your service file, and see whether it works.
PIDFile= is mainly for Type=forking, where your startup program would fork a sub-process, so you tell SYSTEMD (via PIDFile) to watch for that process. In case of Type=simple , with your long-running service, SYSTEMD will create a sub-process to start your service, so it knows exactly what the PID is.

Resources