I created the following service, amos.service, and it needs to run as amos (member of the amos group)
[Unit]
Description=AMOS Service
After=network.target
[Service]
User=amos
Group=amos
Type=simple
WorkingDirectory=/usr/share/amos
ExecStart=/usr/share/amos/amos_service.sh start
ExecStop=/usr/share/amos/amos_service.sh stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
all the permissions have been set on /usr/share/amos
to amos:amos
the amos_service.sh is as follows:
#!/bin/bash
CUDIR=$(dirname "$0")
cd /usr/share/amos
start() {
exec /usr/share/amos/run_amos.sh >> /var/log/amos.log 2>&1
}
stop() {
exec pkill java
}
case $1 in
start|stop) "$1" ;;
esac
cd "$CURDIR"
When I run the service initially without any modifications to the directories, meaning, belonging to root, and amos.service not having the User not Group parameter, everything runs great!
Once I change the directories permissions to amos:amos and add the amos.service User & Group, the serive won't work and I get the following : See attached image
/var/log
is owned by root. I think you want to use a directory/var/log/amos/
which you create as owned by amos.exec pkill java
is really bad! If you have any other service using Java, oh well...