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

Fix cron doesn't work

parent 0bb581dd
......@@ -49,6 +49,7 @@
<listitem><para>Command Console</para></listitem>
<listitem><para>User Guide</para></listitem>
</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>
<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>
......@@ -154,7 +155,7 @@ netsh interface ipv6 show interface
Check localize connection name show correctly. If not, you need set your locale and charset
<programlisting>
echo "Locale=C" >> ~/.bashrc
echo "Charset=$(python -c 'import sys; print sys.getfilesystemencoding()')" >> ~/.bashrc
echo "Charset=$(ipwin codepage)" >> ~/.bashrc
tail ~/.bashrc
</programlisting>
Then restart your command terminal.
......
......@@ -52,6 +52,7 @@ for name in $(net user) ; do
net user $name /delete
fi
done
mkpasswd -l > /etc/passwd
#
# 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
net localgroup $name /delete
fi
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
......
......@@ -15,7 +15,7 @@ Uninstallable=yes
Name: "{app}\cygwin"
Name: "{app}\cygwin\opt\slapos"
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\scripts"
Name: "{app}\cygwin\etc\slapos\images"
......@@ -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\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\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;
......
......@@ -62,6 +62,7 @@ fi
# openssl
# export WINDIR
# ipwin
# slapos_cron_config
# -----------------------------------------------------------
# Create paths
......@@ -77,21 +78,15 @@ mkdir -p /etc/re6stnet
# -----------------------------------------------------------
# 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
# 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
# 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
# -----------------------------------------------------------
......@@ -117,39 +112,35 @@ fi
check_cygwin_service syslog-ng
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 ...
/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"
else
echo The sshd service has been installed.
fi
check_cygwin_service sshd
#
# 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
# Use slapos-cron-config to configure slapos cron service.
if ! cygrunsrv --query cron > /dev/null 2>&1 ; then
echo Run cron-config ...
if [[ -z "${_password}" ]] ; then
csih_inform "Install cron service need the password of $slapos_administrator."
csih_get_value "Please enter the password:" -s
_password="${csih_value}"
[[ -x $slapos_cron_config ]] ||
show_error_exit "Couldn't find slapos cron config script: $slapos_cron_config"
if csih_is_xp && [[ -z "${_password}" ]] ; then
slapos_request_password $slapos_admin "Install cron service need the password of $slapos_admin."
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
echo The cron service has been installed.
fi
check_cygwin_service cron
echo
echo Configure cygwin services OK.
echo
......@@ -390,7 +381,7 @@ echo
if check_re6stnet_needed ; then
client_count=$(sed -n -e "s/^client-count *//p" $re6stnet_configure_file)
[[ -z "$client_count" ]] && client_count=10
echo " Client count: $client_count"
echo "Re6stnet client-count: $client_count"
re6stnet_name_list="re6stnet-tcp re6stnet-udp"
for (( i=1; i<=client_count; i=i+1 )) ; do
re6stnet_name_list="$re6stnet_name_list re6stnet$i"
......@@ -403,7 +394,7 @@ if check_re6stnet_needed ; then
show_error_exit "Failed to install OpenVPN Tap-Windows Driver, missing driver inf file: $filename"
echo "Installing interface $name ..."
# ipwin install \"$filename\" $openvpn_tap_driver_hwid $name; ||
# ipwin install \"$filename\" $openvpn_tap_driver_hwid $name; ||
ip vpntap add dev $name ||
show_error_exit "Failed to install OpenVPN Tap-Windows Driver."
echo "Interface $name installed."
......@@ -416,13 +407,11 @@ if check_re6stnet_needed ; then
check_re6stnet_configure || exit 1
if ! cygrunsrv --query $re6stnet_service_name >/dev/null 2>&1 ; then
if [[ -z "${_password}" ]] ; then
csih_inform "Install re6stnet service need the password of $slapos_administrator."
csih_get_value "Please enter the password:" -s
_password="${csih_value}"
slapos_request_password $slapos_admin "Install re6stnet service need the password of $slapos_admin."
fi
cygrunsrv -I $re6stnet_service_name -c $(dirname $re6stnet_configure_file) \
-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."
fi
echo "You can check log files in the /var/log/re6stnet/*.log"
......@@ -526,28 +515,34 @@ echo
echo
echo Starting configure section cron ...
echo
cron_user=$slapos_administrator
crontab_file="/var/cron/tabs/$(whoami)"
if [[ ! -r $crontab_file ]] ; then
cat <<EOF > $crontab_file
cron_user=$slapos_admin
slapos_crontab_file="/var/cron/tabs/$cron_user"
if [[ ! -f $slapos_crontab_file ]] ; then
cat <<EOF > $slapos_crontab_file
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
MAILTO=""
# 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
* * * * * $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 software --verbose --logfile=/opt/slapos/log/slapos-node-software.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
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
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
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
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 Configure section cron OK.
echo
......
This diff is collapsed.
......@@ -41,11 +41,12 @@ openvpn_tap_driver_hwid=tap0901
re6stnet_configure_file=/etc/re6stnet/re6stnet.conf
re6stnet_service_name=re6stnet
slapos_cron_config=/usr/bin/slapos-cron-config
slaprunner_startup_file=/etc/slapos/scripts/slap-runner.html
slapos_run_key='\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
slapos_run_entry=slapos-configure
slapos_administrator=slaproot
slapos_admin=slaproot
# ======================================================================
# Routine: check_cygwin_service
......@@ -199,22 +200,39 @@ function start_cygwin_service()
[[ "$state" == "Running" ]] || return 1
} # === 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
#
# Copied from csih_create_privileged_user, just create fix account:
# Copied from csih_check_and_create_privileged_user, just create fix account:
# slaproot
# ======================================================================
slapos_create_privileged_user()
slapos_check_and_create_privileged_user()
{
csih_stacktrace "${@}"
$_csih_trace
local username_in_sam
local username
local username="${1-slaproot}"
local admingroup
local dos_var_empty
local _password
local password_value="$1"
local password_value="$2"
local passwd_has_expiry_flags
local ret=0
local username_in_admingroup
......@@ -226,9 +244,8 @@ slapos_create_privileged_user()
local tmpfile2
_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"
then
......@@ -236,7 +253,7 @@ slapos_create_privileged_user()
dos_var_empty=$(/usr/bin/cygpath -w ${LOCALSTATEDIR}/empty)
while [ "${username_in_sam}" != "yes" ]
do
if [ -n "${password_value}" ]
if [ -z "${password_value}" ]
then
_password="${password_value}"
csih_inform "Please enter a password for new user ${username}. Please be sure"
......@@ -286,7 +303,6 @@ slapos_create_privileged_user()
# ${username} already exists. Use it, and make no changes.
# use passed-in value as first guess
csih_PRIVILEGED_PASSWORD="${password_value}"
return 0
fi
# username did NOT previously exist, but has been successfully created.
......@@ -331,31 +347,30 @@ slapos_create_privileged_user()
ret=1
fi
fi
# we just created the user, so of course it's in the local SAM,
# and mkpasswd -l is appropriate
pwd_entry="$(/usr/bin/mkpasswd -l -u "${username}" | /usr/bin/sed -n -e '/^'${username}'/s?\(^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\).*?\1'${LOCALSTATEDIR}'/empty:/bin/false?p')"
/usr/bin/grep -Eiq "^${username}:" "${SYSCONFDIR}/passwd" && username_in_passwd=yes &&
/usr/bin/grep -Fiq "${pwd_entry}" "${SYSCONFDIR}/passwd" && entry_in_passwd=yes
if [ "${entry_in_passwd}" != "yes" ]
fi # ! username_in_sam
# we just created the user, so of course it's in the local SAM,
# and mkpasswd -l is appropriate
pwd_entry="$(/usr/bin/mkpasswd -l -u "${username}" | /usr/bin/sed -n -e '/^'${username}'/s?\(^[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\).*?\1'${LOCALSTATEDIR}'/empty:/bin/false?p')"
/usr/bin/grep -Eiq "^${username}:" "${SYSCONFDIR}/passwd" && username_in_passwd=yes &&
/usr/bin/grep -Fiq "${pwd_entry}" "${SYSCONFDIR}/passwd" && entry_in_passwd=yes
if [ "${entry_in_passwd}" != "yes" ]
then
if [ "${username_in_passwd}" = "yes" ]
then
if [ "${username_in_passwd}" = "yes" ]
then
tmpfile2=$(csih_mktemp) || csih_error "Could not create temp file"
/usr/bin/chmod --reference="${SYSCONFDIR}/passwd" "${tmpfile2}"
/usr/bin/chown --reference="${SYSCONFDIR}/passwd" "${tmpfile2}"
/usr/bin/getfacl "${SYSCONFDIR}/passwd" | /usr/bin/setfacl -f - "${tmpfile2}"
tmpfile2=$(csih_mktemp) || csih_error "Could not create temp file"
/usr/bin/chmod --reference="${SYSCONFDIR}/passwd" "${tmpfile2}"
/usr/bin/chown --reference="${SYSCONFDIR}/passwd" "${tmpfile2}"
/usr/bin/getfacl "${SYSCONFDIR}/passwd" | /usr/bin/setfacl -f - "${tmpfile2}"
# use >> instead of > to preserve permissions and acls
/usr/bin/grep -Ev "^${username}:" "${SYSCONFDIR}/passwd" >> "${tmpfile2}" &&
/usr/bin/mv -f "${tmpfile2}" "${SYSCONFDIR}/passwd" || return 1
fi
echo "${pwd_entry}" >> "${SYSCONFDIR}/passwd" || ret=1
/usr/bin/grep -Ev "^${username}:" "${SYSCONFDIR}/passwd" >> "${tmpfile2}" &&
/usr/bin/mv -f "${tmpfile2}" "${SYSCONFDIR}/passwd" || return 1
fi
return "${ret}"
fi # ! username_in_sam
return 1
} # === End of csih_create_privileged_user() === #
readonly -f slapos_create_privileged_user
echo "${pwd_entry}" >> "${SYSCONFDIR}/passwd" || ret=1
fi
return "${ret}"
} # === End of csih_check_and_create_privileged_user() === #
readonly -f slapos_check_and_create_privileged_user
# ======================================================================
# Routine: create_template_configure_file
......
......@@ -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\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\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;
......
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