#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/local/bin/redis-server"
PIDFILE="/var/run/redis/redis_7128.pid"
RUNDIR="/var/run/redis"
REDIS_USER="redis"
DAEMON_ARGS="/etc/redis/redis_7128.conf"
REDISPORT="7128"
case "$1" in
start)
echo -n "Starting $DAEMON: "
touch $PIDFILE
chown redis:redis $PIDFILE
chmod 755 $RUNDIR
if [ -n "$ULIMIT" ]
then
ulimit -n $ULIMIT
fi
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid $REDIS_USER:$REDIS_USER --exec $DAEMON -- $DAEMON_ARGS
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry forever/TERM/1 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
then
echo "$NAME."
else
echo "failed"
fi
rm -f $PIDFILE
sleep 1
;;
restart|force-reload)
${0} stop
${0} start
;;
status)
echo -n "$DESC is "
if start-stop-daemon --stop --quiet --signal 0 --name ${NAME} --pidfile ${PIDFILE}
then
echo "running"
else
echo "not running"
exit 1
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
Eu tenho o script acima escrito para init.d
, quero transportá-lo para systemd
.
Eu tentei escrever o meu e salvei em /etc/systemd/system/redis.service
, mas as variáveis não estão expandindo
[Unit]
Description=My Redis Service
[Service]
Type=forking
#User=redis
Restart=on-failure
RemainAfterExit=yes
EnvironmentFile=/etc/systemd/system/redisenv
ExecStart=start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid $REDIS_USER:$REDIS_USER --exec $DAEMON -- $DAEMON_ARGS
ExecStart=echo -n "Starting $DAEMON: "
ExecStart=touch $PIDFILE
ExecStart=chown redis:redis $PIDFILE
ExecStart=chmod 755 $RUNDIR
ExecStart=if [ -n "$ULIMIT" ];then ulimit -n $ULIMIT ;fi
ExecStart=if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid $REDIS_USER:$REDIS_USER --exec $DAEMON -- $DAEMON_ARGS ;then echo "$NAME." ; else echo "failed"; fi
ExecStop=start-stop-daemon --stop --retry forever/TERM/1 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
[Install]
WantedBy=multi-user.target
E o EnvironmentFile
que escrevi para ele durante a portabilidade, salvei-o em /etc/systemd/system/redisenv
SECRET=pGNqduRFkB4K9C2vijOmUDa2kPtUhArN
ANOTHER_SECRET=JP8YLOc2bsNlrGuD6LVTq7L36obpjzxd
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/redis-server
PIDFILE=/var/run/redis/redis_6382.pid
RUNDIR=/var/run/redis
REDIS_USER=redis
DAEMON_ARGS=/etc/redis/redis_6382.conf
REDISPORT=6382
Depois disso eu fiz
sudo chmod 777 /etc/systemd/system/redis.service
sudo chmod 777 /etc/systemd/system/redisenv
sudo systemctl daemon-reload
sudo systemctl start redis-service
mas retorna
Failed to start redis.service: Unit redis.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status redis.service' for details.
e sudo systemctl status redis.service
retornam
● redis.service - My Redis Service
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Aug 14 19:11:31 squid2 systemd[1]: [/etc/systemd/system/redis.service:16] Executable path is not absolute, ignoring: if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid $REDIS_USER:$REDIS_USER --exec $DAEMON -- $DAEMON_ARGS ;then echo "$NAME." ;
Aug 14 19:11:31 squid2 systemd[1]: redis.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:10] Executable path is not absolute, ignoring: start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid $REDIS_USER:$REDIS_USER --exec $DAEMON -- $DAEMON_ARGS
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:11] Executable path is not absolute, ignoring: echo -n "Starting $DAEMON: "
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:12] Executable path is not absolute, ignoring: touch $PIDFILE
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:13] Executable path is not absolute, ignoring: chown redis:redis $PIDFILE
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:14] Executable path is not absolute, ignoring: chmod 755 $RUNDIR
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:15] Executable path is not absolute, ignoring: if [ -n "$ULIMIT" ];then ulimit -n $ULIMIT ;fi
Aug 14 19:11:37 squid2 systemd[1]: [/etc/systemd/system/redis.service:16] Executable path is not absolute, ignoring: if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid $REDIS_USER:$REDIS_USER --exec $DAEMON -- $DAEMON_ARGS ;then echo "$NAME." ;
Aug 14 19:11:37 squid2 systemd[1]: redis.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
Qualquer ajuda na portação do script init.d
para systemd
??
O primeiro problema que eu posso ver é que o script que as variáveis não são expansão de variável não está ocorrendo