Register System Service (on Ubuntu 18.04)

HN LEE
learn-backend
Published in
1 min readJun 30, 2020

How to register program as as a service on ubuntu 18.04

Environment

  • Ubuntu 18.04 (on AWS)

Step 1: Write Shell Script

# vim /<dir>/<fn>.sh
  • <fn>.sh
#!/bin/bash<shell scripts>

Step 2: Write Service File

# vim /etc/systemd/system/<service name>.service
  • <service name>.service
[Unit]
Description=Test Service
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/<dir>
ExecStart=/<dir>/<fn>.sh
Restart=always
[Install]
WantedBy=multi-user.target

Step 3: Register the Service

# systemctl daemon-reload
# systemctl enable <service name>
# systemctl start <service name>
# systemctl status <service name>

--

--

HN LEE
learn-backend

A Software Engineer who believes the tech could make the world better.