Instalei o Shadowsocks-r no meu servidor CentOS 7 e quero usar o systemd para gerenciá-lo. Então criei um arquivo em /etc/systemd/system chamado shadowsocks-r.service.
shadowsocks-r.service:
[Unit]
Description=Shadowsocks-R Server
After=network.target
[Service]
ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start
ExecStop=/etc/init.d/shadowsocks-r stop
[Install]
WantedBy=multi-user.target
Mas o serviço não pôde ser iniciado corretamente. Ao verificar o status do serviço, abaixo está o que recebo:
shadowsocks-r.service - Shadowsocks-R Server
Loaded: loaded (/etc/systemd/system/shadowsocks-r.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Tue 2019-05-14 10:29:46 UTC; 8s ago
Process: 19267 ExecStop=/etc/init.d/shadowsocks-r stop (code=exited, status=0/SUCCESS)
Process: 19234 ExecStart=/etc/init.d/shadowsocks-r start (code=exited, status=0/SUCCESS)
Main PID: 19234 (code=exited, status=0/SUCCESS)
May 14 10:29:46 vultr.guest systemd[1]: Started Shadowsocks-R Server.
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: 2019-05-14 10:29:46 INFO util.py:94 loading libcrypto from libcrypto.so.10
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: 2019-05-14 10:29:46 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: IPv6 support
May 14 10:29:46 vultr.guest shadowsocks-r[19234]: Starting ShadowsocksR success
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: 2019-05-14 10:29:46 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: IPv6 support
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: stopped
May 14 10:29:46 vultr.guest shadowsocks-r[19267]: Stopping ShadowsocksR success
As mensagens shadowsocks-r são da função iniciar e parar. Pela mensagem, parece que as funções de início e parada foram executadas. Por que isso aconteceu e o que devo fazer para corrigi-lo? obrigado!
Atualizar:
Depois de correr systemctl start shadowsocks-r.service
, tentei correr journalctl -xe
e é isso que recebo:
May 14 11:09:01 vultr.guest systemd[1]: Started Shadowsocks-R Server.
-- Subject: Unit shadowsocks-r.service has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit shadowsocks-r.service has finished starting up.
--
-- The start-up result is done.
May 14 11:09:01 vultr.guest polkitd[1547]: Unregistered Authentication Agent for unix-process:19521:1303198 (system bus name :1.57, object path
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: 2019-05-14 11:09:01 INFO util.py:94 loading libcrypto from libcrypto.so.10
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: 2019-05-14 11:09:01 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: IPv6 support
May 14 11:09:01 vultr.guest shadowsocks-r[19527]: Starting ShadowsocksR success
May 14 11:09:01 vultr.guest shadowsocks-r[19560]: 2019-05-14 11:09:01 INFO shell.py:74 ShadowsocksR 2.8.2
May 14 11:09:02 vultr.guest shadowsocks-r[19560]: IPv6 support
May 14 11:09:02 vultr.guest shadowsocks-r[19560]: stopped
May 14 11:09:02 vultr.guest shadowsocks-r[19560]: Stopping ShadowsocksR success
------Atualizar------
Agora tentei mais alguns e está confirmado que o comando systemctl realmente interrompeu o processo mesmo quando usei o comando "iniciar". Aqui está o que eu tentei:
- Primeiro eu começo o processo por
/etc/init.d/shadowsocks-r start
E o terminal retorna:
IPv6 support
2019-05-16 08:39:30 INFO util.py:94 loading libcrypto from libcrypto.so.10
2019-05-16 08:39:30 INFO shell.py:74 ShadowsocksR 2.8.2
started
Starting ShadowsocksR success
- Então eu corro
systemctl start shadowsocks-r.service
- Então eu corro
/etc/init.d/shadowsocks-r status
e o resultado é:ShadowsocksR is stopped
Então, mesmo quando eu iniciei o processo shadowsocks-r usando outro método, o systemctl irá eliminá-lo mesmo quando eu tentar iniciá-lo.
- Executando
systemctl status shadowsocks-r.service
, aqui está o que recebo:
shadowsocks-r.service - Shadowsocks-R Server
Loaded: loaded (/etc/systemd/system/shadowsocks-r.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2019-05-16 08:45:10 UTC; 12min ago
Process: 713 ExecStop=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d stop (code=exited, status=0/SUCCESS)
Process: 686 ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start (code=exited, status=1/FAILURE)
Main PID: 686 (code=exited, status=1/FAILURE)
May 16 08:45:10 vultr.guest server.py[686]: 2019-05-16 08:45:10 INFO shell.py:74 ShadowsocksR 2.8.2
May 16 08:45:10 vultr.guest server.py[686]: 2019-05-16 08:45:10 ERROR daemon.py:75 already started at pid 670
May 16 08:45:10 vultr.guest server.py[686]: IPv6 support
May 16 08:45:10 vultr.guest server.py[686]: IPv6 support
May 16 08:45:10 vultr.guest systemd[1]: shadowsocks-r.service: main process exited, code=exited, status=1/FAILURE
May 16 08:45:10 vultr.guest server.py[713]: 2019-05-16 08:45:10 INFO shell.py:74 ShadowsocksR 2.8.2
May 16 08:45:10 vultr.guest server.py[713]: IPv6 support
May 16 08:45:10 vultr.guest server.py[713]: stopped
May 16 08:45:10 vultr.guest systemd[1]: Unit shadowsocks-r.service entered failed state.
May 16 08:45:10 vultr.guest systemd[1]: shadowsocks-r.service failed.
-------Atualizar --------
Por sugestão de @Daniel B, removi a linha ExecStop no arquivo de serviço:
[Unit]
Description=Shadowsocks-R Server
After=network.target
[Service]
ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start
[Install]
WantedBy=multi-user.target
Eu primeiro paro o processo server.py /etc/init.d/shadowsocks-r stop
e ele retornaShadowsocksR is stopped
Então eu corro
systemctl daemon-reload
systemctl start shadowsocks-r.service
systemctl status shadowsocks-r.service
Ainda recebo a mensagem de erro e parece que o comando systemctl não pôde iniciar o processo (antes de iniciar, pare o processo)
shadowsocks-r.service - Shadowsocks-R Server
Loaded: loaded (/etc/systemd/system/shadowsocks-r.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Thu 2019-05-16 09:40:43 UTC; 29s ago
Process: 2964 ExecStart=/usr/local/shadowsocks/server.py -c /etc/shadowsocks-r/config.json -d start (code=exited, status=0/SUCCESS)
Main PID: 2964 (code=exited, status=0/SUCCESS)
May 16 09:40:43 vultr.guest systemd[1]: Started Shadowsocks-R Server.
May 16 09:40:43 vultr.guest server.py[2964]: 2019-05-16 09:40:43 INFO util.py:94 loading libcrypto from libcrypto.so.10
May 16 09:40:43 vultr.guest server.py[2964]: 2019-05-16 09:40:43 INFO shell.py:74 ShadowsocksR 2.8.2
May 16 09:40:43 vultr.guest server.py[2964]: IPv6 support
Você não está especificando o
Type
. Por padrão, ésimple
, que espera que o processo do serviço não saia.De acordo com a página do projeto , correr em primeiro plano é tão simples quanto não passar
-d start
.O arquivo de unidade completo ficaria assim:
O Systemd cuidará automaticamente do monitoramento do processo, reiniciando-o e parando-o conforme solicitado/requerido.
colocar isso em serviço