# Kiwiplan - VUE with systemd

# Introduction

This document it to setup auto restart of the VUE services after a server restart.

## Create The Following Files

### kiwiplan@.service

```shell
sudo vi /etc/systemd/system/kiwiplan@.service
```

Place the following in the file

```shell
[Unit]
Description=Kiwiplan services for %I
After=network-online.target mariadb.target

[Service]
Type=simple
User=remuser
Group=kiwiplan
ExecStart=/KIWI/services/servers.sh start %i
ExecStop=/KIWI/services/servers.sh stop %i
RemainAfterExit=true
PrivateTmp=false
LimitNOFILE=32768
LimitNPROC=32768
Environment=TERM=vt100

[Install]
WantedBy=multi-user.target
```

Reload the changes

```shell
sudo systemctl daemon-reload
```

### servers.sh

```shell
vi /KIWI/services/servers.sh
```

Place the following in the file

```shell
#!/bin/bash
if [ $# -gt 1 ]; then
  export TERM=vt100
  export LOG=/tmp/kiwiplan.$2.log
  echo $(date +'%Y-%m-%d %H:%M:%S') - $1 >> $LOG
  case "$1" in
    start)
       /KIWI/services/sites/$2/current/bin/startservers.sh >> $LOG 2>&1
       ;;
     stop)
       /KIWI/services/sites/$2/current/bin/stopservers.sh >> $LOG 2>&1
       ;;
     *)
       exit 1
       ;;
  esac
  exit 0
else
  echo "No Site passed"
  exit 1
fi
```

Make the file executable

```shell
chmod +x /opt/kiwi/services/servers.sh
```

### Run Configurations

For the VUE site named 'vue' use the following:

To have it start on boot run :

```shell
systemctl enable kiwiplan@vue.service 
```

To stop it from starting at boot time :

```shell
systemctl disable kiwiplan@vue.service
```

To start :

```shell
systemctl start kiwiplan@vue.service
```

 To stop :

```shell
systemctl stop kiwiplan@vue.service
```

 To view status :

```shell
systemctl -l status kiwiplan@vue.service
```