Custom System Services

You can also create your own system service in Docker Compose format. After creating your own custom service, you can launch it in RancherOS in a couple of methods. The service could be directly added to the cloud-config, or a docker-compose.yml file could be saved at a http(s) url location or in a specific directory of RancherOS.

Launching Services through Cloud-Config

If you want to boot RancherOS with a system service running, you can add the service to the cloud-config that is passed to RancherOS. When RancherOS starts, this service will automatically be started.

#cloud-configrancher:services:nginxapp:image:nginxrestart:always

Launching Services using local files

If you already have RancherOS running, you can start a system service by saving a docker-compose.yml file at /var/lib/rancher/conf/.

nginxapp:image:nginxrestart:always

To enable a custom system service from the file location, the command must indicate the file location if saved in RancherOS. If the file is saved at a http(s) url, just use the http(s) url when enabling/disabling.

# Enable the system service saved in /var/lib/rancher/conf
$ sudo ros service enable /var/lib/rancher/conf/example.yml
# Enable a system service saved at a http(s) url
$ sudo ros service enable https://mydomain.com/example.yml

After the custom system service is enabled, you can start the service using sudo ros service up <serviceName>. The <serviceName> will be the names of the services inside the docker-compose.yml.

$ sudo ros service up nginxapp
# If you have more than 1 service in your docker-compose.yml, add all service names to the command
$ sudo ros service up service1 service2 service3

Launching Services from a web repository

The config settings to set the url in which ros should look for an index.yml file is: rancher.repositories.<name>.url. The core repository url is set when a release is made, and any other <name> url you add will be listed together when running ros console list, ros service list or ros engine list

For example, in RancherOS v0.7.0, the core repository is set to https://raw.githubusercontent.com/rancher/os-services/v0.7.0.

Service development and testing

If you’re building your own services in a branch on GitHub, you can push to it, and then load your service from there.

Your service’s log rotation config will now be included when the system logrotate runs. You can view logrotate output with system-docker logs logrotate.

Creating your own Console

Once you have your own Services repository, you can add a new service to its index.yml, and then add a <service-name>.yml file to the directory starting with the first letter.

To create your own console images, you need to:

1 install some basic tools, including an ssh daemon, sudo, and kernel module tools
2 create rancher and docker users and groups with UID and GID’s of 1100 and 1101 respectively
3 add both users to the docker and sudo groups
4 add both groups into the /etc/sudoers file to allow password-less sudo
5 configure sshd to accept logins from users in the docker group, and deny root.
6 set ENTRYPOINT ["/usr/bin/ros", "entrypoint"]

the ros binary, and other host specific configuration files will be bind mounted into the running console container when its launched.