Commit 5826156b authored by Jondy Zhao's avatar Jondy Zhao

Fix cron doesn't work

parent 0bb581dd
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
<listitem><para>Command Console</para></listitem> <listitem><para>Command Console</para></listitem>
<listitem><para>User Guide</para></listitem> <listitem><para>User Guide</para></listitem>
</itemizedlist> </itemizedlist>
<note><para>On Windows Vista or Windows 7, you need to run as administrator when launching the cygwin shell to allow the registry changes required in some of the steps below. You can configure cygwin to always launch with admin privileges if you wish.</para></note>
</para> </para>
<section id="sec_configure_slapos"><title>Configure SlapOS</title> <section id="sec_configure_slapos"><title>Configure SlapOS</title>
<para>It used to generate all the configure files required by slapos slave node, you can run it anytime when you need change the configure of your slapos slave node.</para> <para>It used to generate all the configure files required by slapos slave node, you can run it anytime when you need change the configure of your slapos slave node.</para>
...@@ -154,7 +155,7 @@ netsh interface ipv6 show interface ...@@ -154,7 +155,7 @@ netsh interface ipv6 show interface
Check localize connection name show correctly. If not, you need set your locale and charset Check localize connection name show correctly. If not, you need set your locale and charset
<programlisting> <programlisting>
echo "Locale=C" >> ~/.bashrc echo "Locale=C" >> ~/.bashrc
echo "Charset=$(python -c 'import sys; print sys.getfilesystemencoding()')" >> ~/.bashrc echo "Charset=$(ipwin codepage)" >> ~/.bashrc
tail ~/.bashrc tail ~/.bashrc
</programlisting> </programlisting>
Then restart your command terminal. Then restart your command terminal.
......
...@@ -52,6 +52,7 @@ for name in $(net user) ; do ...@@ -52,6 +52,7 @@ for name in $(net user) ; do
net user $name /delete net user $name /delete
fi fi
done done
mkpasswd -l > /etc/passwd
# #
# Remove local group installed by slapos node # Remove local group installed by slapos node
...@@ -62,6 +63,15 @@ for name in $(net localgroup | sed -n -e "s/^*//p" | sed -e "s/\\s//g") ; do ...@@ -62,6 +63,15 @@ for name in $(net localgroup | sed -n -e "s/^*//p" | sed -e "s/\\s//g") ; do
net localgroup $name /delete net localgroup $name /delete
fi fi
done done
mkgroup -l > /etc/group
#
# Remove configure files
#
echo Removing /etc/opt/slapos
rm -rf /etc/opt/slapos/
echo Removing ~/.slapos
rm -rf ~/.slapos
# #
# Remove slapos-configure from windows startup item # Remove slapos-configure from windows startup item
......
...@@ -15,7 +15,7 @@ Uninstallable=yes ...@@ -15,7 +15,7 @@ Uninstallable=yes
Name: "{app}\cygwin" Name: "{app}\cygwin"
Name: "{app}\cygwin\opt\slapos" Name: "{app}\cygwin\opt\slapos"
Name: "{app}\cygwin\opt\downloads" Name: "{app}\cygwin\opt\downloads"
Name: "{app}\cygwin\usr\local\bin" Name: "{app}\cygwin\bin"
Name: "{app}\cygwin\etc\slapos\driver" Name: "{app}\cygwin\etc\slapos\driver"
Name: "{app}\cygwin\etc\slapos\scripts" Name: "{app}\cygwin\etc\slapos\scripts"
Name: "{app}\cygwin\etc\slapos\images" Name: "{app}\cygwin\etc\slapos\images"
...@@ -46,7 +46,7 @@ Source: "opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin ...@@ -46,7 +46,7 @@ Source: "opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin
Source: "opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\scripts\cyg_wscript"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\slapos_cron_config"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\ipwin\ipwin\ipwin.exe"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\ipwin\ipwin\ipwin.exe"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
......
...@@ -62,6 +62,7 @@ fi ...@@ -62,6 +62,7 @@ fi
# openssl # openssl
# export WINDIR # export WINDIR
# ipwin # ipwin
# slapos_cron_config
# ----------------------------------------------------------- # -----------------------------------------------------------
# Create paths # Create paths
...@@ -77,21 +78,15 @@ mkdir -p /etc/re6stnet ...@@ -77,21 +78,15 @@ mkdir -p /etc/re6stnet
# ----------------------------------------------------------- # -----------------------------------------------------------
# Create account: slaproot # Create account: slaproot
# ----------------------------------------------------------- # -----------------------------------------------------------
if csih_privileged_account_exists $slapos_administrator
then
echo $slapos_administrator has been existed.
csih_account_has_necessary_privileges $slapos_administrator
else
echo create account $slapos_administrator
csih_FORCE_PRIVILEGED_USER=yes
slapos_create_privileged_user || exit 1
_password=$csih_PRIVILEGED_PASSWORD
fi
# Start seclogon service in the Windows XP # Start seclogon service in the Windows XP
# sc config seclogon start=auto csih_is_xp && sc config seclogon start= auto
# In the later, it's RunAs service, and will start by default # In the later, it's RunAs service, and will start by default
# echo Checking slapos account $slapos_admin ...
slapos_check_and_create_privileged_user $slapos_admin ||
show_error_exit "Failed to create account $slapos_admin."
_password="${csih_PRIVILEGED_PASSWORD}"
# ----------------------------------------------------------- # -----------------------------------------------------------
# Configure cygwin services: cygserver syslog-ng sshd # Configure cygwin services: cygserver syslog-ng sshd
# ----------------------------------------------------------- # -----------------------------------------------------------
...@@ -117,39 +112,35 @@ fi ...@@ -117,39 +112,35 @@ fi
check_cygwin_service syslog-ng check_cygwin_service syslog-ng
if ! cygrunsrv --query sshd > /dev/null 2>&1 ; then if ! cygrunsrv --query sshd > /dev/null 2>&1 ; then
if csih_is_xp && [[ -z "${_password}" ]] ; then
slapos_request_password $slapos_admin "Install sshd service need the password of $slapos_admin."
fi
echo Run ssh-host-config ... echo Run ssh-host-config ...
/usr/bin/ssh-host-config --yes --cygwin ntsec \ /usr/bin/ssh-host-config --yes --cygwin ntsec \
--user $slapos_administrator --pwd ${_password} || --user $slapos_admin --pwd ${_password} ||
show_error_exit "Failed to run ssh-host-config" show_error_exit "Failed to run ssh-host-config"
else else
echo The sshd service has been installed. echo The sshd service has been installed.
fi fi
check_cygwin_service sshd check_cygwin_service sshd
# # Use slapos-cron-config to configure slapos cron service.
# Use our own cron-config, no prompt
#
slapos_cron_config=/usr/local/bin/slapos-cron-config
if [[ ! -r $slapos_cron_config ]] ; then
cp -a /usr/bin/cron-config $slapos_cron_config
sed -i -e "s%elif request \"Do you want to install the cron daemon as a service.*$%else%g" \
-e 's/getcygenv " "/cygenv="ntsec"/g' \
-e "s/request \"Do you want the cron daemon to run as yourself\?\"/username=$slapos_administrator/g" \
$slapos_cron_config
fi
if ! cygrunsrv --query cron > /dev/null 2>&1 ; then if ! cygrunsrv --query cron > /dev/null 2>&1 ; then
echo Run cron-config ... [[ -x $slapos_cron_config ]] ||
if [[ -z "${_password}" ]] ; then show_error_exit "Couldn't find slapos cron config script: $slapos_cron_config"
csih_inform "Install cron service need the password of $slapos_administrator."
csih_get_value "Please enter the password:" -s if csih_is_xp && [[ -z "${_password}" ]] ; then
_password="${csih_value}" slapos_request_password $slapos_admin "Install cron service need the password of $slapos_admin."
fi fi
$slapos_cron_config "${_password}" || show_error_exit "Failed to run cron-config"
echo Run slapos-cron-config ...
$slapos_cron_config $slapos_admin ${_password} || show_error_exit "Failed to run cron-config"
else else
echo The cron service has been installed. echo The cron service has been installed.
fi fi
check_cygwin_service cron check_cygwin_service cron
echo echo
echo Configure cygwin services OK. echo Configure cygwin services OK.
echo echo
...@@ -390,7 +381,7 @@ echo ...@@ -390,7 +381,7 @@ echo
if check_re6stnet_needed ; then if check_re6stnet_needed ; then
client_count=$(sed -n -e "s/^client-count *//p" $re6stnet_configure_file) client_count=$(sed -n -e "s/^client-count *//p" $re6stnet_configure_file)
[[ -z "$client_count" ]] && client_count=10 [[ -z "$client_count" ]] && client_count=10
echo " Client count: $client_count" echo "Re6stnet client-count: $client_count"
re6stnet_name_list="re6stnet-tcp re6stnet-udp" re6stnet_name_list="re6stnet-tcp re6stnet-udp"
for (( i=1; i<=client_count; i=i+1 )) ; do for (( i=1; i<=client_count; i=i+1 )) ; do
re6stnet_name_list="$re6stnet_name_list re6stnet$i" re6stnet_name_list="$re6stnet_name_list re6stnet$i"
...@@ -416,13 +407,11 @@ if check_re6stnet_needed ; then ...@@ -416,13 +407,11 @@ if check_re6stnet_needed ; then
check_re6stnet_configure || exit 1 check_re6stnet_configure || exit 1
if ! cygrunsrv --query $re6stnet_service_name >/dev/null 2>&1 ; then if ! cygrunsrv --query $re6stnet_service_name >/dev/null 2>&1 ; then
if [[ -z "${_password}" ]] ; then if [[ -z "${_password}" ]] ; then
csih_inform "Install re6stnet service need the password of $slapos_administrator." slapos_request_password $slapos_admin "Install re6stnet service need the password of $slapos_admin."
csih_get_value "Please enter the password:" -s
_password="${csih_value}"
fi fi
cygrunsrv -I $re6stnet_service_name -c $(dirname $re6stnet_configure_file) \ cygrunsrv -I $re6stnet_service_name -c $(dirname $re6stnet_configure_file) \
-p $(which re6stnet) -a "@re6stnet.conf" -d "CYGWIN re6stnet" \ -p $(which re6stnet) -a "@re6stnet.conf" -d "CYGWIN re6stnet" \
-u $slapos_administrator -w ${_password} || -u $slapos_admin -w ${_password} ||
show_error_exit "Failed to install cygwin service $re6stnet_service_name." show_error_exit "Failed to install cygwin service $re6stnet_service_name."
fi fi
echo "You can check log files in the /var/log/re6stnet/*.log" echo "You can check log files in the /var/log/re6stnet/*.log"
...@@ -526,28 +515,34 @@ echo ...@@ -526,28 +515,34 @@ echo
echo echo
echo Starting configure section cron ... echo Starting configure section cron ...
echo echo
cron_user=$slapos_administrator cron_user=$slapos_admin
crontab_file="/var/cron/tabs/$(whoami)" slapos_crontab_file="/var/cron/tabs/$cron_user"
if [[ ! -r $crontab_file ]] ; then if [[ ! -f $slapos_crontab_file ]] ; then
cat <<EOF > $crontab_file cat <<EOF > $slapos_crontab_file
SHELL=/bin/bash SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
MAILTO="" MAILTO=""
# Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute # Run "Installation/Destruction of Software Releases" and "Deploy/Start/Stop Partitions" once per minute
* * * * * $cron_user /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1 * * * * * /opt/slapos/bin/slapos node software --verbose --logfile=/opt/slapos/log/slapos-node-software.log > /dev/null 2>&1
* * * * * $cron_user /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1 * * * * * /opt/slapos/bin/slapos node instance --verbose --logfile=/opt/slapos/log/slapos-node-instance.log > /dev/null 2>&1
# Run "Destroy Partitions to be destroyed" once per hour # Run "Destroy Partitions to be destroyed" once per hour
0 * * * * $cron_user /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1 0 * * * * /opt/slapos/bin/slapos node report --maximal_delay=3600 --verbose --logfile=/opt/slapos/log/slapos-node-report.log > /dev/null 2>&1
# Run "Check/add IPs and so on" once per hour # Run "Check/add IPs and so on" once per hour
0 * * * * $cron_user /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1 0 * * * * /opt/slapos/bin/slapos node format >> /opt/slapos/log/slapos-node-format.log 2>&1
EOF EOF
echo Change owner of $slapos_crontab_file to $cron_user
chown $cron_user $slapos_crontab_file
echo Change mode of $slapos_crontab_file to 644
chmod 644 $slapos_crontab_file
else
ls -l $slapos_crontab_file
fi fi
echo echo
echo echo
cat $crontab_file || show_error_exit "No crob tab found." cat $slapos_crontab_file || show_error_exit "No crob tab found."
echo echo
echo Configure section cron OK. echo Configure section cron OK.
echo echo
......
This diff is collapsed.
...@@ -41,11 +41,12 @@ openvpn_tap_driver_hwid=tap0901 ...@@ -41,11 +41,12 @@ openvpn_tap_driver_hwid=tap0901
re6stnet_configure_file=/etc/re6stnet/re6stnet.conf re6stnet_configure_file=/etc/re6stnet/re6stnet.conf
re6stnet_service_name=re6stnet re6stnet_service_name=re6stnet
slapos_cron_config=/usr/bin/slapos-cron-config
slaprunner_startup_file=/etc/slapos/scripts/slap-runner.html slaprunner_startup_file=/etc/slapos/scripts/slap-runner.html
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=slapos-configure slapos_run_entry=slapos-configure
slapos_administrator=slaproot slapos_admin=slaproot
# ====================================================================== # ======================================================================
# Routine: check_cygwin_service # Routine: check_cygwin_service
...@@ -199,22 +200,39 @@ function start_cygwin_service() ...@@ -199,22 +200,39 @@ function start_cygwin_service()
[[ "$state" == "Running" ]] || return 1 [[ "$state" == "Running" ]] || return 1
} # === start_cygwin_service() === # } # === start_cygwin_service() === #
# ======================================================================
# Routine: slapos_request_password
# Get slaproot password, save it to _password
# ======================================================================
slapos_request_password()
{
local username="${1-slaproot}"
csih_inform "$2"
csih_get_value "Please enter the password:" -s
_password="${csih_value}"
if [ -z "${_password}" ]
then
csih_error_multi "Exiting configuration. I don't know the password of ${username}."
fi
} # === slapos_request_password() === #
# ====================================================================== # ======================================================================
# Routine: slapos_create_privileged_user # Routine: slapos_create_privileged_user
# #
# Copied from csih_create_privileged_user, just create fix account: # Copied from csih_check_and_create_privileged_user, just create fix account:
# slaproot # slaproot
# ====================================================================== # ======================================================================
slapos_create_privileged_user() slapos_check_and_create_privileged_user()
{ {
csih_stacktrace "${@}" csih_stacktrace "${@}"
$_csih_trace $_csih_trace
local username_in_sam local username_in_sam
local username local username="${1-slaproot}"
local admingroup local admingroup
local dos_var_empty local dos_var_empty
local _password local _password
local password_value="$1" local password_value="$2"
local passwd_has_expiry_flags local passwd_has_expiry_flags
local ret=0 local ret=0
local username_in_admingroup local username_in_admingroup
...@@ -226,9 +244,8 @@ slapos_create_privileged_user() ...@@ -226,9 +244,8 @@ slapos_create_privileged_user()
local tmpfile2 local tmpfile2
_csih_setup _csih_setup
csih_select_privileged_username -f -u $slapos_administrator
username="${csih_PRIVILEGED_USERNAME}" csih_PRIVILEGED_USERNAME="${username}"
if ! csih_privileged_account_exists "$csih_PRIVILEGED_USERNAME" if ! csih_privileged_account_exists "$csih_PRIVILEGED_USERNAME"
then then
...@@ -236,7 +253,7 @@ slapos_create_privileged_user() ...@@ -236,7 +253,7 @@ slapos_create_privileged_user()
dos_var_empty=$(/usr/bin/cygpath -w ${LOCALSTATEDIR}/empty) dos_var_empty=$(/usr/bin/cygpath -w ${LOCALSTATEDIR}/empty)
while [ "${username_in_sam}" != "yes" ] while [ "${username_in_sam}" != "yes" ]
do do
if [ -n "${password_value}" ] if [ -z "${password_value}" ]
then then
_password="${password_value}" _password="${password_value}"
csih_inform "Please enter a password for new user ${username}. Please be sure" csih_inform "Please enter a password for new user ${username}. Please be sure"
...@@ -286,7 +303,6 @@ slapos_create_privileged_user() ...@@ -286,7 +303,6 @@ slapos_create_privileged_user()
# ${username} already exists. Use it, and make no changes. # ${username} already exists. Use it, and make no changes.
# use passed-in value as first guess # use passed-in value as first guess
csih_PRIVILEGED_PASSWORD="${password_value}" csih_PRIVILEGED_PASSWORD="${password_value}"
return 0
fi fi
# username did NOT previously exist, but has been successfully created. # username did NOT previously exist, but has been successfully created.
...@@ -331,6 +347,7 @@ slapos_create_privileged_user() ...@@ -331,6 +347,7 @@ slapos_create_privileged_user()
ret=1 ret=1
fi fi
fi fi
fi # ! username_in_sam
# we just created the user, so of course it's in the local SAM, # we just created the user, so of course it's in the local SAM,
# and mkpasswd -l is appropriate # and mkpasswd -l is appropriate
...@@ -352,10 +369,8 @@ slapos_create_privileged_user() ...@@ -352,10 +369,8 @@ slapos_create_privileged_user()
echo "${pwd_entry}" >> "${SYSCONFDIR}/passwd" || ret=1 echo "${pwd_entry}" >> "${SYSCONFDIR}/passwd" || ret=1
fi fi
return "${ret}" return "${ret}"
fi # ! username_in_sam } # === End of csih_check_and_create_privileged_user() === #
return 1 readonly -f slapos_check_and_create_privileged_user
} # === End of csih_create_privileged_user() === #
readonly -f slapos_create_privileged_user
# ====================================================================== # ======================================================================
# Routine: create_template_configure_file # Routine: create_template_configure_file
......
...@@ -41,7 +41,7 @@ Source: "opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin ...@@ -41,7 +41,7 @@ Source: "opt\git\slapos.package\windows\scripts\usermod"; DestDir: "{app}\cygwin
Source: "opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\groupadd"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\brctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\tunctl"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\scripts\cyg_wscript"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\scripts\slapos_cron_config"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
Source: "opt\git\slapos.package\windows\ipwin\ipwin\ipwin.exe"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec; Source: "opt\git\slapos.package\windows\ipwin\ipwin\ipwin.exe"; DestDir: "{app}\cygwin\bin"; Permissions: everyone-readexec;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment