I have the following working systemctl systemd
startup script that automatically starts on reboot perfectly (other dbdeployer dependency starting too).
Its a .sh script
where I created a few different 'states', basically for the services called.
(One startup script uses docker-compose project, while the other is for a dbdeployer mysql instance)
Systemd service unit for docker-compose containers:
[Unit]
Description=Magento 2.3.5 Docker-Compose Containers
After=dbdeployer-mysql-5-731-in-1.service
Requires=docker.service dbdeployer-mysql-5-731-in-1.service
[Service]
EnvironmentFile=/var/www/systemd.startups/glolighting/magento/2_35/docker-compose.mag2.35.env.file
#Environment=FILE_SCRIPT=/var/www/docker/systemd.startups/magento/2_35/dc-glo-mag235.sh
#PassEnvironment=$DCFOLDER
Type=simple
TimeoutStartSec=0
Restart=always
RestartSec=4s
RemainAfterExit=yes
#WorkingDirectory=${DC_PROJECT_FOLDER}
ExecStartPre=mkdir -p ${LOGFOLDER}
ExecStartPre=echo ${DC_PROJECT_FOLDER}
ExecStartPre=echo Starting Docker-compose service for ${DESCRIPTION}...
ExecStartPre=bash ${SERVICE_FILE_SCRIPT} ${DC_PROJECT_FOLDER} 1
ExecStart=bash ${SERVICE_FILE_SCRIPT} ${DC_PROJECT_FOLDER} 2
ExecStartPost=bash ${SERVICE_FILE_SCRIPT} ${DC_PROJECT_FOLDER} 1
ExecStop=bash ${SERVICE_FILE_SCRIPT} ${DC_PROJECT_FOLDER} 3
ExecStopPost=bash ${SERVICE_FILE_SCRIPT} ${DC_PROJECT_FOLDER} 1
[Install]
WantedBy=multi-user.target
The script being called by systemd
:
____truncated for relevance___
# Continue on success
if [ $arguments_correct -eq 1 ]; then
cd $PATH_DOCKER_COMPOSE_PROJECT_FILE
if [ $OPTION -eq 1 ]; then
echo "$LINE"
echo ""
$(which docker-compose) ps
echo ""
echo "$LINE"
elif [ $OPTION -eq 2 ]; then
$(which docker-compose) start
elif [ $OPTION -eq 3 ]; then
$(which docker-compose) stop
fi
exit 0
fi
I was hoping ExecStartPost=bash ${SERVICE_FILE_SCRIPT} ${DC_PROJECT_FOLDER} 1
will supply me with the correct output, (in other words $(which docker-compose) ps
, but there is a delay - docker containers can take from ~3-10 seconds. So, since this status does not update (requery) everytime you call the status
command, I only see the output when the original ExecStartPost
occurred.
To summarize: once I do systemctl status docker-compose-mag235.service
, I will get output to say that some docker-containers are still exit/starting
state.
Question
Is there any way to use systemctl status docker-compose-mage235.service
(or equivalent systemctl
command) that will be able to give me an updated status. _In other words: The status of $(which docker-compose) ps
at the moment I ran this new systemctl command.
(Before creating these startup systemd services, I always assumed that the state is 're-queried' for every call, but then I realized it's just taking the last output from logfiles (most likely syslog
)).
NOTE:
Calling /location/of/project/file/of/docker-compose.yml
is possible, but I would rather just want to house different systemd services
that I can query based on Docker Compose project, in other words I have multiple folders for different DC projects. And then I would need to create aliases, but before I do that I would know if systemd
can help me.
$(which docker-compose)
. Either it's in the PATH, so it can be run as justdocker-compose
, or it's not in the PATH andwhich
won't find it. – cas May 05 '21 at 12:44"$LINE"
:$arguments_correct
,$PATH_DOCKER_COMPOSE_PROJECT_FILE
, and$OPTION
– cas May 05 '21 at 12:47$(which docker-compose)
: makes sense, it is in the PATH. I was testing outExecStart*
behaviour, and it was just my misunderstanding (and my question maybe also showing that) that initially I thought status can be requeried via one of the Pre/Post* commands. The end plan is to combine everything into one script once everything worked. – CvRChameleon May 05 '21 at 13:27ExecStartStop
in my comment above. That should beExecStartPost
. – cas May 05 '21 at 13:33ExecStartPost
. – CvRChameleon May 05 '21 at 14:21