o serviço do usuário systemd não autorun no login do usuário

6

Eu tenho o Debian Jessie e me conecto a ele pelo ssh. Eu quero autostart comando shell no login do usuário pelo systemd.

Eu criei um serviço systemd simples ~/.config/systemd/user/foo.service witch contains:

[Unit]
Description=Systemd autostart test
Wants=local-fs.target
After=local-fs.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo 123 >> /home/user/there;"

[Install]
WantedBy=multi-user.target

Eu habilitei por systemctl

systemctl --user enable foo

Eu criei um contêiner de mensagens de sucesso

touch ~/there

e após a reinicialização e login (por ssh)% o arquivo~/there está vazio.

Quando eu uso manualmente

systemctl --user restart foo

funciona.

O que estou perdendo?

    
por vadim_shb 28.11.2015 / 09:11

2 respostas

3

Por padrão, os usuários não podem definir serviços do usuário para serem executados no momento da inicialização. O administrador deve habilitar isso individualmente para cada usuário.

sudo loginctl enable-linger <username>

Na documentação :

Enable/disable user lingering for one or more users. If enabled for a specific user, a user manager is spawned for the user at boot and kept around after logouts. This allows users who are not logged in to run long-running services. Takes one or more user names or numeric UIDs as argument. If no argument is specified, enables/disables lingering for the user of the session of the caller.

Você também precisa definir o alvo correto para WantedBy = como Climenty explicou em outra resposta . O multi-user.target não existe para serviços do usuário; por padrão, há apenas default.target .

[Install]
WantedBy=default.target
    
por 10.09.2016 / 19:00
1

Tente isso

[Install]    
WantedBy=default.target
    
por 10.09.2016 / 15:51