Created
March 26, 2018 06:37
-
-
Save mthabsheer/3ad9aeb3d071c206a322eb7a90bbb796 to your computer and use it in GitHub Desktop.
Configuring Linux Services Using systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: create a file named "myservice.service" in /etc/systemd/system | |
Step 2: Copy the below code to the file. Replace the path/to/my/script with yours. | |
[Unit] | |
Description=My Service | |
After=network.target | |
# Mention the required service after which our myservice needs to start | |
After=mysql.service | |
Requires=mysql.service | |
[Service] | |
User=www-data | |
Group=www-data | |
ExecStart=/usr/bin/php path/to/my/script | |
Restart=on-failure | |
[Install] | |
WantedBy=multi-user.target | |
Step 3: To reflect the changes run the below command | |
systemctl daemon-reload | |
Step 4: Use the below commands to Start, restart and stop our service | |
systemctl start myservice | |
systemctl restart myservice | |
systemctl stop myservice |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment