From 188f870e1f3b41fca4e4a8e15f3e8f11f90a543d Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Sun, 16 May 2021 21:26:49 +1000 Subject: [PATCH] Add service --- categories/devops/linux.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/categories/devops/linux.md b/categories/devops/linux.md index c4bd0f9..9cd570f 100644 --- a/categories/devops/linux.md +++ b/categories/devops/linux.md @@ -2,6 +2,38 @@ ## Useful commands and tips +### Create a systemd service + +Create a file called `/etc/systemd/system/hello.service` + +``` +[Unit] +Description=Hello Service +After=network.target +StartLimitIntervalSec=0 +[Service] +Type=simple +Restart=always +RestartSec=1 +User=centos +ExecStart=/app/hello.sh + +[Install] +WantedBy=multi-user.target +``` +Automatically start the service when boot the vm + +```bash +sudo systemctl enable hello +``` + +Start service + +```bash +sudo systemctl start hello +``` +Learned from [here](https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6) + ### ssh Do not use default `22` port ```bash