.service file not working as espected

66 views
Skip to first unread message

Lantos István

unread,
Jun 22, 2015, 5:06:36 PM6/22/15
to coreo...@googlegroups.com
I have this httpd@.service file:
https://gist.github.com/DJviolin/0f986f9c2a3ecb452a55

This is my first systemd script attempt. My problems are:
- Created docker container not appearing under $ docker ps, just only $docker ps -a
- fleetctl destroy httpd@%i.service not destroying the .service file when I do: $ fleetctl stop ht...@8081.service
- The Apache Server was fired up on my first attempt at the following IP: http://172.17.8.101:8081/ (vagrant), but never after.
- Looks like /public_html folder didn't created inside container by this command: -v /home/core/share/www:/usr/local/apache2/htdocs/public_html:ro

- httpd.conf folder created in the host's "/home/core/share/httpd/conf" folder for this command, but I wanted to mirror out the httpd.conf file from the container into the host's folder: -v /home/core/share/httpd/conf:/usr/local/apache2/conf/httpd.conf
Is it even possible? And when I modify the mirrored out file on the host, I wanted the file to be modified inside the docker container also!

Thank You for your help!

István

httpd@.service

Lantos István

unread,
Jun 22, 2015, 5:21:48 PM6/22/15
to coreo...@googlegroups.com
+1
$ etcdctl get /httpd@8081 throwing error.


--
You received this message because you are subscribed to a topic in the Google Groups "CoreOS User" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/coreos-user/gCVgWguCnN8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to coreos-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Seán C. McCord

unread,
Jun 22, 2015, 5:23:33 PM6/22/15
to Lantos István, coreo...@googlegroups.com
- Created docker container not appearing under $ docker ps, just only $docker ps -a

This indicates that the container is likely being started, but it exits immediately.  Check the logs for the unit for more information (fleetctl journal httpd@8081)

- fleetctl destroy httpd@%i.service not destroying the .service file when I do: $ fleetctl stop ht...@8081.service

`fleetctl destroy` expects an actual unit, not a `%i` expansion.  Therefore, you'll want to do `fleetctl destroy ht...@8081.service` or `fleetctl destroy httpd@.service`

- The Apache Server was fired up on my first attempt at the following IP: http://172.17.8.101:8081/ (vagrant), but never after.

That is because you are not including the `--rm` option to `docker run`.  You are, hence, trying to `docker run` a new container on top of the existing one, which won't work.  You would then need to use `docker start`... but _don't_ do that.  Do your self a favour and maintain the container's statelessness:  use `--rm` to have Docker remove the container after it exists (though this sometimes fails... you'll ultimately want to add in an `ExecStartPre` statement which manually removes any existing container.

Also, corrollary to this, you are specifying a container name of simply `httpd`.  If you expect to run more than one of these containers on a machine, you will encounter collisions.  It would be better to set the name to something like `httpd-%i`.


--
You received this message because you are subscribed to the Google Groups "CoreOS User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coreos-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Seán C McCord
CyCore Systems, Inc

Lantos István

unread,
Jun 22, 2015, 5:50:49 PM6/22/15
to Seán C. McCord, coreo...@googlegroups.com
Thank You the help!

Here is the modified file:
https://gist.github.com/DJviolin/0f986f9c2a3ecb452a55

And here is the fleetctl journal:

core@core-01 ~/share/services $ fleetctl start ht...@8081.service
Unit ht...@8081.service launched on b1fc9549.../172.17.8.101
core@core-01 ~/share/services $ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
core@core-01 ~/share/services $ fleetctl journal httpd@8081
-- Logs begin at Mon 2015-06-22 19:06:19 UTC, end at Mon 2015-06-22 21:48:08 UTC. --
Jun 22 21:48:07 core-01 docker[1197]: de94ed779434: Already exists
Jun 22 21:48:07 core-01 docker[1197]: Digest: sha256:d1cd248b8a813615ee6adaf3a0ae9d6d6c0a3c836272d5e67844dd608d4bb04d
Jun 22 21:48:07 core-01 docker[1197]: Status: Image is up to date for httpd:latest
Jun 22 21:48:07 core-01 etcdctl[1211]: Running
Jun 22 21:48:07 core-01 systemd[1]: Started httpd-8081.
Jun 22 21:48:07 core-01 docker[1210]: time="2015-06-22T21:48:07Z" level=fatal msg="Error response from daemon: Cannot start container fe5295a9c178dbff7b9234e2fb8d59cd303cc5e096b73c9664a2e4b4bb13d43c: [8] System error: not a directory"
Jun 22 21:48:07 core-01 systemd[1]: ht...@8081.service: Main process exited, code=exited, status=1/FAILURE
Jun 22 21:48:07 core-01 docker[1263]: httpd-8081
Jun 22 21:48:07 core-01 systemd[1]: ht...@8081.service: Unit entered failed state.
Jun 22 21:48:07 core-01 systemd[1]: ht...@8081.service: Failed with result 'exit-code'.


Seán C. McCord

unread,
Jun 22, 2015, 6:04:55 PM6/22/15
to Lantos István, coreo...@googlegroups.com
Right, the problem now is the "[8] System error: not a directory" issue.

This is most likely referring to one of your volume attachments.  If I had to guess, I would make sure you aren't interposing directories for files in the second (conf) option.

Lantos István

unread,
Jun 23, 2015, 8:45:38 AM6/23/15
to Seán C. McCord, coreo...@googlegroups.com
Thank You for your help and useful tips!
[Unit]
Description=httpd-%i
After=etcd.service
After=docker.service
Requires=docker.service

[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill httpd-%i
ExecStartPre=-/usr/bin/docker rm httpd-%i
ExecStartPre=/usr/bin/docker pull httpd:latest
ExecStart=/usr/bin/docker run --rm --name httpd-%i -v /home/core/share/www:/usr/local/apache2/htdocs/public_html:ro -p %i:80 httpd:latest
ExecStartPost=/usr/bin/etcdctl set /httpd-%i Running
ExecStartPost=-/usr/bin/docker cp httpd-%i:/usr/local/apache2/conf/httpd.conf /home/core/share/httpd-%i/conf
ExecStartPost=-/usr/bin/docker exec -d httpd-%i bash -c 'cp -rf /usr/local/apache2/htdocs/public_html/conf/httpd.conf /usr/local/apache2/conf/httpd.conf'
ExecStartPost=-/usr/bin/docker exec -d httpd-%i bash -c 'httpd -k restart'
ExecStop=/usr/bin/docker stop httpd-%i
ExecStopPost=/usr/bin/etcdctl rm /httpd-%i
ExecStopPost=-/usr/bin/fleetctl destroy httpd@%i.service
ExecStopPost=-/usr/bin/fleetctl unload httpd@%i.service
Restart=always
RestartSec=10

[X-Fleet]
Conflicts=httpd@*.service

This is how it looks my fleetctl journal now:

core@core-01 ~/share/services $ fleetctl start ht...@8081.service && fleetctl journal httpd@8081

Unit ht...@8081.service launched on b1fc9549.../172.17.8.101
-- Logs begin at Mon 2015-06-22 19:06:19 UTC, end at Tue 2015-06-23 12:27:19 UTC. --
Jun 23 12:26:39 core-01 docker[11959]: [Tue Jun 23 12:26:39.702528 2015] [mpm_event:notice] [pid 1:tid 139916128237440] AH00491: caught SIGTERM, shutting down
Jun 23 12:26:39 core-01 docker[12225]: httpd-8081
Jun 23 12:26:39 core-01 fleetctl[12242]: Destroyed ht...@8081.service
Jun 23 12:26:39 core-01 systemd[1]: Stopped httpd-8081.
Jun 23 12:26:44 core-01 systemd[1]: Stopped httpd-8081.
Jun 23 12:27:19 core-01 systemd[1]: Starting httpd-8081...
Jun 23 12:27:19 core-01 docker[12310]: Error response from daemon: no such id: httpd-8081
Jun 23 12:27:19 core-01 docker[12310]: time="2015-06-23T12:27:19Z" level=fatal msg="Error: failed to kill one or more containers"
Jun 23 12:27:19 core-01 docker[12314]: Error response from daemon: no such id: httpd-8081
Jun 23 12:27:19 core-01 docker[12314]: time="2015-06-23T12:27:19Z" level=fatal msg="Error: failed to remove one or more containers"


core@core-01 ~/share/services $ fleetctl journal httpd@8081
-- Logs begin at Mon 2015-06-22 19:06:19 UTC, end at Tue 2015-06-23 12:27:25 UTC. --
Jun 23 12:27:23 core-01 etcdctl[12336]: Running
Jun 23 12:27:23 core-01 docker[12335]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.0.30. Set the 'ServerName' directive globally to suppress this message
Jun 23 12:27:23 core-01 docker[12335]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.0.30. Set the 'ServerName' directive globally to suppress this message
Jun 23 12:27:23 core-01 docker[12335]: [Tue Jun 23 12:27:23.407605 2015] [mpm_event:notice] [pid 1:tid 140482060887936] AH00489: Apache/2.4.12 (Unix) configured -- resuming normal operations
Jun 23 12:27:23 core-01 docker[12335]: [Tue Jun 23 12:27:23.408928 2015] [core:notice] [pid 1:tid 140482060887936] AH00094: Command line: 'httpd -D FOREGROUND'
Jun 23 12:27:23 core-01 systemd[1]: Started httpd-8081.
Jun 23 12:27:23 core-01 docker[12335]: [Tue Jun 23 12:27:23.506820 2015] [mpm_event:notice] [pid 1:tid 140482060887936] AH00494: SIGHUP received.  Attempting to restart
Jun 23 12:27:23 core-01 docker[12335]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.1.0.30. Set the 'ServerName' directive globally to suppress this message
Jun 23 12:27:23 core-01 docker[12335]: [Tue Jun 23 12:27:23.514376 2015] [mpm_event:notice] [pid 1:tid 140482060887936] AH00489: Apache/2.4.12 (Unix) configured -- resuming normal operations
Jun 23 12:27:23 core-01 docker[12335]: [Tue Jun 23 12:27:23.514803 2015] [core:notice] [pid 1:tid 140482060887936] AH00094: Command line: 'httpd -D FOREGROUND'

Finally CoreOs startid to give me some success. :) What I want to do is to make dockerised Xampp for my web design projects. But my real intention is to learn a little bit server administration. Later on I want to get dirty a little bit with server-side javascripting.

Well, after weeks of reading finally I fired up my Apache server with a pure systemd file! :)

What I modified on the script is I use the shared public_html folder to host my modified httpd.conf file, which I copy into the container with bash when i start the service. Before that I copy out the original httpd.conf to custom location with docker cp (if I know well, you can use docker cp to copy into the container after Docker 1.7). This way I don't need Dockerfile to copy in and out files between host and quest, just only service files.

Now TODO for future is to build a Wordpress environment and connect somehow the containers. I need mysql, php, phpmyadmin, an ftp solution to apache and maybe some open source server administration tool, where I can create email addresses, FTP users, etc. The big problem that I see now is how I can solve to store the sql database on the host and getting used by the mysql docker container. Is this even possible? I want to make everything completely modular, where you can delete the container and fire up again without loosing important data.

István

Lantos István

unread,
Jun 23, 2015, 8:57:35 AM6/23/15
to Seán C. McCord, coreo...@googlegroups.com
One more question:

Why I need to define --rm in the ExecStart= line, if I defined the following?

ExecStartPre=-/usr/bin/docker kill httpd-%i
ExecStartPre=-/usr/bin/docker rm httpd-%i

Rob Szumski

unread,
Jun 23, 2015, 1:31:41 PM6/23/15
to Lantos István, "Seán C. McCord", coreo...@googlegroups.com
Your unit will start more quickly if it gets garbage collected at the end of it running. Those lines will clean it up if that process fails to complete (happens randomly). Otherwise you’ll pause on start for 2 or 3 seconds while docker does its magic.

Paul Morgan

unread,
Jun 23, 2015, 2:03:58 PM6/23/15
to Rob Szumski, Lantos István, Seán C. McCord, coreo...@googlegroups.com
On Tue, Jun 23, 2015 at 1:31 PM, Rob Szumski <rob.s...@coreos.com> wrote:
> Your unit will start more quickly if it gets garbage collected at the end of
> it running. Those lines will clean it up if that process fails to complete
> (happens randomly). Otherwise you’ll pause on start for 2 or 3 seconds while
> docker does its magic.

personally i rm in execstartpre for one big reason:
i want the chance to ship a stopped or failed container off-host for analysis.

--
Paul Morgan

Lantos István

unread,
Jun 24, 2015, 4:34:06 AM6/24/15
to coreo...@googlegroups.com
One more question:
What are the best practices to building dockerised apps on one host anyway? Build everything as possible (except database, load balancer) into one single image, or try to separate everything? Seems like having Apache and PHP in different containers can't work, so I downloading now the httpd with php image, but I think good idea to separate mysql. Good pratice to start with a basic Ubuntu (or Debian) image, exec in, start to build an environment for production use, test how it's working, than later create a Dockerfile with needed libs and apps for your use and when you finish fire-up with systemd? Looks like the most downloaded images in docker hub still can be very opinionated for production use.
Reply all
Reply to author
Forward
0 new messages