Skip to content

Instantly share code, notes, and snippets.

@mthabsheer
Created March 26, 2018 06:37
Show Gist options
  • Save mthabsheer/3ad9aeb3d071c206a322eb7a90bbb796 to your computer and use it in GitHub Desktop.
Save mthabsheer/3ad9aeb3d071c206a322eb7a90bbb796 to your computer and use it in GitHub Desktop.
Configuring Linux Services Using systemd
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