@@ -113,7 +113,7 @@ var cfg config
113
113
func init () {
114
114
user , err := util .GetUser ()
115
115
if err != nil {
116
- die ("cannot get current user: %v" , err )
116
+ log . Fatalf ("cannot get current user: %v" , err )
117
117
}
118
118
119
119
cmd .AddCommonFlags (CmdKeeper , & cfg .CommonConfig )
@@ -150,21 +150,6 @@ var managedPGParameters = []string{
150
150
"synchronous_standby_names" ,
151
151
}
152
152
153
- func stderr (format string , a ... interface {}) {
154
- out := fmt .Sprintf (format , a ... )
155
- fmt .Fprintln (os .Stderr , strings .TrimSuffix (out , "\n " ))
156
- }
157
-
158
- func stdout (format string , a ... interface {}) {
159
- out := fmt .Sprintf (format , a ... )
160
- fmt .Fprintln (os .Stdout , strings .TrimSuffix (out , "\n " ))
161
- }
162
-
163
- func die (format string , a ... interface {}) {
164
- stderr (format , a ... )
165
- os .Exit (1 )
166
- }
167
-
168
153
func readPasswordFromFile (filepath string ) (string , error ) {
169
154
fi , err := os .Lstat (filepath )
170
155
if err != nil {
@@ -485,7 +470,7 @@ func NewPostgresKeeper(cfg *config, end chan error) (*PostgresKeeper, error) {
485
470
return nil , fmt .Errorf ("failed to load keeper local state file: %v" , err )
486
471
}
487
472
if p .keeperLocalState .UID != "" && p .cfg .uid != "" && p .keeperLocalState .UID != p .cfg .uid {
488
- die ("saved uid %q differs from configuration uid: %q" , p .keeperLocalState .UID , cfg .uid )
473
+ log . Fatalf ("saved uid %q differs from configuration uid: %q" , p .keeperLocalState .UID , cfg .uid )
489
474
}
490
475
if p .keeperLocalState .UID == "" {
491
476
p .keeperLocalState .UID = cfg .uid
@@ -494,7 +479,7 @@ func NewPostgresKeeper(cfg *config, end chan error) (*PostgresKeeper, error) {
494
479
log .Infow ("uid generated" , "uid" , p .keeperLocalState .UID )
495
480
}
496
481
if err = p .saveKeeperLocalState (); err != nil {
497
- die ("error: %v" , err )
482
+ log . Fatalf ("error: %v" , err )
498
483
}
499
484
}
500
485
@@ -1737,7 +1722,7 @@ func keeper(c *cobra.Command, args []string) {
1737
1722
case "debug" :
1738
1723
slog .SetLevel (zap .DebugLevel )
1739
1724
default :
1740
- die ("invalid log level: %v" , cfg .LogLevel )
1725
+ log . Fatalf ("invalid log level: %v" , cfg .LogLevel )
1741
1726
}
1742
1727
if cfg .debug {
1743
1728
slog .SetDebug ()
@@ -1748,19 +1733,19 @@ func keeper(c *cobra.Command, args []string) {
1748
1733
}
1749
1734
1750
1735
if cfg .dataDir == "" {
1751
- die ("data dir required" )
1736
+ log . Fatalf ("data dir required" )
1752
1737
}
1753
1738
1754
1739
if err = cmd .CheckCommonConfig (& cfg .CommonConfig ); err != nil {
1755
- die (err .Error ())
1740
+ log . Fatalf (err .Error ())
1756
1741
}
1757
1742
1758
1743
if err = os .MkdirAll (cfg .dataDir , 0700 ); err != nil {
1759
- die ("cannot create data dir: %v" , err )
1744
+ log . Fatalf ("cannot create data dir: %v" , err )
1760
1745
}
1761
1746
1762
1747
if cfg .pgListenAddress == "" {
1763
- die ("--pg-listen-address is required" )
1748
+ log . Fatalf ("--pg-listen-address is required" )
1764
1749
}
1765
1750
1766
1751
ip := net .ParseIP (cfg .pgListenAddress )
@@ -1776,73 +1761,73 @@ func keeper(c *cobra.Command, args []string) {
1776
1761
}
1777
1762
}
1778
1763
if cfg .pgListenAddress == "" {
1779
- die ("--pg-listen-address is required" )
1764
+ log . Fatalf ("--pg-listen-address is required" )
1780
1765
}
1781
1766
1782
1767
if _ , ok := validAuthMethods [cfg .pgReplAuthMethod ]; ! ok {
1783
- die ("--pg-repl-auth-method must be one of: md5, trust" )
1768
+ log . Fatalf ("--pg-repl-auth-method must be one of: md5, trust" )
1784
1769
}
1785
1770
if cfg .pgReplUsername == "" {
1786
- die ("--pg-repl-username is required" )
1771
+ log . Fatalf ("--pg-repl-username is required" )
1787
1772
}
1788
1773
if cfg .pgReplAuthMethod == "trust" {
1789
- stdout ( "warning: not utilizing a password for replication between hosts is extremely dangerous" )
1774
+ log . Warn ( " not utilizing a password for replication between hosts is extremely dangerous" )
1790
1775
if cfg .pgReplPassword != "" || cfg .pgReplPasswordFile != "" {
1791
- die ("can not utilize --pg-repl-auth-method trust together with --pg-repl-password or --pg-repl-passwordfile" )
1776
+ log . Fatalf ("can not utilize --pg-repl-auth-method trust together with --pg-repl-password or --pg-repl-passwordfile" )
1792
1777
}
1793
1778
}
1794
1779
if cfg .pgSUAuthMethod == "trust" {
1795
- stdout ( "warning: not utilizing a password for superuser is extremely dangerous" )
1780
+ log . Warn ( " not utilizing a password for superuser is extremely dangerous" )
1796
1781
if cfg .pgSUPassword != "" || cfg .pgSUPasswordFile != "" {
1797
- die ("can not utilize --pg-su-auth-method trust together with --pg-su-password or --pg-su-passwordfile" )
1782
+ log . Fatalf ("can not utilize --pg-su-auth-method trust together with --pg-su-password or --pg-su-passwordfile" )
1798
1783
}
1799
1784
}
1800
1785
if cfg .pgReplAuthMethod != "trust" && cfg .pgReplPassword == "" && cfg .pgReplPasswordFile == "" {
1801
- die ("one of --pg-repl-password or --pg-repl-passwordfile is required" )
1786
+ log . Fatalf ("one of --pg-repl-password or --pg-repl-passwordfile is required" )
1802
1787
}
1803
1788
if cfg .pgReplAuthMethod != "trust" && cfg .pgReplPassword != "" && cfg .pgReplPasswordFile != "" {
1804
- die ("only one of --pg-repl-password or --pg-repl-passwordfile must be provided" )
1789
+ log . Fatalf ("only one of --pg-repl-password or --pg-repl-passwordfile must be provided" )
1805
1790
}
1806
1791
if _ , ok := validAuthMethods [cfg .pgSUAuthMethod ]; ! ok {
1807
- die ("--pg-su-auth-method must be one of: md5, password, trust" )
1792
+ log . Fatalf ("--pg-su-auth-method must be one of: md5, password, trust" )
1808
1793
}
1809
1794
if cfg .pgSUAuthMethod != "trust" && cfg .pgSUPassword == "" && cfg .pgSUPasswordFile == "" {
1810
- die ("one of --pg-su-password or --pg-su-passwordfile is required" )
1795
+ log . Fatalf ("one of --pg-su-password or --pg-su-passwordfile is required" )
1811
1796
}
1812
1797
if cfg .pgSUAuthMethod != "trust" && cfg .pgSUPassword != "" && cfg .pgSUPasswordFile != "" {
1813
- die ("only one of --pg-su-password or --pg-su-passwordfile must be provided" )
1798
+ log . Fatalf ("only one of --pg-su-password or --pg-su-passwordfile must be provided" )
1814
1799
}
1815
1800
1816
1801
if cfg .pgSUUsername == cfg .pgReplUsername {
1817
- stdout ( "warning: superuser name and replication user name are the same. Different users are suggested." )
1802
+ log . Warn ( " superuser name and replication user name are the same. Different users are suggested." )
1818
1803
if cfg .pgReplAuthMethod != cfg .pgSUAuthMethod {
1819
- die ("do not support different auth methods when utilizing superuser for replication." )
1804
+ log . Fatalf ("do not support different auth methods when utilizing superuser for replication." )
1820
1805
}
1821
1806
if cfg .pgSUPassword != cfg .pgReplPassword && cfg .pgSUAuthMethod != "trust" && cfg .pgReplAuthMethod != "trust" {
1822
- die ("provided superuser name and replication user name are the same but provided passwords are different" )
1807
+ log . Fatalf ("provided superuser name and replication user name are the same but provided passwords are different" )
1823
1808
}
1824
1809
}
1825
1810
1826
1811
if cfg .pgReplPasswordFile != "" {
1827
1812
cfg .pgReplPassword , err = readPasswordFromFile (cfg .pgReplPasswordFile )
1828
1813
if err != nil {
1829
- die ("cannot read pg replication user password: %v" , err )
1814
+ log . Fatalf ("cannot read pg replication user password: %v" , err )
1830
1815
}
1831
1816
}
1832
1817
if cfg .pgSUPasswordFile != "" {
1833
1818
cfg .pgSUPassword , err = readPasswordFromFile (cfg .pgSUPasswordFile )
1834
1819
if err != nil {
1835
- die ("cannot read pg superuser password: %v" , err )
1820
+ log . Fatalf ("cannot read pg superuser password: %v" , err )
1836
1821
}
1837
1822
}
1838
1823
1839
1824
// Open (and create if needed) the lock file.
1840
1825
// There is no need to clean up this file since we don't use the file as an actual lock. We get a lock
1841
- // on the file. So the lock get released when our process stops (or dies ).
1826
+ // on the file. So the lock get released when our process stops (or log.Fatalfs ).
1842
1827
lockFileName := filepath .Join (cfg .dataDir , "lock" )
1843
1828
lockFile , err := os .OpenFile (lockFileName , os .O_RDWR | os .O_CREATE , 0644 )
1844
1829
if err != nil {
1845
- die ("cannot take exclusive lock on data dir %q: %v" , lockFileName , err )
1830
+ log . Fatalf ("cannot take exclusive lock on data dir %q: %v" , lockFileName , err )
1846
1831
}
1847
1832
1848
1833
// Get a lock on our lock file.
@@ -1855,14 +1840,14 @@ func keeper(c *cobra.Command, args []string) {
1855
1840
1856
1841
err = syscall .FcntlFlock (lockFile .Fd (), syscall .F_SETLK , ft )
1857
1842
if err != nil {
1858
- die ("cannot take exclusive lock on data dir %q: %v" , lockFileName , err )
1843
+ log . Fatalf ("cannot take exclusive lock on data dir %q: %v" , lockFileName , err )
1859
1844
}
1860
1845
1861
1846
log .Infow ("exclusive lock on data dir taken" )
1862
1847
1863
1848
if cfg .uid != "" {
1864
1849
if ! pg .IsValidReplSlotName (cfg .uid ) {
1865
- die ("keeper uid %q not valid. It can contain only lower-case letters, numbers and the underscore character" , cfg .uid )
1850
+ log . Fatalf ("keeper uid %q not valid. It can contain only lower-case letters, numbers and the underscore character" , cfg .uid )
1866
1851
}
1867
1852
}
1868
1853
@@ -1885,7 +1870,7 @@ func keeper(c *cobra.Command, args []string) {
1885
1870
1886
1871
p , err := NewPostgresKeeper (& cfg , end )
1887
1872
if err != nil {
1888
- die ("cannot create keeper: %v" , err )
1873
+ log . Fatalf ("cannot create keeper: %v" , err )
1889
1874
}
1890
1875
go p .Start (ctx )
1891
1876
0 commit comments