linux_wiki:systemd_service_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux_wiki:systemd_service_script [2018/03/23 14:49]
billdozor [The Service Unit File]
linux_wiki:systemd_service_script [2019/05/25 23:50] (current)
Line 118: Line 118:
 Jan 24 10:31:08 server1.local logger[17693]: /usr/local/bin/myprog.sh is still running... Jan 24 10:31:08 server1.local logger[17693]: /usr/local/bin/myprog.sh is still running...
 </code> </code>
 +
 +----
 +
 +===== Example: Docker Compose =====
 +
 +Putting docker-compose commands into a service.
 +
 +/etc/systemd/system/docker-compose.service
 +<code bash>
 +[Unit]
 +Description=Docker Compose Containers
 +Requires=docker.service
 +After=docker.service
 +
 +[Service]
 +Type=oneshot
 +RemainAfterExit=yes
 +ExecStart=/usr/local/bin/docker-compose -f /data/docker/docker-compose.yml up -d
 +ExecStop=/usr/local/bin/docker-compose -f /data/docker/docker-compose.yml down
 +
 +[Install]
 +WantedBy=multi-user.target
 +</code>
 +
 +----
 +
 +===== Example: Apache HTTPD Compiled =====
 +
 +Creating a service unit file for a locally compiled and installed Apache web server.
 +
 +\\
 +/etc/systemd/system/httpd-local.service
 +<code bash>
 +[Unit]
 +Description=Apache Web Server
 +After=network.target remote-fs.target nss-lookup.target
 +
 +[Service]
 +Type=forking
 +PIDFile=/usr/local/apache2/logs/httpd.pid
 +ExecStart=/usr/local/apache2/bin/apachectl start
 +ExecStop=/usr/local/apache2/bin/apachectl graceful-stop
 +ExecReload=/usr/local/apache2/bin/apachectl graceful
 +PrivateTmp=true
 +LimitNOFILE=infinity
 +
 +[Install]
 +WantedBy=multi-user.target
 +</code>
 +
 +\\
 +Reload systemd<code bash>systemctl daemon-reload</code>
 +
 +\\
 +Enable/start service<code bash>systemctl enable httpd-local
 +systemctl start httpd-local</code>
 +
 +----
 +
 +====== Override File ======
 +
 +Override files are used when you want to modify part or all of a RPM/system provided systemd unit file. Use over rides instead of directly modifying system unit files, as they could be reverted upon next related package update.
 +
 +System Provided unit files: /usr/lib/systemd/system/
 +
 +===== Override Example: docker service =====
 +
 +System provided file to over ride: /usr/lib/systemd/system/docker.service
 +
 +  * Create a directory to contain the over ride file (named after the original unit file name)<code bash>mkdir /etc/systemd/system/docker.service.d/</code>
 +  * Create the over ride file<code bash>/etc/systemd/system/docker.service.d/docker.conf
 +
 +[Service]
 +EnvironmentFile=
 +EnvironmentFile=-/etc/sysconfig/docker
 +ExecStart=
 +ExecStart=/usr/bin/dockerd $OPTIONS</code>
 +    * Each variable with a blank assignment ('EnvironmentFile=') clears that variable. If you did not put the assignment to nothing line, the variables would be appended to the built in values.
 +
 +  * Reload the systemd daemon for the override file to be picked up<code bash>systemctl daemon-reload</code>
 +
 +  * Restart the service
 +
 +===== Override Example: rpcbind service =====
 +
 +System provided file to over ride: /usr/lib/systemd/system/rpcbind.service
 +
 +  * Create a directory to contain the over ride file (named after the original unit file name, but add a ".d" for directory)<code bash>mkdir /etc/systemd/system/rpcbind.service.d/</code>
 +  * Create the over ride file (NAME.conf)<code bash>/etc/systemd/system/rpcbind.service.d/rpcbind.conf
 +
 +[Service]
 +ExecStart=
 +ExecStart=/sbin/rpcbind $RPCBIND_ARGS</code>
 +    * Each variable with a blank assignment ('EnvironmentFile=') clears that variable. If you did not put the assignment to nothing line, the variables would be appended to the built in values.
 +
 +  * Reload the systemd daemon for the override file to be picked up<code bash>systemctl daemon-reload</code>
 +
 +  * Restart the service
  
 ---- ----
  
  • linux_wiki/systemd_service_script.1521830982.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)