# Run as a service on Linux

#### 1. Create a Custom systemd Service

Create a Unit file to define a systemd service: \
File: `sudo vim /etc/systemd/system/myservice.service`

```toml
[Unit]
Description=Extension Name Service
After=network.target

[Service]
User=root
WorkingDirectory=/usr/local/bin
# when using config:
# ExecStart=/usr/local/bin/super-tables-linux
# when NOT using config:
# ExecStart=/usr/local/bin/super-tables-linux –-port 443 –-cert yourdomain.crt –-key yourdomain.key
Restart=always

[Install]
WantedBy=multi-user.target

```

This defines a simple service. The critical part is the `ExecStart` directive, which specifies the command that will be run to start the service.

#### 2. Give the service file the proper permissions

```bash
sudo chmod 644 /etc/systemd/system/myservice.service
```

**Start and Enable the Service**

1\. Once you have a unit file, you are ready to test the service:

```bash
sudo systemctl start myservice
```

2\. Check the status of the service:

```bash
sudo systemctl status myservice
```

If the service is running correctly, the output should resemble the following:

```bash
● myservice.service – Example systemd service.
Loaded: loaded (/lib/systemd/system/myservice.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-05-01 18:17:14 UTC; 4s ago
Main PID: 16266 (bash)
Tasks: 2 Memory: 748.0K CPU: 4ms CGroup: /system.slice/myservice.service
├─16266 /bin/bash /usr/bin/test_service.sh
└─16270 sleep 30
May 01 18:17:14 localhost systemd[1]: Started Example systemd service..
May 01 18:17:14 localhost cat[16269]: Example service started at 2018-05-01 18:17:14
May 01 18:17:14 localhost bash[16266]: Looping…
```

3\. The service can be stopped or restarted using standard \`systemd\` commands:

```bash
sudo systemctl stop myservice
sudo systemctl restart myservice
```

4\. Finally, use the enable command to ensure that the service starts whenever the system boots:

```bash
sudo systemctl enable myservice
```

5\. (*Optional*) Reboot your Server and check the status of the service:

```bash
sudo systemctl status myservice
```

You should see that the service logged its start time immediately after booting:

```bash
● myservice.service – Example systemd service.
Loaded: loaded (/usr/lib/systemd/system/myservice.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2018-05-02 15:03:07 UTC; 48s ago
Main PID: 2973 (bash)
CGroup: /system.slice/myservice.service
├─2973 /bin/bash /usr/bin/test_service.sh
└─3371 sleep 30
May 02 15:03:07 localhost systemd[1]: Started Example systemd service..
May 02 15:03:07 localhost systemd[1]: Starting Example systemd service….
May 02 15:03:07 localhost bash[2973]: Looping…
May 02 15:03:37 localhost bash[2973]: Looping…
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.infotopics.com/enterprise-installation/installation-guide/getting-started/linux/run-as-a-service-on-linux.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
