#!/bin/bash
/usr/sbin/init
...
commands or operations (which are not something like (re)start service but some pre- post- operations) to be executed
...
exec "#@"
doesn’t work either.
How can I execute custom startup script after executing /usr/sbin/init in docker?
@clouderafn did you find out a way to do that ? I am a newbie and stuck with same issue
Would be great help if you could share as to what you did .
Thanks
I’m sorry for the translation, I speak Spanish and I’m using google translate.
Hope this can help you.
what I do is launch a script in CMD or ENTRYPOINT, inside of which I have put a secondary script in the background after the instruction /usr/sbin/init, hopefully sytemd ends before and is ready to be used.
FROM centos:centos7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
COPY ./start /opt/start.sh
CMD["/opt/start.sh"]
start.sh
#!/bin/bash
# script set in background
setsid ./install.sh > output.txt &
# run systemd
exec /usr/sbin/init
Thanks @daners, this really works. Finally!!! I was looking for this solution for such long time. Ill go back to the hundreds of forums I went through to recommend your aproach