I have this systemd unit file and my attempt was to convert the existing init.d script to a systemd unit file. I am having trouble declaring the config file that should be used as declared in the init.d script.
Here is the init.d script:
# The following variables can be overwritten in $DEFAULT
# maximum number of open files
MAX_OPEN_FILES=
# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
fi
# set maximum open files if set
if [ -n "$MAX_OPEN_FILES" ]; then
ulimit -n $MAX_OPEN_FILES
fi
get_user_shell() {
local shell=$(getent passwd ${1:-`whoami`} | cut -d: -f7 | sed -e 's/[[:space:]]*$//')
if [[ $shell == *"/sbin/nologin" ]] || [[ $shell == "/bin/false" ]] || [[ -z "$shell" ]];
then
shell="/bin/bash"
fi
echo "$shell"
}
super() {
local shell=$(get_user_shell $USER)
su - $USER -s $shell -c "PATH=$PATH; PM2_HOME=$PM2_HOME $*"
}
start() {
echo "Starting $NAME"
super $PM2 start --only="$PM2_APP_NAME" --env=production $PM2_CONFIG_FILE
}
stop() {
super $PM2 stop --only="$PM2_APP_NAME" $PM2_CONFIG_FILE
$PM2 kill
}
restart() {
echo "Restarting $NAME"
stop
start
}
reload() {
echo "Reloading $NAME"
super $PM2 reload --only="$PM2_APP_NAME" $PM2_CONFIG_FILE
}
status() {
echo "Status for $NAME:"
super $PM2 list
RETVAL=$?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
reload)
reload
;;
force-reload)
reload
;;
*)
echo "Usage: {start|stop|status|restart|reload|force-reload}"
exit 1
;;
esac
exit $RETVAL
And here is my attempt so far of the systemd unit file:
[Unit]
Description=app1
Documentation=https://pm2.keymetrics.io/
After=network.target
[Service]
Type=forking
User=appuser
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Environment=PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/bin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Environment=PM2_HOME=/home/appuser/.pm2
PIDFile=/home/appuser/.pm2/pm2.pid
Restart=on-failure
ExecStart=/home/appuser/products/services/ash/releases/2.10.0/node_modules/pm2/bin/pm2 "-c /home/appuser/products/services/app1/current/ecosystem.config.js"
ExecReload=/home/appuser/products/services/ash/releases/2.10.0/node_modules/pm2/bin/pm2 reload all
ExecStop=/home/appuser/products/services/ash/releases/2.10.0/node_modules/pm2/bin/pm2 kill
[Install]
WantedBy=multi-user.target
So far I cannot get this to work?