{"action":"created","issue":{"url":"https://api.github.com/repos/coreos/rkt/issues/3168","repository_url":"https://api.github.com/repos/coreos/rkt","labels_url":"https://api.github.com/repos/coreos/rkt/issues/3168/labels{/name}","comments_url":"https://api.github.com/repos/coreos/rkt/issues/3168/comments","events_url":"https://api.github.com/repos/coreos/rkt/issues/3168/events","html_url":"https://github.com/coreos/rkt/issues/3168","id":175360914,"number":3168,"title":"How to: systemd + rkt prepare/run prepared","user":{"login":"lorddaedra","id":947642,"avatar_url":"https://avatars.githubusercontent.com/u/947642?v=3","gravatar_id":"","url":"https://api.github.com/users/lorddaedra","html_url":"https://github.com/lorddaedra","followers_url":"https://api.github.com/users/lorddaedra/followers","following_url":"https://api.github.com/users/lorddaedra/following{/other_user}","gists_url":"https://api.github.com/users/lorddaedra/gists{/gist_id}","starred_url":"https://api.github.com/users/lorddaedra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lorddaedra/subscriptions","organizations_url":"https://api.github.com/users/lorddaedra/orgs","repos_url":"https://api.github.com/users/lorddaedra/repos","events_url":"https://api.github.com/users/lorddaedra/events{/privacy}","received_events_url":"https://api.github.com/users/lorddaedra/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/coreos/rkt/labels/area/developer%20tooling","name":"area/developer tooling","color":"bfe5bf"},{"url":"https://api.github.com/repos/coreos/rkt/labels/area/usability","name":"area/usability","color":"bfe5bf"},{"url":"https://api.github.com/repos/coreos/rkt/labels/kind/documentation","name":"kind/documentation","color":"c7def8"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-06T21:51:25Z","updated_at":"2016-09-07T03:29:58Z","closed_at":null,"body":"**Environment**\r\n\r\nrkt Version: 1.14.0\r\nappc Version: 0.8.7\r\nGo Version: go1.6.3\r\nGo OS/Arch: linux/amd64\r\nFeatures: -TPM +SDJOURNAL\r\n--\r\nLinux 4.4.0-36-generic x86_64\r\n--\r\nNAME=\"Ubuntu\"\r\nVERSION=\"16.04.1 LTS (Xenial Xerus)\"\r\nID=ubuntu\r\nID_LIKE=debian\r\nPRETTY_NAME=\"Ubuntu 16.04.1 LTS\"\r\nVERSION_ID=\"16.04\"\r\nHOME_URL=\"http://www.ubuntu.com/\"\r\nSUPPORT_URL=\"http://help.ubuntu.com/\"\r\nBUG_REPORT_URL=\"http://bugs.launchpad.net/ubuntu/\"\r\nUBUNTU_CODENAME=xenial\r\n--\r\nsystemd 229\r\n+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN\r\n\r\n**What did you do?**\r\n\r\nI would like to find best way to restart several rkt pods in correct order, with minimal downtime. I use systemd on single node. \r\n\r\n**What did you expect to see?**\r\n\r\nDocs about how to integrate rkt prepare / rkt run-prepared with systemd. How to prepare pod before stopping and how to run prepared pod.\r\n\r\n**What did you see instead?**\r\n\r\nNo docs, some questions about it...\r\n\r\n\r\n===\r\n\r\nI have project, which contain 3 pods (each of pods is just 1 container with nginx [and static files], uwsgi [Django + project code] and Postgresql [project database]). \r\n\r\nI use 3 .service files to start/restart/stop them. I use Before= and After= to set correct order. (start order is postgresql->uwsgi->nginx, stop order is opposite nginx->uwsgi->postgresql)\r\n\r\nThis 3 .service files are PartOf=project.target and I use ```systemctl restart <project>.target ``` to restart them or update project containers to new version...\r\n\r\nThis works nice but I tried to optimise downtime during restart. (I use single node so it matter)...\r\n\r\nI need to  fetch images before stopping containers. I found solution here: http://unix.stackexchange.com/a/41756\r\n\r\nSo now I use separate 3 .service files (6 total now), which fetching images before stopping containers (I used After= and Before= to set correct order for them)... They use ExecStop= to do that.\r\n\r\nNow it works much better. my  ```systemctl restart <project>.target ```  now fetch images, stop old containers and start new.\r\n\r\nI would like to improve this solution even more. I would not just fetch images before stopping containers, I would like fetch and prepare them. And starting containers will mean just run-prepared. 9 .service files total.\r\n\r\nAnd there are some questions/problems. \r\nFirst of them is how to save id. I prefer save so file (/path/to/file) and in ExecStart= will be something like rkt run-prepared | cat /path/to/file\r\n\r\nAnother problem - how to deal with reboot. After reboot if use hack http://unix.stackexchange.com/a/41756 and put prepare action to ExecStop=, it will not execute this command. He will try run-prepared already used pod. How to deal with it?..\r\n\r\nInteresting to see, how to integrate systemd with rkt prepare/run-prepared. Solution should work in all cases: start after reboot, restart/update, stop before shutdown.\r\n\r\nCan I run already used pod via run-prepared?.. May be in <project>-<service>-run-prepared.service before ExecStart=/usr/bin/rkt run prepared | cat /path/to/file I need add another ExecStart, which will be execute /bin/bash -c '...' to check existance of id in /path/to/file and ability to run this pod (somehow check is it prepared or exited state), if something bad - try to restart project-service-prepare.service\r\n\r\nSo will be nice to see good article or answers about it..."},"comment":{"url":"https://api.github.com/repos/coreos/rkt/issues/comments/245164967","html_url":"https://github.com/coreos/rkt/issues/3168#issuecomment-245164967","issue_url":"https://api.github.com/repos/coreos/rkt/issues/3168","id":245164967,"user":{"login":"lorddaedra","id":947642,"avatar_url":"https://avatars.githubusercontent.com/u/947642?v=3","gravatar_id":"","url":"https://api.github.com/users/lorddaedra","html_url":"https://github.com/lorddaedra","followers_url":"https://api.github.com/users/lorddaedra/followers","following_url":"https://api.github.com/users/lorddaedra/following{/other_user}","gists_url":"https://api.github.com/users/lorddaedra/gists{/gist_id}","starred_url":"https://api.github.com/users/lorddaedra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lorddaedra/subscriptions","organizations_url":"https://api.github.com/users/lorddaedra/orgs","repos_url":"https://api.github.com/users/lorddaedra/repos","events_url":"https://api.github.com/users/lorddaedra/events{/privacy}","received_events_url":"https://api.github.com/users/lorddaedra/received_events","type":"User","site_admin":false},"created_at":"2016-09-07T03:29:57Z","updated_at":"2016-09-07T03:29:57Z","body":"Thank you! I will use it (#3005) after release. Currently I can use ```rkt prepare --quiet ... > /tmp/rkt/project/service/prepared-pod-uuid``` and ```rkt run-prepared | cat /tmp/rkt/project/service/prepared-pod-uuid```\r\n\r\nAbout orchestration: I know about Fleet and Kubernetes, they are nice tools, but not really simple and best way to work with rkt containers on single server, they are for clouds (3+ servers). [I know, I can create 3 virtual machines on this server, install CoreOS on each, create cluster... but...]\r\n\r\nsystemd is standard for most Linux-based OS'es so I tried to find way write several .service - files, .slice and .target and use simple command like ``` systemctl restart <project>.target``` to make updates...\r\n\r\nMy tags for production are immutable. Im my repository I use several tags and ```production``` tag special for current release.\r\n\r\nSo I pull image , for example with 1.1 tag, change tag to production and push it back to repository. It allows me have several versions of my project and rollback if I will need to do that but I do not need change my .service files on server every time I need new release, it save time... So I can just change tag to production in repository and restart target on server. It's easy. \r\n\r\nWhat is the best way to check pod state? via grep command?\r\n\r\n``` ExecStartPre=/bin/bash -c '/usr/bin/rkt list --full --no-legend | grep 'prepared' | grep -f /tmp/rkt/project/service/prepared-pod-uuid || /bin/systemctl  --no-block restart project-service-prepare.service '\r\n```\r\n(Interesting thing: this work if I restart this .service, but not if I restart .target (which contain this .service), may be I will put this command to separate .service file... also it freeze system without ``` --no-block ```)\r\n"}}
{"actor":{"display_login":"lorddaedra"}}