Após compilar o Samba 4 no CentOS precisamos criar a Unit para gerenciamento do serviço, na documentação do Samba 4 possui um InitScript para rodar com SystemV ao qual pode ser criado no CentOS 7 e também controlado pelo SystemD, porém nos packages do Samba 4 possui o script default para utilizar em SystemD, após algumas horas acertando e testando encontrei a forma de utilizar.
Utilizar o InitScript do SystemV no CentOS 7:
1 - Criar script
1 |
# touch /etc/init.d/samba |
1 |
# chmod +x /etc/init.d/samba |
1 |
# vi /etc/init.d/samba |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
#!/bin/bash # # samba4 This shell script takes care of starting and stopping # samba4 daemons. # # chkconfig: - 58 74 # description: Samba 4.0 will be the next version of the Samba suite # and incorporates all the technology found in both the Samba4 alpha # series and the stable 3.x series. The primary additional features # over Samba 3.6 are support for the Active Directory logon protocols # used by Windows 2000 and above. ### BEGIN INIT INFO # Provides: samba4 # Required-Start: $network $local_fs $remote_fs # Required-Stop: $network $local_fs $remote_fs # Should-Start: $syslog $named # Should-Stop: $syslog $named # Short-Description: start and stop samba4 # Description: Samba 4.0 will be the next version of the Samba suite # and incorporates all the technology found in both the Samba4 alpha # series and the stable 3.x series. The primary additional features # over Samba 3.6 are support for the Active Directory logon protocols # used by Windows 2000 and above. ### END INIT INFO # Source function library. . /etc/init.d/functions # Source networking configuration. . /etc/sysconfig/network prog=samba prog_dir=/usr/local/samba/sbin lockfile=/var/lock/subsys/$prog start() { [ "$NETWORKING" = "no" ] && exit 1 # [ -x /usr/sbin/ntpd ] || exit 5 # Start daemons. echo -n $"Starting samba4: " daemon $prog_dir/$prog -D RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile return $RETVAL } stop() { [ "$EUID" != "0" ] && exit 4 echo -n $"Shutting down samba4: " killproc $prog_dir/$prog RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $lockfile return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart) stop start ;; reload) echo "Not implemented yet." exit 3 ;; *) echo $"Usage: $0 {start|stop|status|restart|reload}" exit 2 esac |
2 - Criar Unit a partir do Script acima, adicionar a inicialização, neste formato é criado uma Unit que chamado o Script e gerencia o serviço, ou seja, um gerenciamento escravo
1 |
# chkconfig --add samba |
1 |
# chkconfig samba on |
1 2 |
# systemctl status samba # systemctl start samba |
https://wiki.samba.org/index.php/Samba4/InitScript
Utilizar Unit do SystemD no CentOS 7:
1 - Criar a Unit
1 |
# touch /etc/systemd/system/samba.service |
1 |
# vi /etc/systemd/system/samba.service |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[Unit] Description=Samba AD Daemon After=syslog.target network.target [Service] Type=forking NotifyAccess=all PIDFile=/usr/local/samba/var/run/samba.pid LimitNOFILE=16384 EnvironmentFile=-/etc/sysconfig/samba ExecStart=/usr/local/samba/sbin/samba -D ExecReload=/usr/bin/kill -HUP $MAINPID ExecStop=/usr/bin/killall samba Restart=on-failure [Install] WantedBy=multi-user.target |
2 - Reiniciar daemon do SystemD e validar Unit
1 |
# systemctl daemon-reload |
1 |
# systemctl enable samba |
1 |
# systemctl start samba |
1 |
# systemctl status samba |
1 |
# systemctl stop samba |
3 - Observação
No CentOS 7 Minimal o comando "killall" vem no pacote "psmisc", portanto instalar o mesmo.
Valide o diretórios que se encontram o binários do Samba 4.
No pacote do Samba 4, o exemplo de Unit se encontra dentro de "samba-4.X.X/packaging/systemd/".